Skip to content

Instantly share code, notes, and snippets.

@jamesdabbs
Created January 23, 2014 17:07
Show Gist options
  • Save jamesdabbs/8582575 to your computer and use it in GitHub Desktop.
Save jamesdabbs/8582575 to your computer and use it in GitHub Desktop.
Tmux wrapper w/ zsh autocomplete
## In `.zshrc`
# The autocomplete function should set `reply` to an array of possibilities
function tmux_sessions() { reply=( $(ta --available) ) }
compctl -K tmux_sessions ta
## In `/path/to/ta` - which should be executable and on your path
#!/usr/bin/env ruby
session = ARGV.first
if session == "--available"
puts `tmux list-sessions`.lines.map { |l| l.split(":").first }.join " "
exit
end
opts = session.nil? ? "" : "-t #{session}"
cmd = ENV['TMUX'] ? "switch" : "attach"
system "tmux #{cmd} #{opts}".strip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment