dot

packages and services management
Log | Files | Refs | README

commit 4c214db2b263e73b005a8699446377e976397776
parent 018618b9f820cf712e8fc2bcb2a1628ccedc7802
Author: josuah <mail@josuah.net>
Date:   Sat, 19 Nov 2016 00:38:26 -0500

Whatis generation for iomenu

Diffstat:
Mbin/buffer | 52++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 46 insertions(+), 6 deletions(-)

diff --git a/bin/buffer b/bin/buffer @@ -9,7 +9,7 @@ # Busybox: mkdir, sort, tr, sed, exec -CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/dmenu_run" +CACHE="${XDG_CACHE_HOME:-$HOME/.cache}" COMMAND="$2" NL=' ' TAB=' ' @@ -20,15 +20,44 @@ NL=' # update_cache() { - mkdir -p "${CACHE%/*}" + mkdir -p "$CACHE" # get the command name from cache or stest IFS=':' - if stest -dqr -n "$CACHE" $PATH + if stest -dqr -n "$CACHE/dmenu_run" $PATH then - stest -flx $PATH | sort -u > "$CACHE" + stest -flx $PATH | sort -u > "$CACHE/dmenu_run" fi unset IFS + + # populate iomenu cache from dmenu's cache + if [ ! -f "$CACHE/iomenu_run" ] + then + cp "$CACHE/dmenu_run" "$CACHE/iomenu_run" + fi +} + + +# +# Generate descriptions of commands from whatis(1). This takes a lot of time. +# +update_descriptions() +{ + local whatis + + update_cache + + while IFS= read -r command + do + whatis="$(whatis -s 1 "$command" 2> /dev/null | tail -n 1)" + if [ "$whatis" ] + then + printf '%-20s # %-20s %s\n' \ + "$command" "${whatis% - *}" "${whatis#* - }" + else + printf '%s\n' "$command" + fi + done < $CACHE/dmenu_run > "$CACHE/iomenu_run" } @@ -71,13 +100,13 @@ get_name() # # Get the options according to the command and run it # -main() +run() { local command="${1:-$( iomenu -l 256 -s '#' << EOF | tr / ! # $(abduco | tr ! / | sed -r '2,$ s/(.*)\t(.*)/\2 # \1/') # Commands -$(cat "$CACHE") +$(cat "$CACHE/iomenu_run") EOF )}" options path @@ -131,4 +160,15 @@ EOF } +main() +{ + if [ "$1" = '-u' ] + then + update_descriptions + else + update_cache + run $@ + fi +} + main $@