Skip to content

Instantly share code, notes, and snippets.

@dohzya
Last active March 9, 2017 12:52
Show Gist options
  • Save dohzya/6ad2a6a6765f43ab9c52 to your computer and use it in GitHub Desktop.
Save dohzya/6ad2a6a6765f43ab9c52 to your computer and use it in GitHub Desktop.
List tmux sessions (for every sockets)
#!/usr/bin/env ruby
sockets = %x(ps ax -o args=).lines.grep(/tmux.*-L/).map{|l| l.chomp.match(/-L +([^ ]+)/)[1] }.uniq
servers = [['default', nil]] + sockets.sort.map{|s| [s, s] }
res = []
servers.each do |srv, sock|
res << "#{srv}:"
arg = sock ? "-L #{sock}" : ""
%x(tmux #{arg} ls 2> /dev/null).each_line{|l| res << "- #{l.chomp}" }
res << ""
end
puts res.join("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment