Skip to content

Instantly share code, notes, and snippets.

@janx
Last active July 2, 2025 15:52
Show Gist options
  • Save janx/d08fbc1006f7183b14a4 to your computer and use it in GitHub Desktop.
Save janx/d08fbc1006f7183b14a4 to your computer and use it in GitHub Desktop.
Jump to specified window (archlinux + bspwm + dmenu)
#!/usr/bin/env ruby
# get a list of all windows
window_list = `wmctrl -l`.split("\n").map {|l| l.strip.split(' ', 4)}
# write window names to a tmp file
File.open('/tmp/dmenu_goto_windows', 'w') do |f|
window_list.each {|w| f.puts w[3] }
end
# bring up dmenu prompt, ask user to choose from window names in the tmp file
selected = `dmenu -i -fn Tamzen-12 -l 10 -p 'Goto window: ' < /tmp/dmenu_goto_windows`.strip
# find window data using its name
win = window_list.find {|w| w[3] == selected }
# switch to the window
`bspc window -f #{win[0]}` if win
@Echinoidea
Copy link

Echinoidea commented Jul 2, 2025

This is great. Here's the bash version

#!/bin/sh

window_list=$(wmctrl -l)

echo "$window_list" | awk '{$1=$2=$3=""; print substr($0, 4)}' > /tmp/dmenu_goto_windows

selected=$(dmenu -i -l 10 -p "goto window:" < /tmp/dmenu_goto_windows)

win_line=$(echo "$window_list" | grep -F "$selected")
win_id=$(echo "$win_line" | awk '{print $1}')

if [ -n "$win_id" ]; then
  bspc node -f "$win_id"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment