-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsys
executable file
·97 lines (79 loc) · 1.91 KB
/
sys
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
#!/usr/bin/env bash
username="${USER:-murtaza}"
function update() {
nix flake update
}
function switch_nixos() {
sudo nixos-rebuild switch --flake .# "$@"
}
function switch_home_manager() {
nix run .#homeConfigurations.$username.activationPackage
}
function install_scripts() {
local target="$HOME/.local"
mkdir -p "$target"
ln -sft "$target" "$PWD/static/scripts"
}
function install_neovim() {
local target="$HOME/.config"
mkdir -p "$target"
ln -sft "$target" "$PWD/static/nvim"
}
function install_emacs() {
local target="$HOME/.config/emacs"
mkdir -p "$target"
ln -sft "$target" "$PWD/static/emacs/init.el"
ln -sft "$target" "$PWD/static/emacs/early-init.el"
}
######## bash completion context ########
root=(update switch install)
switch=(nixos home-manager)
install=(scripts neovim emacs)
comp() {
local arg="$1"
shift
for c in "$@"; do
[[ "${c:0:${#arg}}" == "${arg,,}" ]] && echo "$c"
done
}
if [[ -n "$COMP_LINE" ]]; then
if [[ "$1" == "$3" ]]; then
comp "$2" "${root[@]}"
exit 0
fi
if [[ "$3" == "switch" ]]; then
comp "$2" "${switch[@]}"
elif [[ "$3" == "install" ]]; then
comp "$2" "${install[@]}"
fi
exit 0
fi
numargs="${#@}"
if [[ "$numargs" -lt 1 ]]; then
echo "very few arguments"
exit 1
fi
cmd="$1"; shift
arg="$1"; shift
case "$cmd" in
"update")
update
;;
"switch")
case "$arg" in
"") switch_nixos "$@" ;;
nixos) switch_nixos "$@" ;;
home-manager) switch_home_manager ;;
*) echo "invalid command: $arg" ;;
esac
;;
"install")
case "$arg" in
scripts) install_scripts ;;
neovim) install_neovim ;;
emacs) install_emacs ;;
*) echo "invalid command: $arg" ;;
esac
;;
*) echo "invalid command: $cmd" ;;
esac