[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] WINID completion for herbstcommander
- To: herbstluftwm _minus_ devel _at_ lists _dot_ sourceforge _dot_ net
- Subject: [PATCH] WINID completion for herbstcommander
- From: Gabor Adam Toth <tg _at_ tgbit _dot_ net>
- Date: Tue, 25 Sep 2012 06:49:42 +0200
---
scripts/herbstcommander.sh | 43 +++++++++++++++++++++++++++++++++++++++----
scripts/wselect.sh | 4 ++--
2 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/scripts/herbstcommander.sh b/scripts/herbstcommander.sh
index 77e8c3f..41135fc 100755
--- a/scripts/herbstcommander.sh
+++ b/scripts/herbstcommander.sh
@@ -26,6 +26,7 @@ cmd=( "$@" )
forceexec=0
while :; do
+ dmenu_args=
if [[ "$forceexec" != 1 ]]; then
completion=$($herbstclient_cmd complete "${#cmd[ _at_ ]}" "${cmd[ _at_ ]}")
if [[ "$?" = 7 ]] ; then
@@ -37,16 +38,50 @@ while :; do
reply=$($herbstclient_cmd "${cmd[ _at_ ]}")
status=$?
if [[ "$display_reply" && "$reply" ]]; then
- $dmenu_cmd -p "${cmd[*]}" <<< "$reply" >/dev/null
+ $dmenu_cmd -p "${cmd[*]}" <<< "$reply" >/dev/null
fi
exit $status
else
- next=$($dmenu_cmd -p "${prompt}${cmd[*]}" <<< "$completion")
+ case "${cmd[*]}" in
+ raise|jumpto|bring)
+ tags=( $($herbstclient_cmd tag_status) )
+ IFS=$'\n'
+ completion=
+ n=
+ i=1
+ for line in $(wmctrl -lp); do
+ IFS=' '
+ f=( $line )
+ id=${f[0]}
+ tag=${tags[ ${f[1]} ]}
+ comm=$(ps -o comm= ${f[2]})
+ title=${f[ _at_ ]:4}
+ line=$(printf "%2d) %s %-3s [%s] %s" $i $id $tag $comm "$title")
+ if [ -n "$completion" ]; then
+ n=$'\n';
+ fi
+ completion=$completion$n$line
+ i=$((i+1))
+ done
+ IFS=' '
+ dmenu_args='-l 10'
+ ;;
+ esac
+ next=$($dmenu_cmd $dmenu_args -p "${prompt}${cmd[*]}" <<< "$completion")
(( $? != 0 )) && exit 125 # dmenu was killed
if [[ -z "$next" ]]; then
- forceexec=1 # empty reply instead of cmpletion
+ forceexec=1 # empty reply instead of completion
else
- cmd+=( $next )
+ case "${cmd[*]}" in
+ raise|jumpto|bring)
+ # add the WINID only (second field)
+ args=( $next )
+ cmd+=( ${args[1]} )
+ ;;
+ *)
+ cmd+=( $next )
+ ;;
+ esac
fi
fi
done
diff --git a/scripts/wselect.sh b/scripts/wselect.sh
index 63517f4..af6197a 100755
--- a/scripts/wselect.sh
+++ b/scripts/wselect.sh
@@ -4,7 +4,7 @@
# dependences: wmctrl, awk,
# dmenu with multiline support (command line flag -l)
-dmenu_command=${dmenu_command:-dmenu}
+dmenu_command=${dmenu_command:-dmenu -i}
dmenu_lines=${dmenu_lines:-10}
case "$1" in
@@ -22,7 +22,7 @@ case "$1" in
;;
esac
-id=$(wmctrl -l |cat -n| sed 's/\t/) /g'| sed 's/^[ ]*//' \
+id=$(wmctrl -l | cat -n | sed 's/\t/) /g; s/^[ ]*//; s/^\([0-9])\)/ \1/' \
| $dmenu_command -l $dmenu_lines -p "$name") \
&& action $(awk '{ print $2 ; }' <<< "$id")
--
1.7.12