diff --git a/home-manager/programs/fish/default.nix b/home-manager/programs/fish/default.nix index d3464eb1c..193403b88 100644 --- a/home-manager/programs/fish/default.nix +++ b/home-manager/programs/fish/default.nix @@ -82,6 +82,8 @@ j = "jj"; lzd = "lazydocker"; lzg = "lazygit"; + ompc = "omp commit"; + ompcp = "omp commit --push"; v = "nvim"; # Function-based abbreviations @@ -120,6 +122,8 @@ ocxel = "_ocxel_function"; ocxeh = "_ocxeh_function"; ocxelh = "_ocxelh_function"; + ompxe = "_ompxe_function"; + ompxeh = "_ompxeh_function"; pixe = "_pixe_function"; pixel = "_pixel_function"; pixelh = "_pixelh_function"; @@ -220,6 +224,8 @@ "_ocxel_function" "_ocxeh_function" "_ocxelh_function" + "_ompxe_function" + "_ompxeh_function" "_pixe_function" "_pixel_function" "_pixelh_function" diff --git a/home-manager/programs/fish/functions/_ompxe_function.fish b/home-manager/programs/fish/functions/_ompxe_function.fish new file mode 100644 index 000000000..5d2b5e320 --- /dev/null +++ b/home-manager/programs/fish/functions/_ompxe_function.fish @@ -0,0 +1,11 @@ +function _ompxe_function --description "Run OMP with a free-form prompt" + # Run OMP with a free-form prompt (spaces allowed) + # Usage: ompxe [] + + if test (count $argv) -eq 0 + omp + else + set -l prompt (string join " " -- $argv) + omp "$prompt" + end +end diff --git a/home-manager/programs/fish/functions/_ompxeh_function.fish b/home-manager/programs/fish/functions/_ompxeh_function.fish new file mode 100644 index 000000000..e5ff8cd28 --- /dev/null +++ b/home-manager/programs/fish/functions/_ompxeh_function.fish @@ -0,0 +1,12 @@ +function _ompxeh_function --description "Run OMP headlessly with a prompted input" + # Prompt for input and run OMP in print mode + # Usage: ompxeh + + read -P "Prompt: " prompt + if test -z "$prompt" + echo "No prompt provided, aborting." >&2 + return 1 + end + + omp -p "$prompt" +end diff --git a/spec/coverage_spec.sh b/spec/coverage_spec.sh index 7943ed1e9..c1f0de3de 100644 --- a/spec/coverage_spec.sh +++ b/spec/coverage_spec.sh @@ -170,6 +170,34 @@ The path "spec/docker_setup_wrapper_spec.sh" should be exist End End +Describe 'fish shortcut declarations' +FISH_SCRIPT="$PWD/home-manager/programs/fish/default.nix" + +It 'defines ompc abbreviation' +When run grep -F 'ompc = "omp commit";' "$FISH_SCRIPT" +The status should be success +The output should include 'ompc = "omp commit";' +End + +It 'defines ompcp abbreviation' +When run grep -F 'ompcp = "omp commit --push";' "$FISH_SCRIPT" +The status should be success +The output should include 'ompcp = "omp commit --push";' +End + +It 'registers ompxe helper abbreviation' +When run grep -F 'ompxe = "_ompxe_function";' "$FISH_SCRIPT" +The status should be success +The output should include 'ompxe = "_ompxe_function";' +End + +It 'registers ompxeh helper abbreviation' +When run grep -F 'ompxeh = "_ompxeh_function";' "$FISH_SCRIPT" +The status should be success +The output should include 'ompxeh = "_ompxeh_function";' +End +End + Describe 'no shell scripts are missing from coverage list' # This test will fail if a new .sh file is added without updating this spec # When adding a new shell script, add it to this list AND create a corresponding spec file diff --git a/spec/fish/_ompxe_function_test.fish b/spec/fish/_ompxe_function_test.fish new file mode 100644 index 000000000..20a643a82 --- /dev/null +++ b/spec/fish/_ompxe_function_test.fish @@ -0,0 +1,21 @@ +set fn (status dirname)/../../home-manager/programs/fish/functions +source $fn/_ompxe_function.fish + +# ── no args: interactive mode ───────────────────────────── +set log1 (mktemp) +function omp; echo "argc="(count $argv) >> $log1; for arg in $argv; echo "arg=$arg" >> $log1; end; end + +_ompxe_function + +@test "no args calls omp without prompt args" (grep -Fx -c 'argc=0' $log1) -ge 1 + +# ── with args: builds prompt ────────────────────────────── +set log2 (mktemp) +function omp; echo "argc="(count $argv) >> $log2; for arg in $argv; echo "arg=$arg" >> $log2; end; end + +_ompxe_function hello world + +@test "with args passes a single prompt argument" (grep -Fx -c 'argc=1' $log2) -ge 1 +@test "with args preserves spaces in the prompt" (grep -Fx -c 'arg=hello world' $log2) -ge 1 + +rm -f $log1 $log2 diff --git a/spec/fish/_ompxeh_function_test.fish b/spec/fish/_ompxeh_function_test.fish new file mode 100644 index 000000000..ed6271cdd --- /dev/null +++ b/spec/fish/_ompxeh_function_test.fish @@ -0,0 +1,16 @@ +set fn (status dirname)/../../home-manager/programs/fish/functions +source $fn/_ompxeh_function.fish + +@test "empty prompt rejects" (echo "" | _ompxeh_function 2>&1) = "No prompt provided, aborting." +@test "empty prompt returns 1" (echo "" | _ompxeh_function 2>/dev/null; echo $status) = 1 + +set log1 (mktemp) +function omp; echo "argc="(count $argv) >> $log1; for arg in $argv; echo "arg=$arg" >> $log1; end; end + +echo "hello world" | _ompxeh_function + +@test "non-empty prompt passes two arguments" (grep -Fx -c 'argc=2' $log1) -ge 1 +@test "non-empty prompt uses print mode" (grep -Fx -c 'arg=-p' $log1) -ge 1 +@test "non-empty prompt preserves spaces in the prompt" (grep -Fx -c 'arg=hello world' $log1) -ge 1 + +rm -f $log1