From d86c727ba212b2660e73d2e95edb69e960f46f8d Mon Sep 17 00:00:00 2001 From: Devon Date: Fri, 24 Mar 2023 10:44:55 -0400 Subject: [PATCH] Create tbx command --- fish/functions/enter.fish | 15 ------------ fish/functions/tbx.fish | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 15 deletions(-) delete mode 100644 fish/functions/enter.fish create mode 100644 fish/functions/tbx.fish diff --git a/fish/functions/enter.fish b/fish/functions/enter.fish deleted file mode 100644 index d500e01..0000000 --- a/fish/functions/enter.fish +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env fish - -function enter -d "Enter a toolbox for this project or create one if it does not exist" - set TOOLBOX_NAME (basename $PWD) - - for container in (podman ps --format '{{.Names}}') - if test $container = $TOOLBOX_NAME - toolbox run -c $TOOLBOX_NAME emacs - exit 0 - end - end - - toolbox create --image localhost/dev-base:latest $TOOLBOX_NAME - toolbox run -c $TOOLBOX_NAME emacs -end diff --git a/fish/functions/tbx.fish b/fish/functions/tbx.fish new file mode 100644 index 0000000..e9a92e4 --- /dev/null +++ b/fish/functions/tbx.fish @@ -0,0 +1,48 @@ +#!/usr/bin/env fish +function tbx -d "Enter a toolbox for this project or create one if it does not exist" + set TOOLBOX_NAME (basename $PWD) + set --local CMD $argv[1] + + switch $CMD + case "" + _tbx_create_if_not_exsits + case -h --help + echo "Usage: tbx Create and run emacs in toolbox for the project." + echo " tbx enter Enter the toolbox the project." + echo " tbx create Create a toolbox for the project." + echo " tbx emacs Run emacs in the project's toolbox." + echo "Options:" + echo " -h or --help Print this help message" + + case create + _tbx_create_if_not_exsits + + case enter + toolbox enter $TOOLBOX_NAME + + case emacs + _tbx_start_emacs + + case \* + echo "tbx: Unknown command or option: \"$CMD\" (see tbx -h for usage)" >&2 + return 1 + end +end + +function _tbx_create_if_not_exists + set TOOLBOX_NAME (basename $PWD) + + for container in (podman ps --format '{{.Names}}') + if test $container = $TOOLBOX_NAME + return + end + end + + toolbox create --image localhost/dev-base:latest $TOOLBOX_NAME +end + +function _tbx_start_emacs + set TOOLBOX_NAME (basename $PWD) + + toolbox run -c $TOOLBOX_NAME emacs +end