Compare commits

..

No commits in common. "38850ebf8e787f0bdff6f60955d09b5e03dc6399" and "2a899712d5f5b58e98d026eb55a0bc8a6d21ff56" have entirely different histories.

10 changed files with 33 additions and 110 deletions

View File

@ -98,19 +98,19 @@ def main [
--ignore-constraint (-C), # 忽略模块的约束检查
] {
# 家目录
$env.HOME_DIR = (
let-env HOME_DIR = (
if ($home_dir != null) { $home_dir } else { $env.HOME }
| path expand
)
# 日志等级
$env.LOG_LEVEL = (
let-env LOG_LEVEL = (
if ($verbose) { 0 }
else { if ($less) { 12 } else { 10 } }
)
# 确认选项
$env.NO_CONFIRM = $no_confirm
let-env NO_CONFIRM = $no_confirm
# 约束检查
$env.IGNORE_CONSTRAINT = $ignore_constraint
let-env IGNORE_CONSTRAINT = $ignore_constraint
# 加载配置集
active_config register
# 运行操作

View File

@ -2,15 +2,13 @@
#
# Copyright (C) 2022 KAAAsS
use constraints.nu
module linux {
export def install [
path: path
] {
let filename = ($path | path basename)
mkdir $"($env.HOME_DIR)/.config/autostart"
echo $"[Desktop Entry]
# 设置自启脚本
export def install [
path: path
] {
let filename = ($path | path basename)
mkdir $"($env.HOME_DIR)/.config/autostart"
echo $"[Desktop Entry]
Exec=($path)
Icon=dialog-scripts
Name=($filename)
@ -18,68 +16,6 @@ Path=
Type=Application
X-KDE-AutostartScript=true
" | save -f $"($env.HOME_DIR)/.config/autostart/($filename).desktop"
null
}
export def uninstall [
path: path
] {
let filename = ($path | path basename)
rm -f $"($env.HOME_DIR)/.config/autostart/($filename).desktop"
null
}
}
module darwin {
export def install [
path: path
] {
let filename = ($path | path basename)
mkdir $"($env.HOME_DIR)/Library/LaunchAgents"
echo $"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<dict>
<key>Label</key>
<string>($filename)</string>
<key>ProgramArguments</key>
<array>
<string>($path)</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
" | save -f $"($env.HOME_DIR)/Library/LaunchAgents/($filename).plist"
launchctl load $"($env.HOME_DIR)/Library/LaunchAgents/($filename).plist"
null
}
export def uninstall [
path: path
] {
let filename = ($path | path basename)
launchctl stop $"($filename)"
launchctl unload $"($env.HOME_DIR)/Library/LaunchAgents/($filename).plist"
rm -f $"($env.HOME_DIR)/Library/LaunchAgents/($filename).plist"
null
}
}
use linux
use darwin
# 设置自启脚本
export def install [
path: path
] {
if (constraints os linux) {
linux install $path
} else if (constraints os darwin) {
darwin install $path
} else {
error make { msg: "当前系统不支持自启脚本" }
}
null
}
@ -87,12 +23,7 @@ export def install [
export def uninstall [
path: path
] {
if (constraints os linux) {
linux uninstall $path
} else if (constraints os darwin) {
darwin uninstall $path
} else {
error make { msg: "当前系统不支持自启脚本" }
}
let filename = ($path | path basename)
rm -f $"($env.HOME_DIR)/.config/autostart/($filename).desktop"
null
}

View File

@ -21,23 +21,15 @@ module os {
}
}
export use os
# 图形界面约束
export def gui [] {
use pkg.nu
if (os linux) {
# Linux 暂时只考虑 X11
pkg check_install? libxrandr
} else if (os darwin) {
# MacOS 都是图形界面
true
} else {
false
}
pkg check_install? libxrandr
}
export use os
# 获得默认的约束
export def default_constraints [] {
{

View File

@ -9,7 +9,7 @@ use global_conf.nu
# 注册自定义约束
export def-env register_custom_constraint [
name: string, # 约束名
fn: closure, # 约束检查函数,返回 bool
fn: block, # 约束检查函数,返回 bool
] {
log debug $"自定义约束: ($name): ($fn)"
let constraints = (global_conf get_config "_" "constraints")
@ -62,7 +62,7 @@ export def check_constraint [
export def check_all_constraints [] {
let constraints = (global_conf get_config "_" "constraints")
mut result = []
mut result = null
for $cons in ($constraints | transpose key).key {
$result = ($result | append {
"constraint": $cons,

View File

@ -6,7 +6,7 @@ use ../constraints.nu
export-env {
# 全局配置
$env.modules_config = { "_":
let-env modules_config = { "_":
{ "constraints": (constraints default_constraints) }
}
}
@ -57,7 +57,7 @@ export def-env set_config [
$old_config
| merge { $config : $value }
)
$env.modules_config = (
let-env modules_config = (
$modules_config
| merge { $module : $config }
)

View File

@ -36,12 +36,12 @@ export def-env register_post_install [module: string, hook: closure] {
}
# 注册模块卸载前运行钩子
export def-env register_pre_uninstall [module: string, hook: closure] {
export def-env register_pre_uninstall [module: string, hook: block] {
register_hook "pre_uninstall" $module $hook
}
# 注册模块卸载后运行钩子
export def-env register_post_uninstall [module: string, hook: closure] {
export def-env register_post_uninstall [module: string, hook: block] {
register_hook "post_uninstall" $module $hook
}

View File

@ -18,7 +18,7 @@ export def filtered_modules [
$modules
} else {
# 检查模块是否存在
mut result = []
mut result = null
for $module in $want_modules {
if (not ($module in $modules)) {
log error $"模块 ($module) 不存在!"
@ -34,7 +34,7 @@ export def filtered_modules [
if ("IGNORE_CONSTRAINT" in $env and $env.IGNORE_CONSTRAINT) {
return $modules
}
mut result = []
mut result = null
for $module in $modules {
let constraints = (global_conf get_config $module "constraints" [])
let check = (

View File

@ -21,7 +21,7 @@ def get_base_dir [local: path, dest: path] {
# 声明文件及其目标路径
export def-env declare [
module: string, # 模块名称
local: any, # 本地路径,以项目根目录为起点的相对路径
local: path, # 本地路径,以项目根目录为起点的相对路径
dest: string, # 目标路径,以用户家目录为起点的相对路径
--local-only: bool, # 是否是本地特有的文件。若文件不存在则会自动从 example 创建本地文件
] {
@ -33,7 +33,7 @@ export def-env declare [
}
# 遍历 local 路径,获得映射
mut new_maps = []
mut new_maps = null
for $local in $locals {
let dest = if ($type == "list<string>") {
# 对于文件列表(如 glob把文件名追加在最后

View File

@ -3,7 +3,7 @@
# Copyright (C) 2022 KAAAsS
def-env confirm_loop [ prompt: string, default: string ] {
$env.result = if ($env.result == null) {
let-env result = if ($env.result == null) {
let got = (input $prompt)
if ($got == "y" or $got == "n") {
$got
@ -43,7 +43,7 @@ export def confirm [
$default == "y"
} else {
# 尝试获得结果
$env.result = null
let-env result = null
# 最多尝试 5 次(因为 nushell 的限制暂时无法在循环里编辑环境)
confirm_loop $prompt $default
@ -67,7 +67,7 @@ def main [] {
print (confirm "测试 1")
print (confirm "测试 2" "y")
print (confirm "测试 3" "n")
$env.NO_CONFIRM = true
let-env NO_CONFIRM = true
print (confirm "测试 2" "y")
print (confirm "测试 3" "n")
print (confirm "测试 1")

View File

@ -6,13 +6,13 @@ use pkgs/homebrew.nu
export-env {
# 所有可用的包管理器
$env.package_managers = [
let-env package_managers = [
(pacman pack),
(homebrew pack),
(fallback_manager)
]
# 计算默认包管理器
$env.default_package_manager = (select_managers)
let-env default_package_manager = (select_managers)
}
def select_managers [
@ -184,7 +184,7 @@ export def test [] {
use testing *
# 增加 Mock 管理器
$env.package_managers = [
let-env package_managers = [
{
"name": "unavailable",
"available?": { false }
@ -202,7 +202,7 @@ export def test [] {
"check_install?": {|p| $p == "mock2" },
}
]
$env.default_package_manager = (select_managers)
let-env default_package_manager = (select_managers)
# select_managers
let mock = (select_managers "mock2")