1 # detacheable buffer for programs and files using abduco
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 + While at the end of the arguments, prompt for a file\n' "${0##*/}"
18 # Update the cache and get the command to run.
24 if stest -dqr -n "$CACHE/dmenu_run" $PATH
26 stest -flx $PATH | sort -u > "$CACHE/dmenu_run"
32 # Prompt for options for a given command and log it to an history file
39 printf '%s ' "$command" >> "$CACHE/iomenu/history"
41 while read -r cmd options
43 [ "$command" = "$cmd" -a "$options" ] && printf '%s\n' "$options"
44 done < $CACHE/iomenu/history |
45 iomenu -p "$command" |
46 tee -a "$CACHE/iomenu/history"
48 sort -u "$CACHE/iomenu/history" -o "$CACHE/iomenu/history"
53 # Prompt for a file path in $HOME and print it.
57 find "$HOME" -type f ! -path '*/.cache/*' ! -path '*/.git/*' |
58 sed -r "s/.{${#HOME}}/~/" | iomenu -l 256 | sed 's/^~//'
63 # Get the options according to the command and run it
67 local command="$1" options=""
70 [ $# -gt 0 ] && shift && options="$*"
72 command="${command:-$(
73 iomenu -l 256 -s '#' << EOF | tr / !
75 # $(abduco | tr ! / | sed -r '2,$ s/(.*)\t(.*)/\2 # \1/')
78 $(cat "$CACHE/dmenu_run")
82 if [ -z "$command" -o "$ABDUCO" -a -z "${name##*dvtm*}" ]
86 elif [ -z "$ABDUCO" -a -z "${command##*dvtm*}" ]
88 TERM='screen' ABDUCO='dvtm' exec abduco -A 'dvtm' dvtm-status
90 elif [ "${command##* *}" ]
92 [ -z "$options" ] && options="$(get_options "$command")"
94 # if '+' is at the end of options, prompt for a path
95 if [ "$options" -a -z "${options%%*+}" ]
97 path="$(get_path)" options="${options%+}"
101 name="$command${options:+ $options}${path:+ ~${path#$HOME}}"
102 name="$(printf %s "$name" | tr / !)"
104 export TERM='screen' ABDUCO="$command"
108 exec abduco -e ^Z -A "$name" $command $options "$path"
110 exec abduco -e ^Z -A "$name" $command $options
119 if [ $# -gt 0 -a -z "${1##-*}" ]