Last active
August 29, 2015 14:03
-
-
Save C0mkid/f02be6dfa0b09d1fac27 to your computer and use it in GitHub Desktop.
ttpi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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