-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate.sh
executable file
·153 lines (128 loc) · 2.48 KB
/
populate.sh
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
#!/usr/bin/env bash
set -e
set -o pipefail
PROGRAM=$(basename "$0")
# Colors
red="\e[91m"
magenta="\e[35m"
nc="\e[0m"
DOTFILES="$HOME/.dotfiles"
# CONFIGS=(fontconfig greenclip.toml)
PROGRAMS=(
autorandr
bat
dunst
fd
git
greenclip
lazygit
nnn
nvim
picom
pipewire
pymarks
rofi
sxhkd
sxiv
tmux
zathura
xss-lock
)
err() {
printf "${red}Error:${nc} %s\n" "$*"
}
program_exists() {
local program="$1"
if command -v "$program" >/dev/null; then
return 0
else
err "'$program' not found"
return 1
fi
}
dir_exists() {
local folder="$DOTFILES/$program"
if [ -d "$folder" ]; then
return 0
else
err "'$folder' not found"
return 1
fi
}
confirmation() {
local default_value="Y"
local program="$1"
local input
echo -ne "Restore ${red}$program${nc}? [Y/n] "
read -p "" -r choice
input=${choice:-$default_value}
case "$input" in
y | Y) return 0 ;;
n | N) return 1 ;;
*) return 1 ;;
esac
}
restore_program() {
local program="$1"
if program_exists "$program" && dir_exists "$program"; then
folder="$DOTFILES/$program"
if confirmation "$program"; then
cd "$DOTFILES"
stow -v "$program"
echo -e "$folder ${magenta}restored${nc}"
echo
fi
fi
}
check_dependencies() {
local programs="fzf stow fd"
for program in $programs; do
if ! program_exists "$program"; then
err "'$program' not found"
exit 1
fi
done
}
restore_array() {
# FIX: better naming
for program in "${PROGRAMS[@]}"; do
restore_program "$program"
done
}
selection() {
# shellcheck disable=2012
selection=$(fd . -d 1 -t d "$DOTFILES" -x basename | fzf \
--layout=reverse-list \
--height=45% \
--border=sharp \
--prompt="$PROGRAM> " \
--pointer='→' \
--ansi \
--multi \
--no-preview)
[[ -z "$selection" ]] && exit 1
for selected in $selection; do
restore_program "$selected"
done
}
usage() {
echo
echo "Usage: $PROGRAM <command>"
echo
echo "command:"
echo " pick Pick a program to restore"
exit 0
}
main() {
local arg
arg="$1"
check_dependencies
case "$arg" in
pick) selection ;;
*) restore_array ;;
esac
}
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
usage
fi
main "$@"