Skip to content

Commit

Permalink
tmxrun: Add support for 'split-window'
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Chancellor <[email protected]>
  • Loading branch information
nathanchance committed Dec 10, 2024
1 parent 1a68baa commit 43eb1f8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fish/functions/tmxrun.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function tmxrun -d "Wrapper for tmxrun.py"
# The duplication is sad but it is so much better to handle adding -- in the wrapper function
for arg in $argv
switch $arg
case -c -d -H --container --detach --host
case -c -d -H -s -v --container --detach --host --split-horizontal --split-vertical
if not set -q pos_args
set -a py_args $arg
else
Expand Down
23 changes: 19 additions & 4 deletions python/scripts/tmxrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
# pylint: enable=wrong-import-position

parser = ArgumentParser(
description=
'Run command in "tmux new-window" with proper quoting to run in either host or container')
description='Run command in tmux with proper quoting to run in either host or container')
parser.add_argument('-c',
'--container',
action='store_const',
Expand All @@ -26,16 +25,32 @@
dest='mode',
help='Run command on the host')
parser.add_argument('-d', '--detach', action='store_true', help='Do not switch to created window')
parser.add_argument('-s',
'--split-horizontal',
action='store_const',
const=['split-window', '-v'],
dest='cmd',
help='Split command in a horizontal pane')
parser.add_argument('-v',
'--split-vertical',
action='store_const',
const=['split-window', '-H'],
dest='cmd',
help='Split command in a vertical pane')
parser.add_argument('args', nargs='+', help='Command and any arguments to run')
args = parser.parse_args()

mode = args.mode if args.mode else 'container' if lib.utils.in_container() else 'host'

tmx_cmd = ['tmux', 'new-window']
tmx_cmd = ['tmux']
if args.cmd:
tmx_cmd += args.cmd
else:
tmx_cmd.append('new-window')
if args.detach:
tmx_cmd.append('-d')

CMD_STR = ' '.join(map(str, args.args))
CMD_STR = ' '.join(args.args)
if mode == 'container':
CMD_STR = f"dbxe -- fish -c '{CMD_STR}'"
tmx_cmd.append(CMD_STR)
Expand Down

0 comments on commit 43eb1f8

Please sign in to comment.