1
Fork 0

bash: add 2command.sh script

This commit is contained in:
Alan Faubert 2024-12-16 20:58:06 -05:00
parent 890ca49e05
commit 465693b3f0
3 changed files with 11 additions and 0 deletions

1
bash/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/2command.txt

View file

@ -12,6 +12,7 @@ If you create additional `~/.bashrc.d/*` or `~/.profile.d/*` files, they will al
## Scripts
- [`2command.sh`](scripts/2command.sh) - display a menu of commands to select to run from `bash/2command.txt`, one per line
- [`2link.sh`](scripts/2link.sh) - create relative symlinks to files or directories from given directory
- [`2path.sh`](scripts/2path.sh) - create symlinks to files or directories from `~/.local/bin`, giving unique names to directories
- [`syncfiles.sh`](scripts/syncfiles.sh) - given paths to two or more files, prompt to copy the newest one over each of the ones it differs from

9
bash/scripts/2command.sh Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
dir="$(dirname "$(dirname "$(readlink --canonicalize "$0")")")"
awk '{print FNR ") " $0}' "$dir"/2command.txt
printf 'Selection: '
if [ "$1" ]; then num="$1"; echo "$num"; else read num; fi
{ [ "$num" -ge 1 ] && [ "$num" -le $(cat "$dir"/2command.txt | wc --lines) ]; } 2> /dev/null || exit 1
cmd="$(tail --lines=+$num "$dir"/2command.txt | head --lines=1)"
echo "$num) $cmd"
eval "$cmd"