Instantly share code, notes, and snippets.
Very nice. I made a few modifications in order to
The window id is encoded inside the strings passed to rofi hidden inside an html comment, for instace <!-- 264 -->, and retrieved later on using sed.
<!-- 264 -->
# Based on https://gist.github.com/lbonn/89d064cde963cfbacabd77e0d3801398
# In order to have meaningful window names for terminals, use
# inside .vimrc:
# set title
# inside .bashrc:
# export PROMPT_COMMAND='echo -en "\033]0; $("pwd") \a"'
row=$(swaymsg -t get_tree | jq -r '
| select(.type == "workspace") as $ws
| (if .focused == true then "*" else " " end) as $asterisk
| "[\($ws.name)] \($asterisk) <span weight=\"bold\">\(.app_id)</span> - \(.name) <!-- \(.id) -->\u0000icon\u001f\(.app_id)"' \
| sed 's/&/&/g' \
| rofi -dmenu -show-icons -markup-rows)
if [ ! -z "$row" ]
winid=$(echo "$row" | sed 's/.*<!-- \([0-9]*\) -->.*/\1/')
swaymsg "[con_id=$winid] focus"
Sorry, something went wrong.
... and i rewrote this so it works with fuzzel, which involved (unfortunately) removing the fancy pango markup, but it should work with anything that supports dmenu now (as long as it also supports rofi's icon system):