-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path.shell_control
More file actions
executable file
·82 lines (73 loc) · 1.66 KB
/
.shell_control
File metadata and controls
executable file
·82 lines (73 loc) · 1.66 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
# .shell_control
show() {
# usage: show [-i|-r] <message>
# -i: show an important message
# -r: show a command
local important=0
if [[ $1 == "-i" ]]; then
shift
important=1
echo -n $'\e[38;5;196m'"$(tput bold)! "
elif [[ $1 == "-r" ]]; then
shift
echo -n $'\e[38;5;40m$\e[38;5;63m '
else
echo -n $'\e[1;34m>\e[0m\e[31m '
fi
echo -n "$@"
if [[ $important == "1" ]]; then
echo -n " $(tput sgr0)"$'\e[0m'
else
echo -n $'\e[0m'
fi
echo
}
run() {
# usage: run <command>; SC_DRYRUN=1 means command will not run
show -r "$@"
if [[ $SC_DRYRUN == 0 ]]; then
eval "$@"
return $?
else
return 0
fi
}
abort() {
# usage: abort <message> [cleanup command]
if [[ -n $2 ]]; then
run "$2"
fi
echo $'\e[1;31merror:' "$1" $'\e[0m' >&2
exit 1
}
ask() {
# usage: ask "question"; SC_FORCE=1 implies reply is yes
if [[ $SC_FORCE == 1 ]]; then
REPLY='y'
return 0
fi
echo -n $'\n\e[1;35m'
# shellcheck disable=SC2162
read -p "$1 (y/n) [n] ... "
echo -n $'\e[0;0m'
}
query() {
# usage: query "question" [fallback]; SC_FORCE=1 implies reply is fallback
if [[ $SC_FORCE == 1 ]]; then
REPLY="$2" # fallback used
return 0
fi
echo -n $'\n\e[1;35m'
SH="$(ps -p $$ | tail -n 1 | sed 's/^.* //g')"
if [[ $SH =~ "zsh" ]]; then
printf "%s " "$1 ... "
# shellcheck disable=SC2162
read REPLY
else
# shellcheck disable=SC2162
read -p "$1 ... " REPLY
fi
echo -n $'\e[0;0m'
}
export SC_DRYRUN=0
export SC_FORCE=0