Skip to content

Instantly share code, notes, and snippets.

@C0mkid
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save C0mkid/f02be6dfa0b09d1fac27 to your computer and use it in GitHub Desktop.
Save C0mkid/f02be6dfa0b09d1fac27 to your computer and use it in GitHub Desktop.
ttpi
#!/usr/bin/python2.7
from subprocess import check_output, STDOUT, CalledProcessError, call
from sys import argv, stdout, stdin
import fileinput
def run(func):
if type(func) != type([]) and type(func) == type(""):
func = func.split(' ')
try:
out = check_output(func, stderr=STDOUT)[:-1]
except CalledProcessError as o:
out = o.output[:-1]
return out
ls = run('tmux ls')
if len(argv) == 1 and 'windows' in ls:
print ls
exit()
names = [i.split(":")[0]for i in ls.split("\n")]
if len(argv) == 1:
argv = ['tt', '0']
if argv[1] in names:
call(['tmux', 'attach', '-t', argv[1]])
exit()
response = ''
while response != 'y':
if not 'windows' in ls:
out = 'no sessions, create one called "%s"? (y/n) '
else:
out = 'session "%s" does not exist, create it? (y/n) '
stdout.write(out % argv[1])
response = stdin.readline()[:-1].lower()
if response == 'y':
call(['tmux', 'new-session', '-s', argv[1]])
elif response == 'n':
exit()
@nathyong
Copy link

nathyong commented Nov 1, 2014

I fixed up your indentation and added support for exiting gracefully on a captured C-c. My fork is at https://gist.github.com/nathyong/c18c91c1f16785e08293

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