Compare commits
3 Commits
2a899712d5
...
38850ebf8e
Author | SHA1 | Date | |
---|---|---|---|
38850ebf8e | |||
91efeb74b8 | |||
477a579044 |
8
dotfiles
8
dotfiles
@ -98,19 +98,19 @@ def main [
|
|||||||
--ignore-constraint (-C), # 忽略模块的约束检查
|
--ignore-constraint (-C), # 忽略模块的约束检查
|
||||||
] {
|
] {
|
||||||
# 家目录
|
# 家目录
|
||||||
let-env HOME_DIR = (
|
$env.HOME_DIR = (
|
||||||
if ($home_dir != null) { $home_dir } else { $env.HOME }
|
if ($home_dir != null) { $home_dir } else { $env.HOME }
|
||||||
| path expand
|
| path expand
|
||||||
)
|
)
|
||||||
# 日志等级
|
# 日志等级
|
||||||
let-env LOG_LEVEL = (
|
$env.LOG_LEVEL = (
|
||||||
if ($verbose) { 0 }
|
if ($verbose) { 0 }
|
||||||
else { if ($less) { 12 } else { 10 } }
|
else { if ($less) { 12 } else { 10 } }
|
||||||
)
|
)
|
||||||
# 确认选项
|
# 确认选项
|
||||||
let-env NO_CONFIRM = $no_confirm
|
$env.NO_CONFIRM = $no_confirm
|
||||||
# 约束检查
|
# 约束检查
|
||||||
let-env IGNORE_CONSTRAINT = $ignore_constraint
|
$env.IGNORE_CONSTRAINT = $ignore_constraint
|
||||||
# 加载配置集
|
# 加载配置集
|
||||||
active_config register
|
active_config register
|
||||||
# 运行操作
|
# 运行操作
|
||||||
|
@ -2,13 +2,15 @@
|
|||||||
#
|
#
|
||||||
# Copyright (C) 2022 KAAAsS
|
# Copyright (C) 2022 KAAAsS
|
||||||
|
|
||||||
# 设置自启脚本
|
use constraints.nu
|
||||||
export def install [
|
|
||||||
path: path
|
module linux {
|
||||||
] {
|
export def install [
|
||||||
let filename = ($path | path basename)
|
path: path
|
||||||
mkdir $"($env.HOME_DIR)/.config/autostart"
|
] {
|
||||||
echo $"[Desktop Entry]
|
let filename = ($path | path basename)
|
||||||
|
mkdir $"($env.HOME_DIR)/.config/autostart"
|
||||||
|
echo $"[Desktop Entry]
|
||||||
Exec=($path)
|
Exec=($path)
|
||||||
Icon=dialog-scripts
|
Icon=dialog-scripts
|
||||||
Name=($filename)
|
Name=($filename)
|
||||||
@ -16,6 +18,68 @@ Path=
|
|||||||
Type=Application
|
Type=Application
|
||||||
X-KDE-AutostartScript=true
|
X-KDE-AutostartScript=true
|
||||||
" | save -f $"($env.HOME_DIR)/.config/autostart/($filename).desktop"
|
" | 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
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +87,12 @@ X-KDE-AutostartScript=true
|
|||||||
export def uninstall [
|
export def uninstall [
|
||||||
path: path
|
path: path
|
||||||
] {
|
] {
|
||||||
let filename = ($path | path basename)
|
if (constraints os linux) {
|
||||||
rm -f $"($env.HOME_DIR)/.config/autostart/($filename).desktop"
|
linux uninstall $path
|
||||||
|
} else if (constraints os darwin) {
|
||||||
|
darwin uninstall $path
|
||||||
|
} else {
|
||||||
|
error make { msg: "当前系统不支持自启脚本" }
|
||||||
|
}
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,23 @@ module os {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export use os
|
||||||
|
|
||||||
# 图形界面约束
|
# 图形界面约束
|
||||||
export def gui [] {
|
export def gui [] {
|
||||||
use pkg.nu
|
use pkg.nu
|
||||||
|
|
||||||
pkg check_install? libxrandr
|
if (os linux) {
|
||||||
|
# Linux 暂时只考虑 X11
|
||||||
|
pkg check_install? libxrandr
|
||||||
|
} else if (os darwin) {
|
||||||
|
# MacOS 都是图形界面
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export use os
|
|
||||||
|
|
||||||
# 获得默认的约束
|
# 获得默认的约束
|
||||||
export def default_constraints [] {
|
export def default_constraints [] {
|
||||||
{
|
{
|
||||||
|
@ -9,7 +9,7 @@ use global_conf.nu
|
|||||||
# 注册自定义约束
|
# 注册自定义约束
|
||||||
export def-env register_custom_constraint [
|
export def-env register_custom_constraint [
|
||||||
name: string, # 约束名
|
name: string, # 约束名
|
||||||
fn: block, # 约束检查函数,返回 bool
|
fn: closure, # 约束检查函数,返回 bool
|
||||||
] {
|
] {
|
||||||
log debug $"自定义约束: ($name): ($fn)"
|
log debug $"自定义约束: ($name): ($fn)"
|
||||||
let constraints = (global_conf get_config "_" "constraints")
|
let constraints = (global_conf get_config "_" "constraints")
|
||||||
@ -62,7 +62,7 @@ export def check_constraint [
|
|||||||
export def check_all_constraints [] {
|
export def check_all_constraints [] {
|
||||||
let constraints = (global_conf get_config "_" "constraints")
|
let constraints = (global_conf get_config "_" "constraints")
|
||||||
|
|
||||||
mut result = null
|
mut result = []
|
||||||
for $cons in ($constraints | transpose key).key {
|
for $cons in ($constraints | transpose key).key {
|
||||||
$result = ($result | append {
|
$result = ($result | append {
|
||||||
"constraint": $cons,
|
"constraint": $cons,
|
||||||
|
@ -6,7 +6,7 @@ use ../constraints.nu
|
|||||||
|
|
||||||
export-env {
|
export-env {
|
||||||
# 全局配置
|
# 全局配置
|
||||||
let-env modules_config = { "_":
|
$env.modules_config = { "_":
|
||||||
{ "constraints": (constraints default_constraints) }
|
{ "constraints": (constraints default_constraints) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ export def-env set_config [
|
|||||||
$old_config
|
$old_config
|
||||||
| merge { $config : $value }
|
| merge { $config : $value }
|
||||||
)
|
)
|
||||||
let-env modules_config = (
|
$env.modules_config = (
|
||||||
$modules_config
|
$modules_config
|
||||||
| merge { $module : $config }
|
| merge { $module : $config }
|
||||||
)
|
)
|
||||||
|
@ -36,12 +36,12 @@ export def-env register_post_install [module: string, hook: closure] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 注册模块卸载前运行钩子
|
# 注册模块卸载前运行钩子
|
||||||
export def-env register_pre_uninstall [module: string, hook: block] {
|
export def-env register_pre_uninstall [module: string, hook: closure] {
|
||||||
register_hook "pre_uninstall" $module $hook
|
register_hook "pre_uninstall" $module $hook
|
||||||
}
|
}
|
||||||
|
|
||||||
# 注册模块卸载后运行钩子
|
# 注册模块卸载后运行钩子
|
||||||
export def-env register_post_uninstall [module: string, hook: block] {
|
export def-env register_post_uninstall [module: string, hook: closure] {
|
||||||
register_hook "post_uninstall" $module $hook
|
register_hook "post_uninstall" $module $hook
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ export def filtered_modules [
|
|||||||
$modules
|
$modules
|
||||||
} else {
|
} else {
|
||||||
# 检查模块是否存在
|
# 检查模块是否存在
|
||||||
mut result = null
|
mut result = []
|
||||||
for $module in $want_modules {
|
for $module in $want_modules {
|
||||||
if (not ($module in $modules)) {
|
if (not ($module in $modules)) {
|
||||||
log error $"模块 ($module) 不存在!"
|
log error $"模块 ($module) 不存在!"
|
||||||
@ -34,7 +34,7 @@ export def filtered_modules [
|
|||||||
if ("IGNORE_CONSTRAINT" in $env and $env.IGNORE_CONSTRAINT) {
|
if ("IGNORE_CONSTRAINT" in $env and $env.IGNORE_CONSTRAINT) {
|
||||||
return $modules
|
return $modules
|
||||||
}
|
}
|
||||||
mut result = null
|
mut result = []
|
||||||
for $module in $modules {
|
for $module in $modules {
|
||||||
let constraints = (global_conf get_config $module "constraints" [])
|
let constraints = (global_conf get_config $module "constraints" [])
|
||||||
let check = (
|
let check = (
|
||||||
|
@ -21,7 +21,7 @@ def get_base_dir [local: path, dest: path] {
|
|||||||
# 声明文件及其目标路径
|
# 声明文件及其目标路径
|
||||||
export def-env declare [
|
export def-env declare [
|
||||||
module: string, # 模块名称
|
module: string, # 模块名称
|
||||||
local: path, # 本地路径,以项目根目录为起点的相对路径
|
local: any, # 本地路径,以项目根目录为起点的相对路径
|
||||||
dest: string, # 目标路径,以用户家目录为起点的相对路径
|
dest: string, # 目标路径,以用户家目录为起点的相对路径
|
||||||
--local-only: bool, # 是否是本地特有的文件。若文件不存在则会自动从 example 创建本地文件
|
--local-only: bool, # 是否是本地特有的文件。若文件不存在则会自动从 example 创建本地文件
|
||||||
] {
|
] {
|
||||||
@ -33,7 +33,7 @@ export def-env declare [
|
|||||||
}
|
}
|
||||||
|
|
||||||
# 遍历 local 路径,获得映射
|
# 遍历 local 路径,获得映射
|
||||||
mut new_maps = null
|
mut new_maps = []
|
||||||
for $local in $locals {
|
for $local in $locals {
|
||||||
let dest = if ($type == "list<string>") {
|
let dest = if ($type == "list<string>") {
|
||||||
# 对于文件列表(如 glob),把文件名追加在最后
|
# 对于文件列表(如 glob),把文件名追加在最后
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# Copyright (C) 2022 KAAAsS
|
# Copyright (C) 2022 KAAAsS
|
||||||
|
|
||||||
def-env confirm_loop [ prompt: string, default: string ] {
|
def-env confirm_loop [ prompt: string, default: string ] {
|
||||||
let-env result = if ($env.result == null) {
|
$env.result = if ($env.result == null) {
|
||||||
let got = (input $prompt)
|
let got = (input $prompt)
|
||||||
if ($got == "y" or $got == "n") {
|
if ($got == "y" or $got == "n") {
|
||||||
$got
|
$got
|
||||||
@ -43,7 +43,7 @@ export def confirm [
|
|||||||
$default == "y"
|
$default == "y"
|
||||||
} else {
|
} else {
|
||||||
# 尝试获得结果
|
# 尝试获得结果
|
||||||
let-env result = null
|
$env.result = null
|
||||||
|
|
||||||
# 最多尝试 5 次(因为 nushell 的限制暂时无法在循环里编辑环境)
|
# 最多尝试 5 次(因为 nushell 的限制暂时无法在循环里编辑环境)
|
||||||
confirm_loop $prompt $default
|
confirm_loop $prompt $default
|
||||||
@ -67,7 +67,7 @@ def main [] {
|
|||||||
print (confirm "测试 1")
|
print (confirm "测试 1")
|
||||||
print (confirm "测试 2" "y")
|
print (confirm "测试 2" "y")
|
||||||
print (confirm "测试 3" "n")
|
print (confirm "测试 3" "n")
|
||||||
let-env NO_CONFIRM = true
|
$env.NO_CONFIRM = true
|
||||||
print (confirm "测试 2" "y")
|
print (confirm "测试 2" "y")
|
||||||
print (confirm "测试 3" "n")
|
print (confirm "测试 3" "n")
|
||||||
print (confirm "测试 1")
|
print (confirm "测试 1")
|
||||||
|
@ -6,13 +6,13 @@ use pkgs/homebrew.nu
|
|||||||
|
|
||||||
export-env {
|
export-env {
|
||||||
# 所有可用的包管理器
|
# 所有可用的包管理器
|
||||||
let-env package_managers = [
|
$env.package_managers = [
|
||||||
(pacman pack),
|
(pacman pack),
|
||||||
(homebrew pack),
|
(homebrew pack),
|
||||||
(fallback_manager)
|
(fallback_manager)
|
||||||
]
|
]
|
||||||
# 计算默认包管理器
|
# 计算默认包管理器
|
||||||
let-env default_package_manager = (select_managers)
|
$env.default_package_manager = (select_managers)
|
||||||
}
|
}
|
||||||
|
|
||||||
def select_managers [
|
def select_managers [
|
||||||
@ -184,7 +184,7 @@ export def test [] {
|
|||||||
use testing *
|
use testing *
|
||||||
|
|
||||||
# 增加 Mock 管理器
|
# 增加 Mock 管理器
|
||||||
let-env package_managers = [
|
$env.package_managers = [
|
||||||
{
|
{
|
||||||
"name": "unavailable",
|
"name": "unavailable",
|
||||||
"available?": { false }
|
"available?": { false }
|
||||||
@ -202,7 +202,7 @@ export def test [] {
|
|||||||
"check_install?": {|p| $p == "mock2" },
|
"check_install?": {|p| $p == "mock2" },
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
let-env default_package_manager = (select_managers)
|
$env.default_package_manager = (select_managers)
|
||||||
|
|
||||||
# select_managers
|
# select_managers
|
||||||
let mock = (select_managers "mock2")
|
let mock = (select_managers "mock2")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user