-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclinks
executable file
·192 lines (153 loc) · 4.96 KB
/
clinks
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
read -r -d '' doc <<EOM
Use 'stow' Command to Create Symlinks for All of My Dotfiles and Scripts
EOM
source bugyi.sh
SYNC="${HOME}"/Sync
function run() {
# Check if Running at Work
SYS_INFO="$(uname -a)"
if [[ "${SYS_INFO}" == *"Darwin"* ]]; then
AT_WORK=true
GETOPT=/usr/local/Cellar/gnu-getopt/2.33.2/bin/getopt
else
GETOPT=/usr/bin/getopt
fi
parse_cli_args "$@"
# ----- mkdir Commands
# Make sure that certain directories are not symlinked directly.
# >>> $HOME directories
home_dirs=(".vim" ".ssh")
for D in "${home_dirs[@]}"; do
mkdir "${HOME}"/"${D}" &>/dev/null
done
# >>> User Data Directories
data_dirs=("qutebrowser" "okular" "applications")
for D in "${data_dirs[@]}"; do
mkdir "${HOME}"/.local/share/"${D}" &>/dev/null
done
# ----- Cleanup Commands
imsg "Cleaning up files that might cause the stow command to fail..."
dmsg "Deleting all .mypy_cache/ directories..."
for D in "bin" "home"; do
find "${HOME}"/Sync/"${D}" -type d -name ".mypy_cache*" -exec sudo /bin/rm -rf {} \; &>/dev/null
done
dmsg "Deleting all __pycache__/ directories..."
find "${HOME}"/Sync/bin -type d -name __pycache__ -exec sudo /bin/rm -rf {} \; &>/dev/null
# ----- Main Logic
imsg "Collecting stow commands to run..."
if [[ "${AT_WORK}" == true ]]; then
stow_it_later "${SYNC}/bin/macos" "$HOME/.local/bin"
else
# >>> Other Directories
mkdir -p /usr/share/rlwrap/{filters,completions} &>/dev/null
##### ETC
if [[ $(hostname) == "athena" ]]; then
stow_it_later "${SYNC}/bin/cron.jobs" "/etc"
fi
##### SCRIPTS
if [[ "${SYS_INFO}" == *"gentoo"* ]]; then
stow_it_later "${SYNC}/bin/gentoo" "$HOME/.local/bin"
fi
if [[ "${SYS_INFO}" == *"Debian"* ]]; then
stow_it_later "${SYNC}/bin/debian" "$HOME/.local/bin"
fi
##### MODULES / LIBRARIES / HEADERS
stow_it_later "${SYNC}/bin/xmonad" "$HOME/.local/bin"
stow_it_later "${SYNC}/lib/python" "/usr/local/lib/python"
stow_it_later "${SYNC}/lib/C" "/usr/local/lib"
stow_it_later "${SYNC}/lib/zsh" "/usr/local/lib"
stow_it_later "${SYNC}/src" "/usr/local/src"
stow_it_later "${SYNC}/include" "/usr/local/include"
##### DOTFILES
stow_it_later "${SYNC}/usr" "/usr"
fi
##### SCRIPTS
stow_it_later "${SYNC}/bin/awk" "$HOME/.local/bin"
stow_it_later "${SYNC}/bin/GTD" "$HOME/.local/bin"
stow_it_later "${SYNC}/bin/main" "$HOME/.local/bin"
stow_it_later "${SYNC}/bin/tmux" "$HOME/.local/bin"
stow_it_later "${SYNC}/bin/vim" "$HOME/.local/bin"
stow_it_later "${SYNC}/bin/zathura" "$HOME/.local/bin"
##### DOTFILES
stow_it_later "${SYNC}/home" "${HOME}"
##### PROJECTS
stow_it_later "${SYNC}/var/projects" "$HOME/projects"
if [[ "${VERBOSE}" -eq 0 ]]; then
local tqdm_cmd="tqdm --desc 'running stow commands' --total ${#STOW_IT_CMDS[@]}"
else
dmsg "Running ${#STOW_IT_CMDS[@]} stow commands..."
local tqdm_cmd="tee /dev/null"
fi
for stow_cmd in "${STOW_IT_CMDS[@]}"; do
eval "${stow_cmd}" 1>&2
echo
done | eval "${tqdm_cmd}" >/dev/null
if [[ "${AT_WORK}" = true ]]; then
rm ~/.xinitrc
fi
}
function parse_cli_args() {
eval set -- "$("${GETOPT}" -o "h,v" -l "help,verbose" -- "$@")"
export USAGE_GRAMMAR=(
"[-v] [STOW_FLAG]"
"-h"
)
# shellcheck disable=SC2154
read -r -d '' help <<EOM
$(usage)
${doc}
Positional Arguments:
STOW_FLAG Option flag to pass to the 'stow' command. Defaults to '-R'.
Optional Arguments:
-h | --help
View this help message.
-v | --verbose
Enable verbose output. This option can be specified multiple times (e.g. -v, -vv, ...).
EOM
VERBOSE=0
while [[ -n "$1" ]]; do
case $1 in
-h | --help)
echo "${help}"
exit 0
;;
-v | --verbose)
VERBOSE=$((VERBOSE + 1))
;;
--)
shift
break
;;
esac
shift
done
if [[ "${VERBOSE}" -gt 1 ]]; then
PS4='$LINENO: '
set -x
fi
if [[ -n "$1" ]]; then
FLAG="$1"
shift
else
FLAG=R
fi
}
STOW_IT_CMDS=()
function stow_it_later() { STOW_IT_CMDS+=("stow_it $*"); }
function stow_it() {
local src="$1"
shift
local target="$1"
shift
local dir="${src%/*}"
local subdir="${src##*/}"
local stow_cmd="stow --dir=${dir} --target=${target} -${FLAG} ${subdir}"
dmsg "${stow_cmd}"
# shellcheck disable=SC2086
# We use perl to filter out spurious warning output (see https://github.com/aspiers/stow/issues/65).
sudo 2>&1 ${stow_cmd} | perl -nE 'print unless /BUG in find_stowed_path\?/'
}
if [[ "${SCRIPTNAME}" == "$(basename "${BASH_SOURCE[0]}")" ]]; then
run "$@"
fi