Add auto apply scripts
This commit is contained in:
62
interactive.sh
Executable file
62
interactive.sh
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
|
||||
dirs=()
|
||||
for d in */ ; do
|
||||
dirs+=("${d%/}")
|
||||
done
|
||||
|
||||
selected=()
|
||||
for ((i=0; i<${#dirs[@]}; i++)); do
|
||||
selected[i]=0
|
||||
done
|
||||
|
||||
stty -echo -icanon time 0 min 0
|
||||
|
||||
current=0
|
||||
while true; do
|
||||
clear
|
||||
echo "Use ↑/↓ to move, space to select, Enter to confirm."
|
||||
for ((i=0; i<${#dirs[@]}; i++)); do
|
||||
mark="[ ]"
|
||||
[[ ${selected[i]} -eq 1 ]] && mark="[x]"
|
||||
if [[ $i -eq $current ]]; then
|
||||
echo -e "> \e[7m$mark ${dirs[i]}\e[0m"
|
||||
else
|
||||
echo " $mark ${dirs[i]}"
|
||||
fi
|
||||
done
|
||||
|
||||
IFS= read -rsn1 key
|
||||
if [[ $key == $'\x1b' ]]; then
|
||||
read -rsn2 -t 0.1 key2
|
||||
key+=$key2
|
||||
fi
|
||||
|
||||
case "$key" in
|
||||
$'\x1b[A') ((current--)) ;; # Up
|
||||
$'\x1b[B') ((current++)) ;; # Down
|
||||
" ")
|
||||
selected[$current]=$((1 - selected[$current]))
|
||||
;;
|
||||
"")
|
||||
break
|
||||
;;
|
||||
esac
|
||||
|
||||
((current<0)) && current=$((${#dirs[@]}-1))
|
||||
((current>=${#dirs[@]})) && current=0
|
||||
done
|
||||
|
||||
stty sane
|
||||
|
||||
for ((i=0; i<${#dirs[@]}; i++)); do
|
||||
if [[ ${selected[i]} -eq 1 ]]; then
|
||||
dir="${dirs[i]}"
|
||||
if [[ -f "$dir/apply.sh" ]]; then
|
||||
echo "Running apply.sh in $dir"
|
||||
(cd "$dir" && bash apply.sh)
|
||||
else
|
||||
echo "No apply.sh found in $dir"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user