1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#!/bin/bash
# herbstcommander.sh - launch herbstluftwm-commands via dmenu
# Written by Florian Bruhin <me@the-compiler.org>
# To customize dmenu-colors, create a file named "herbstcommander" in your
# herbstluftwm config-directory, with something like this in it:
#
# dmenu_cmd="dmenu -i -b -nb #313131 -nf #686868 -sb #454545 -sf #898989"
#
# You can also directly pass dmenu-arguments to this script instead, as long
# as dmenu_cmd is undefined.
config_1="$XDG_CONFIG_HOME/herbstluftwm/herbstcommander"
config_2="$HOME/.config/herbstluftwm/herbstcommander"
[[ -f "$config_1" ]] && source "$config_1"
[[ -f "$config_2" ]] && source "$config_2"
dmenu_cmd=${dmenu_cmd:-dmenu $@}
herbstclient_cmd=${herbstclient_cmd:-herbstclient}
prompt=${prompt:-herbstluft: }
display_reply=${display_reply:-true}
cmd=()
forceexec=0
while :; do
if [[ "$forceexec" != 1 ]]; then
completion=$($herbstclient_cmd complete "${#cmd[@]}" "${cmd[@]}")
if [[ "$?" = 7 ]] ; then
forceexec=1
fi
fi
if [[ "$forceexec" == 1 ]]; then
echo "Executing ${cmd[@]}"
reply=$($herbstclient_cmd "${cmd[@]}")
status=$?
if [[ "$display_reply" && "$reply" ]]; then
$dmenu_cmd -p "${cmd[*]}" <<< "$reply" >/dev/null
fi
exit $status
else
next=$($dmenu_cmd -p "${prompt}${cmd[*]}" <<< "$completion")
(( $? != 0 )) && exit 125 # dmenu was killed
if [[ -z "$next" ]]; then
forceexec=1 # empty reply instead of cmpletion
else
cmd+=( $next )
fi
fi
done
|