-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.nu
executable file
·169 lines (145 loc) · 3.51 KB
/
deploy.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env -S nu --stdin
use std/log
use std/iter
def main [] {
[]
| pf shell ~/.config/shell
| pf navi ~/.local/share/navi/cheats
| pf memo ~/.local/share/memo
| pf zsh/zshenv ~/.zshenv
| pf zsh/zshrc ~/.config/zsh/.zshrc
| pf zsh/p10k.zsh -t ~/.config/zsh
| pf bashrc ~/.bashrc
| pf rofi/config ~/.config/rofi
| pf rofi/themes ~/.local/share/rofi/themes
| pf gtk/gtk-3.0 ~/.config/gtk-3.0
| pf gtk/gtk-4.0 ~/.config/gtk-4.0
| pf bin -t ~/.local
| pf cargo ~/.cargo
| pf fcitx5/config ~/.config/fcitx5
| pf fcitx5/share ~/.local/share/fcitx5
| pf waybar/style.less ~/.config/waybar/style.css
| pf waybar/latte.css ~/.config/waybar/latte.css
| pf waybar/config.jsonc ~/.config/waybar/config.jsonc
# | pf Templates -t ~
| pfs [
starship.toml fish nushell dunst hypr
LazyVim neovide wezterm kitty zellij yazi git git-cliff
gitui lazygit zathura mpv gdb pip.conf macchina paru mimeapps.list
mise atuin uv
] ~/.config
| pfs [memo applications] ~/.local/share
| each {|it| deploy-item $it }
return
}
def 'main root' [] {
for src in (ls root | get name) {
cp -r $src /
}
}
# prepare
def pf [
src: string,
--target (-t),
dest: string,
] {
let self = $in
$self
| append {
src: $src,
dest: $dest,
place: $target,
}
}
def pfs [srcs: list<string>, dest: string] {
let self = $in
$srcs
| reduce --fold $self {|src, self|
$self
| append {
src: $src,
dest: $dest,
place: true,
}
}
}
def deploy-item [it: record] {
let dest = $it.dest | path expand
match ($it.src | path type) {
file => { deploy-file $it.src $dest $it.place },
dir if $it.place => { place-dir $it.src $dest },
dir => { deploy-dir $it.src $dest },
}
}
def deploy-file [
src: string,
dest: path,
place: bool,
] {
let dest = if $place {
mkdir -v $dest
$dest | path join ($src | path basename)
} else {
mkdir -v ($dest | path dirname)
$dest
}
link $src $dest
}
def deploy-dir [
src: string,
dest: path,
] {
let dest_path = {|p|
$dest
| path join (
$p
| path strip (pwd) $src
)
}
let dirs = glob $"($src)/**/*" --no-file
| skip 1
| each $dest_path
# 确保dirs为空时也创建dest
mkdir -v $dest ...$dirs
glob $"($src)/**/*" --no-dir
| each {|file|
let dest = (do $dest_path $file)
let file = $file | path strip (pwd)
link $file $dest
}
}
def place-dir [src: string, dest: path] {
let dest_path = {|p|
$dest
| path join (
$p
| path strip (pwd) ($src | path dirname)
)
}
let dirs = glob $"($src)/**/*" --no-file
| each $dest_path
mkdir -v ...$dirs
glob $"($src)/**/*" --no-dir
| each {|file|
let dest = (do $dest_path $file)
let file = $file | path strip (pwd)
link $file $dest
}
}
def link [src: string, dest: path] {
let srcp = pwd | path join $src
if not (is-linked $srcp $dest) {
log info $"($src) => ($dest)"
ln -s $srcp $dest
}
}
def is-linked [src: path, dest: path]: nothing -> bool {
try {
$src == (realpath $dest)
} catch {
false
}
}
def 'path strip' [...prefix: string]: nothing -> path {
$in | path relative-to ($prefix | path join)
}