-
Notifications
You must be signed in to change notification settings - Fork 1
/
dotman
executable file
·54 lines (48 loc) · 1.25 KB
/
dotman
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
#!/bin/bash
set -euo pipefail
if [[ ${DEBUG:-} = 1 ]]; then
set -o xtrace
fi
echoerr() {
>&2 echo -n -e "\e[34m!Error:\e[39m "
>&2 echo "$@"
}
# read file path, get the directory name, go up a few steps, and then resolve the relative path
SCRIPT_DIR="$(readlink -m "$(dirname "$(readlink -f "$0")")/../../..")"
STOW_ARGS=("--dir=${SCRIPT_DIR}/packages/" "--target=${HOME}")
help_message() {
echo 'Usage: dotman [package ...]'
echo
echo 'Available packages:'
for dir in "${SCRIPT_DIR}"/packages/*; do
if [[ -d "$dir" ]]; then
echo " $(basename "${dir}")"
fi
done
}
if [[ -z "${1:-}" ]]; then
echoerr "No package names given."
help_message
exit 1
fi
for item in "$@"; do
if [[ -d "${SCRIPT_DIR}/packages/${item}" ]]; then
echo "Package: ${1}"
stow "${STOW_ARGS[@]}" "$item"
else
echoerr "Package not found: ${1}"
fi
done
# # Deprecated, old "all" shortcut
# if [[ "${1}" == "all" ]]; then
# for dir in "${SCRIPT_DIR}"/packages/*; do
# if [[ -d $dir ]]; then
# echo "Package: $(basename "${dir}")"
# stow "${STOW_ARGS[@]}" "$(basename "$dir")" || true
# else
# echoerr "This should not happen. There is a non-directory file in the packages directory."
# exit 2
# fi
# done
# else
# fi