-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotfiles
More file actions
executable file
·68 lines (54 loc) · 1.42 KB
/
dotfiles
File metadata and controls
executable file
·68 lines (54 loc) · 1.42 KB
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
#!/bin/bash
command_dir="${0%/*}/_dotfiles"
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/dotfiles"
temp=$(getopt --name 'dotfiles' --options 'hn' --long 'help,dry-run' -- "$@")
eval set -- "$temp"
unset temp
main() {
options=()
args=()
parse_options "$@"
local command="${args[0]}"
unset args[0]
case "$command" in
'load'|'save')
eval "$command_dir/$command ${options[@]} ${args[@]}";;
*)
help;;
esac
}
help() {
local text="\
Usage: dotfiles [OPTION]...
Manage the storage and repository of custom linux dotfiles.
Mandatory arguments to long options are mandatory for short options too.
-h, --help display this help and exit
-n, --dry-run perform a trial run with no changes made
Exit status:
0 if OK,
1 if minor problems (e.g., cannot access subdirectory),
2 if serious trouble (e.g., cannot access command-line argument)."
echo "$text" | sed 's/^\s\{6\}//g'
exit 0
}
parse_options() {
while [ -n "$1" ]; do
case "$1" in
'-h'|'--help')
options+=(--help)
shift && continue;;
'-n'|'--dry-run')
options+=(--dry-run)
shift && continue;;
'--')
shift && break;;
*)
echo 'Internal error!' >&2
exit 1;;
esac
done
for arg; do
args+=("$arg")
done
}
main "$@"