-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Nathan Chancellor <[email protected]>
- Loading branch information
1 parent
f07a6ff
commit d3ed5a2
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env fish | ||
# SPDX-License-Identifier: MIT | ||
# Copyright (C) 2024 Nathan Chancellor | ||
|
||
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 | ||
if not set -q pos_args | ||
set -a py_args $arg | ||
else | ||
set -a pos_args $arg | ||
end | ||
case '*' | ||
set -a pos_args $arg | ||
end | ||
end | ||
$PYTHON_SCRIPTS_FOLDER/tmxrun.py $py_args -- $pos_args | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from argparse import ArgumentParser | ||
from pathlib import Path | ||
import subprocess | ||
import sys | ||
|
||
sys.path.append(str(Path(__file__).resolve().parents[1])) | ||
# pylint: disable=wrong-import-position | ||
import lib.utils | ||
# pylint: enable=wrong-import-position | ||
|
||
parser = ArgumentParser( | ||
description= | ||
'Run command in "tmux new-window" with proper quoting to run in either host or container') | ||
parser.add_argument('-c', | ||
'--container', | ||
action='store_const', | ||
const='container', | ||
dest='mode', | ||
help='Run command in default distrobox container') | ||
parser.add_argument('-H', | ||
'--host', | ||
action='store_const', | ||
const='host', | ||
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('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'] | ||
if args.detach: | ||
tmx_cmd.append('-d') | ||
|
||
CMD_STR = ' '.join(map(str, args.args)) | ||
if mode == 'container': | ||
CMD_STR = f"dbxe -- fish -c '{CMD_STR}'" | ||
tmx_cmd.append(CMD_STR) | ||
|
||
subprocess.run(tmx_cmd, check=True) |