-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
·66 lines (55 loc) · 1.18 KB
/
run
File metadata and controls
executable file
·66 lines (55 loc) · 1.18 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
#!/usr/bin/env bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
SCRIPT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
FILTER=""
DRY=false
ALL=false
ACTIONS=""
usage() {
local prog=${0##*/}
cat << EOF
Usage: $prog [options]
Run dev-env setup actions.
Options
-h Print usage message
-d Perform a dry run (no execution)
-a Run all actions (skips actions starting with '_' except for '__init')
EOF
}
log() {
if $DRY; then
echo -e "${RED}[DRY RUN]:${NC} $@"
else
echo -e "$@"
fi
}
execute() {
log "${GREEN}execute $@${NC}"
if $DRY; then
return
fi
"$@"
}
main() {
local opt OPTIND OPTARG
while getopts 'dah' opt; do
case "$opt" in
d) DRY=true;;
a) ALL=true;;
h) usage; return 0;;
*) usage; return 1;;
esac
done
cd $SCRIPT_DIR
if $ALL; then
selected_actions=$(find ./actions -executable -type f -not -name '_[a-z]*' -printf '%f\n' | LC_COLLATE=C sort)
else
selected_actions=$(find ./actions -executable -type f -printf '%f\n' | LC_COLLATE=C sort -r | fzf -m --bind 'space:toggle+clear-query' --marker ' ')
fi
for action in $selected_actions; do
execute ./actions/$action
done
}
main "$@"