-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathutils.exclude.sh
executable file
·48 lines (39 loc) · 1.33 KB
/
utils.exclude.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
#!/usr/bin/env bash
# Utility functions that the other dotfile related scripts will use
# Note that this stuff isn't supposed to be used by the dotfiles themselves, just by the stuff that helps manage/bootstrap them
# LOL looks like a framework is surfacing... xD
echo_with_prompt () {
# The narcissistic default prompt
PROMPT="${PROMPT:-'[ AjmalsDotfiles ]'}"
echo "$PROMPT $@"
}
execute_func_with_prompt() {
# Args
# $1 - the function to call
# $2 - the thing this function does
# Returns 1 if the user cancels the operation
# Returns 2 if the function failed
# Returns 0 if all went well
# TODO this feels like a hack honestly :p
# See if there is a better way than just "$1" the function
echo_with_prompt "This utility will $2"
echo_with_prompt "Proceed? (y/n)"
read resp
# TODO - regex here?
if [ "$resp" = 'y' -o "$resp" = 'Y' ] ; then
# This thing here "calls" the function
"$1" || return 2
echo_with_prompt "$2 complete"
else
echo_with_prompt "$2 cancelled by user"
return 1
fi
}
# Function to ensure needed binaries are installed
test-bins () {
echo_with_prompt "Making sure required commands are installed..."
for bin in $@ ; do
which $bin || { echo_with_prompt "Command $bin not found, please install it to continue" ; return 1 ; }
done
echo_with_prompt "All good!"
}