Skip to content

Instantly share code, notes, and snippets.

@carlzulauf
Created April 16, 2017 08:51
Show Gist options
  • Save carlzulauf/90808fc8fe0b43fce3f28d9bf29aeb96 to your computer and use it in GitHub Desktop.
Save carlzulauf/90808fc8fe0b43fce3f28d9bf29aeb96 to your computer and use it in GitHub Desktop.
use wmctrl and gtk-launch to bring an existing window to the front or launch the app
#!/usr/bin/ruby
base_cmd = ARGV[0]
cmd_pattern = Regexp.new(base_cmd)
running = `wmctrl -lx`.lines.grep(cmd_pattern)
if running.any?
window_id = running.first.match(/0x[0-9a-f]{8}/)[0]
exec "wmctrl -ia #{window_id}"
else
puts "starting: #{ARGV.join(' ')}"
exec "gtk-launch", *ARGV
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment