[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] WINID completion for herbstcommander



---
 scripts/herbstcommander.sh | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/scripts/herbstcommander.sh b/scripts/herbstcommander.sh
index 77e8c3f..d0a09cf 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,45 @@ 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) )
+				i=1
+				completion=$(
+					wmctrl -l | while read line; do
+						fields=( $line )
+						id=${fields[0]}
+						tag=${tags[ ${fields[1]} ]}
+						class=$(xprop -notype -id $id WM_CLASS |
+							sed 's/.*\?= *//; s/"\(.*\?\)", *"\(.*\?\)".*/\1,\2/')
+						title=${fields[ _at_ ]:3}
+						printf "%-3s %s %-3s [%s] %s\n" "$i)" "$id" "$tag" "$class" "$title"
+						i=$((i+1))
+					done
+				)
+
+				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)
+					fields=( $next )
+					cmd+=( ${fields[1]} )
+					;;
+				*)
+					cmd+=( $next )
+					;;
+			esac
 		fi
 	fi
 done
-- 
1.7.12