q.sh/q-run

27 lines
574 B
Text
Raw Normal View History

#!/bin/sh
2023-05-14 19:24:27 +00:00
ENV_awk=awk
ENV_sort=sort
ENV_uniq=uniq
find_all_executables() {
2024-11-03 01:52:52 +00:00
{
IFS=:; for d in $PATH; do for f in $d/*; do [ -f $f ] && [ -x $f ] && echo ${f##*/}; done; done;
} | $ENV_sort | $ENV_uniq
}
if [[ -z "$@" ]]; then
2024-11-03 01:52:52 +00:00
echo "^run [a-zA-Z0-9_-]*$"
elif [[ "$1" == "--hint" ]]; then
2024-11-03 01:52:52 +00:00
find_all_executables | $ENV_awk '{print $1 " run " $1}'
elif [[ "$1" == "--complete" ]]; then
2024-11-03 01:52:52 +00:00
shift
find_all_executables | $ENV_awk '{print $1 " run " $1}'
elif [[ "$1" == "--preview" ]]; then
2024-11-03 01:52:52 +00:00
shift
echo "Will run $1"
elif [[ "$1" == "--run" ]]; then
2024-11-03 01:52:52 +00:00
shift
setsid "$1"
fi