Repository navigation
Expand file tree
/
Copy pathscripts.sh
More file actions
executable file
·91 lines (84 loc) · 2.09 KB
/
Copy pathscripts.sh
File metadata and controls
executable file
·91 lines (84 loc) · 2.09 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
83
84
85
86
87
88
89
90
91
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MODULES_DIR="$SCRIPT_DIR/modules"
run_module() {
local name="$1"
local mod="$MODULES_DIR/$name"
if [[ -f "$mod" ]]; then
bash "$mod"
else
echo "module not found: $name" >&2
return 1
fi
}
# pass args: each arg is a module filename to run directly
if [[ $# -ne 0 ]]; then
for var in "$@"; do
run_module "$var"
done
exit 0
fi
shopt -s nullglob
mods=( "$MODULES_DIR"/*.sh )
shopt -u nullglob
filtered=()
for m in "${mods[@]}"; do
[[ "$(basename "$m")" == "util.sh" ]] && continue
filtered+=("$m")
done
cols="$(tput cols 2>/dev/null || echo 120)"
while true; do
echo
n=1
current_group=""
items=()
print_group() {
printf '%s\n' "${items[@]}" | column -c "$cols"
items=()
}
for m in "${filtered[@]}"; do
name="$(basename "$m" .sh)"
group="${name%%_*}"
if [[ "$group" != "$current_group" ]]; then
[[ -n "$current_group" ]] && print_group
echo
echo "$group"
echo "-------------------"
current_group="$group"
fi
display="${name#*_}"
display="${display//_/ }"
items+=("$(printf "%2d) %s" "$n" "$display")")
n=$((n+1))
done
print_group
echo
IFS= read -rn1 -p "Select a number, q/Esc to quit: " key || break
if [[ "$key" == $'\e' ]]; then
break
fi
if [[ -n "$key" ]]; then
read -r rest
choice="$key$rest"
else
choice=""
fi
case "$choice" in
q|Q) break ;;
''|*[!0-9]*) echo "invalid selection" ;;
*)
idx=$((choice - 1))
if (( idx >= 0 && idx < ${#filtered[@]} )); then
mod="${filtered[$idx]}"
if bash "$mod"; then
echo "done: $(basename "$mod")"
else
echo "failed: $(basename "$mod") (exit $?)"
fi
else
echo "invalid number"
fi
;;
esac
done