1 # Detacheable buffer for programs and files
4 CACHE="${XDG_CACHE_HOME:-$HOME/.cache}"
9 printf '%s\n' "${0##*/} [-w] [cmd [args...]]
11 -w update command description using whatis
12 cmd do not prompt for a command and run CMD right away
13 args do not prompt for arguments neither and use ARG"
18 # Update the cache and get the command to run.
20 update_commands_cache()
22 # get the command name from cache or stest
24 if stest -dqr -n "$CACHE/dmenu_run" $PATH
26 stest -flx $PATH | sort -u > "$CACHE/dmenu_run"
27 cp "$CACHE/dmenu_run" "$CACHE/iomenu/run"
34 # Generate descriptions of commands from whatis(1). This takes a lot of time.
36 update_descriptions_cache()
42 while IFS= read -r command
44 whatis="$(man -f -s 1 "$command" 2> /dev/null | tail -n 1)"
47 printf '%-20s # %s\n' \
48 "$command" "${whatis#* - }"
50 printf '%s\n' "$command"
52 done < $CACHE/dmenu_run > "$CACHE/iomenu/run"
57 # Prompt for options for a given command and log it to an history file
64 printf '%s ' "$command" >> "$CACHE/iomenu/history"
66 while read -r cmd options
68 [ "$command" = "$cmd" -a "$options" ] && printf '%s\n' "$options"
69 done < $CACHE/iomenu/history |
70 iomenu -p "$command" |
71 tee -a "$CACHE/iomenu/history"
73 sort -u "$CACHE/iomenu/history" -o "$CACHE/iomenu/history"
78 # Prompt for a file path in $HOME and print it.
84 find "$HOME" -type f ! -path '*/.cache/*' ! -path '*/.git/*' |
85 sed -r "s/.{${#HOME}}/~/" |
92 # Get the options according to the command and run it
96 local command="$1" options=""
99 [ $# -gt 0 ] && shift && options="$*"
101 command="${command:-$(
102 iomenu -l 256 -s '#' << EOF | tr / !
104 # $(abduco | tr ! / | sed -r '2,$ s/(.*)\t(.*)/\2 # \1/')
107 $(cat "$CACHE/iomenu/run")
111 [ -z "$command" ] && exit 1
113 # prompt for option if needed
114 if [ "${command##* *}" ]
116 [ -z "$options" ] && options="$( get_options "$command")"
118 # if '+' is at the end of the options then prompt for a path
119 if [ -z "${options%%*+}" -a "$options" ]
121 path="$(get_path)" options="${options%+}"
125 name="$command${options:+ $options}${path:+ ~${path#$HOME}}"
126 name="$(printf %s "$name" | tr / !)"
128 export TERM='screen' ABDUCO="$command"
130 # run new or existing session with this name
133 exec abduco -e ^Z -A "$name" $command $options "$path"
135 exec abduco -e ^Z -A "$name" $command $options
142 mkdir -p "$CACHE/iomenu"
146 update_descriptions_cache
147 elif [ $# -gt 0 -a -z "${1##-*}" ]
151 update_commands_cache