-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·103 lines (91 loc) · 2.44 KB
/
setup
File metadata and controls
executable file
·103 lines (91 loc) · 2.44 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
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
#!/bin/bash
STOWOPT="--ignore=ignore --ignore=default"
howto() {
[[ $# != 0 ]] && echo "$@" >&2
echo -e "\n Dotfiles setup:\n
\tsetup [OPTION] PACKAGENAME\n
Description:\n
\tSet up dotfiles and symbolic links. PACKAGENAME should be the name of a
\tsubdirectory, with the exception of the packages listed below under
\tSpecial Packages.\n
Options:\n
\t-D remove/unlink mode\n
Special Packages:\n
\t+ color
\t\t Takes one more argument. Sets the color scheme for the Kitty terminal.
\t\t If not argument is given shows a preview of available schemes.
"
[[ $# != 0 ]] && exit 1
exit 0
}
remove() {
stow -D "$1"
}
set_colors_kitty() {
cfname="kitty/colors.ignore/$2.Kcolor"
conf='kitty/.config/kitty/kitty.conf'
if [[ -f $cfname ]] ; then
echo "Loading colour scheme: $2"
sed -E -e "/^# \{\{\{ Define colours/,/^# \}\}\}/ {
/\{\{\{/r $cfname
/\}\}\}|\{\{\{/ ! d
}" "$conf" > temp && mv temp "$conf"
else
kitty/.local/bin/cschemes.py kitty/colors.ignore/
fi
}
set_colors() {
set_colors_kitty "$@"
}
main() {
while getopts "Dh" opt ; do
case $opt in
D)
local remove_package=1
;;
h)
howto
;;
\?)
howto "Invalid option: -$OPTARG"
;;
:)
howto "Option -$OPTARG requires an argument."
;;
esac
done
shift $((OPTIND - 1))
pkgname=$1
case $pkgname in
color)
set_colors "$@"
exit 0
;;
*)
[[ -d $1 ]] || howto "Invalid package name"
;;
esac
if [[ $remove_package ]]; then
remove "$pkgname"
exit 0
fi
host=$(hostname)
defaults=$(find "$pkgname" -iname "*\.default")
for default in $defaults ; do
fname=${default%.default}
cp "$default" "$fname"
if [[ -f "${fname}.${host}.ignore" ]] ; then
IFS=" ="
while read -r option ; do
optionarr=($option)
sed -Ei "s/^\<${optionarr[0]}\>.*\$/$option/" "$fname"
done < "${fname}.${host}.ignore"
fi
if [[ $pkgname =~ ^kitty/? ]] ; then
cscheme=($(grep -E "^\<color_scheme\>" "$fname"))
set_colors_kitty "$pkgname" "${cscheme[1]}" "$fname"
fi
done
stow $STOWOPT "$pkgname"
}
main "$@"