Moved tmux sections to separate file
This commit is contained in:
parent
0e5fab0104
commit
46080b4363
2 changed files with 73 additions and 65 deletions
|
|
@ -4,7 +4,7 @@ import json
|
|||
import re
|
||||
import time
|
||||
|
||||
from functions.common import *
|
||||
from functions.tmux import *
|
||||
|
||||
# STATIC VARIABLES
|
||||
ATTRIBUTES = {
|
||||
|
|
@ -686,70 +686,6 @@ def secret_screensaver(screensaver=None):
|
|||
raise Exception('Invalid screensaver')
|
||||
run_program(cmd, check=False, pipe=False)
|
||||
|
||||
def tmux_kill_pane(*panes):
|
||||
"""Kill tmux pane by id."""
|
||||
cmd = ['tmux', 'kill-pane', '-t']
|
||||
for pane_id in panes:
|
||||
print(pane_id)
|
||||
run_program(cmd+[pane_id], check=False)
|
||||
|
||||
def tmux_split_window(
|
||||
lines=None, percent=None,
|
||||
behind=False, vertical=False,
|
||||
follow=False, target_pane=None,
|
||||
command=None, text=None, watch=None):
|
||||
"""Run tmux split-window command and return pane_id as str."""
|
||||
# Bail early
|
||||
if not lines and not percent:
|
||||
raise Exception('Neither lines nor percent specified.')
|
||||
if not command and not text and not watch:
|
||||
raise Exception('No command, text, or watch file specified.')
|
||||
|
||||
# Build cmd
|
||||
cmd = ['tmux', 'split-window', '-PF', '#D']
|
||||
if behind:
|
||||
cmd.append('-b')
|
||||
if vertical:
|
||||
cmd.append('-v')
|
||||
else:
|
||||
cmd.append('-h')
|
||||
if not follow:
|
||||
cmd.append('-d')
|
||||
if lines is not None:
|
||||
cmd.extend(['-l', str(lines)])
|
||||
elif percent is not None:
|
||||
cmd.extend(['-p', str(percent)])
|
||||
if target_pane:
|
||||
cmd.extend(['-t', str(target_pane)])
|
||||
|
||||
if command:
|
||||
cmd.extend(command)
|
||||
elif text:
|
||||
cmd.extend(['echo-and-hold "{}"'.format(text)])
|
||||
elif watch:
|
||||
cmd.extend([
|
||||
'watch', '--color', '--no-title',
|
||||
'--interval', '1',
|
||||
'cat', watch])
|
||||
|
||||
# Run and return pane_id
|
||||
result = run_program(cmd)
|
||||
return result.stdout.decode().strip()
|
||||
|
||||
def tmux_update_pane(pane_id, command=None, text=None):
|
||||
"""Respawn with either a new command or new text."""
|
||||
# Bail early
|
||||
if not command and not text:
|
||||
raise Exception('Neither command nor text specified.')
|
||||
|
||||
cmd = ['tmux', 'respawn-pane', '-k', '-t', pane_id]
|
||||
if command:
|
||||
cmd.extend(command)
|
||||
elif text:
|
||||
cmd.extend(['echo-and-hold "{}"'.format(text)])
|
||||
|
||||
run_program(cmd)
|
||||
|
||||
def update_main_options(state, selection, main_options):
|
||||
"""Update menu and state based on selection."""
|
||||
index = int(selection) - 1
|
||||
|
|
|
|||
72
.bin/Scripts/functions/tmux.py
Normal file
72
.bin/Scripts/functions/tmux.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
# Wizard Kit: Functions - tmux
|
||||
|
||||
from functions.common import *
|
||||
|
||||
def tmux_kill_pane(*panes):
|
||||
"""Kill tmux pane by id."""
|
||||
cmd = ['tmux', 'kill-pane', '-t']
|
||||
for pane_id in panes:
|
||||
print(pane_id)
|
||||
run_program(cmd+[pane_id], check=False)
|
||||
|
||||
def tmux_split_window(
|
||||
lines=None, percent=None,
|
||||
behind=False, vertical=False,
|
||||
follow=False, target_pane=None,
|
||||
command=None, text=None, watch=None):
|
||||
"""Run tmux split-window command and return pane_id as str."""
|
||||
# Bail early
|
||||
if not lines and not percent:
|
||||
raise Exception('Neither lines nor percent specified.')
|
||||
if not command and not text and not watch:
|
||||
raise Exception('No command, text, or watch file specified.')
|
||||
|
||||
# Build cmd
|
||||
cmd = ['tmux', 'split-window', '-PF', '#D']
|
||||
if behind:
|
||||
cmd.append('-b')
|
||||
if vertical:
|
||||
cmd.append('-v')
|
||||
else:
|
||||
cmd.append('-h')
|
||||
if not follow:
|
||||
cmd.append('-d')
|
||||
if lines is not None:
|
||||
cmd.extend(['-l', str(lines)])
|
||||
elif percent is not None:
|
||||
cmd.extend(['-p', str(percent)])
|
||||
if target_pane:
|
||||
cmd.extend(['-t', str(target_pane)])
|
||||
|
||||
if command:
|
||||
cmd.extend(command)
|
||||
elif text:
|
||||
cmd.extend(['echo-and-hold "{}"'.format(text)])
|
||||
elif watch:
|
||||
cmd.extend([
|
||||
'watch', '--color', '--no-title',
|
||||
'--interval', '1',
|
||||
'cat', watch])
|
||||
|
||||
# Run and return pane_id
|
||||
result = run_program(cmd)
|
||||
return result.stdout.decode().strip()
|
||||
|
||||
def tmux_update_pane(pane_id, command=None, text=None):
|
||||
"""Respawn with either a new command or new text."""
|
||||
# Bail early
|
||||
if not command and not text:
|
||||
raise Exception('Neither command nor text specified.')
|
||||
|
||||
cmd = ['tmux', 'respawn-pane', '-k', '-t', pane_id]
|
||||
if command:
|
||||
cmd.extend(command)
|
||||
elif text:
|
||||
cmd.extend(['echo-and-hold "{}"'.format(text)])
|
||||
|
||||
run_program(cmd)
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("This file is not meant to be called directly.")
|
||||
|
||||
# vim: sts=2 sw=2 ts=2
|
||||
Loading…
Reference in a new issue