1 # Prompt for a programs to run
4 CACHE="${XDG_CACHE_HOME:-$HOME/.cache}"
9 printf 'Usage: %s [cmd [args...] [+]]
11 cmd do not prompt for a command and run cmd right away
12 args do not prompt for arguments neither and use arg
13 + if present after the arguments, prompt for a path\n' "${0##*/}"
18 # Update the cache and get the command to run.
22 local IFS=':' update=''
26 [ "$CACHE/iomenu/run" -ot "$dir" ] && update=1
29 [ "$update" ] && find -L $PATH -type f -exec test -x {} \; -print |
30 sed 's|.*/||' | sort -u > "$CACHE/iomenu/run"
35 # Prompt for options for a given command and log it to an history file
42 printf '%s ' "$command" >> "$CACHE/iomenu/history"
44 while read -r cmd options
46 [ "$command" = "$cmd" -a "$options" ] && printf '%s\n' "$options"
47 done < $CACHE/iomenu/history |
48 iomenu -p "$command" |
49 tee -a "$CACHE/iomenu/history"
51 sort -u "$CACHE/iomenu/history" -o "$CACHE/iomenu/history"
56 # Prompt for a file path in $HOME and print it.
60 find "$HOME" ! -path '*/.cache/*' ! -path '*/.git/*' |
61 sed -r "s/.{${#HOME}}/~/" | iomenu -l 256 | sed 's/^~//'
66 # Get the options according to the command and run it
70 local command="$1" options=""
73 [ $# -gt 0 ] && shift && options="$*"
75 command="${command:-$(
76 iomenu -l 256 -s '#' < "$CACHE/iomenu/run"
79 [ -z "$command" ] && exit 1
81 if [ "${command##* *}" ]
83 [ -z "$options" ] && options="$(get_options "$command")"
85 # if '+' at the end of options, prompt for a path
86 if [ "$options" -a -z "${options%%*+}" ]
88 path="$(get_path)" options="${options%+}"
92 [ "$path" ] && exec $command $options "$path" || exec $command $options
98 mkdir -p "$CACHE/iomenu"
100 if [ $# -gt 0 -a -z "${1##-*}" ]