q.sh/q-run

28 lines
640 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() {
{
IFS=:; for d in $PATH; do for f in $d/*; do [ -f $f ] && [ -x $f ] && echo ${f##*/}; done; done;
2023-05-14 19:24:27 +00:00
} | $ENV_sort | $ENV_uniq
}
if [[ -z "$@" ]]; then
echo "^run [a-zA-Z0-9_-]*$"
elif [[ "$1" == "--hint" ]]; then
2023-05-14 19:24:27 +00:00
find_all_executables | $ENV_awk '{print $1 " run " $1}'
elif [[ "$1" == "--complete" ]]; then
shift
2023-05-14 19:24:27 +00:00
find_all_executables | $ENV_awk '{print $1 " run " $1}'
elif [[ "$1" == "--preview" ]]; then
shift
echo "Will run $1"
elif [[ "$1" == "--run" ]]; then
shift
(nohup "$1" 2>/dev/null &)
sleep 0.01
fi