Skip to content

Instantly share code, notes, and snippets.

@talpay
Last active August 31, 2020 09:28
Show Gist options
  • Save talpay/0d7057ef9b648d30311ab07f8dd9bb48 to your computer and use it in GitHub Desktop.
Save talpay/0d7057ef9b648d30311ab07f8dd9bb48 to your computer and use it in GitHub Desktop.
Generate command in Python to launch multiple commands in tmux via 1 step.
# parse multiple CL commands into a single tmux command
# each line = 1 command = 1 tmux tab
commands = """
nvidia-smi -l 1
htop
python myprogram.py --trials 10 --expid 502
python myprogram.py --trials 10 --expid 554
python myprogram.py --trials 10 --expid 574
"""
comms = commands.split("\n")
for d in comms:
if d == '': comms.remove(d)
print(comms)
res = ['tmux new-session \; \\']
for c in comms:
res.append(" send-keys \'"+c+"\' C-m \; \\")
res.append(" neww \; \\")
res = res[:-1]
print("\n".join(res)) # copy the output into the command line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment