Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions home-manager/programs/fish/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
j = "jj";
lzd = "lazydocker";
lzg = "lazygit";
ompc = "omp commit";
ompcp = "omp commit --push";
v = "nvim";

# Function-based abbreviations
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -220,6 +224,8 @@
"_ocxel_function"
"_ocxeh_function"
"_ocxelh_function"
"_ompxe_function"
"_ompxeh_function"
"_pixe_function"
"_pixel_function"
"_pixelh_function"
Expand Down
11 changes: 11 additions & 0 deletions home-manager/programs/fish/functions/_ompxe_function.fish
Original file line number Diff line number Diff line change
@@ -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 [<prompt words...>]

if test (count $argv) -eq 0
omp
else
set -l prompt (string join " " -- $argv)
omp "$prompt"
end
end
12 changes: 12 additions & 0 deletions home-manager/programs/fish/functions/_ompxeh_function.fish
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions spec/coverage_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions spec/fish/_ompxe_function_test.fish
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +4 to +21

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve test isolation and avoid redefining the omp mock function in the global scope, it's better to wrap each test case in a begin...end block. This scopes the mock function and log file variables locally to each test, making the tests more robust and self-contained.

# ── no args: interactive mode ─────────────────────────────
begin
    set -l log (mktemp)
    function omp; echo "argc="(count $argv) >> $log; for arg in $argv; echo "arg=$arg" >> $log; end; end

    _ompxe_function

    @test "no args calls omp without prompt args" (grep -Fx -c 'argc=0' $log) -ge 1
    rm -f $log
end

# ── with args: builds prompt ──────────────────────────────
begin
    set -l log (mktemp)
    function omp; echo "argc="(count $argv) >> $log; for arg in $argv; echo "arg=$arg" >> $log; end; end

    _ompxe_function hello world

    @test "with args passes a single prompt argument" (grep -Fx -c 'argc=1' $log) -ge 1
    @test "with args preserves spaces in the prompt" (grep -Fx -c 'arg=hello world' $log) -ge 1
    rm -f $log
end

16 changes: 16 additions & 0 deletions spec/fish/_ompxeh_function_test.fish
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +7 to +16

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve test isolation, it's a good practice to scope mock functions and temporary files. By wrapping the test logic that uses the omp mock in a begin...end block, you can ensure the mock and its log file are local to that test case and cleaned up properly, preventing potential side effects.

begin
    set -l log (mktemp)
    function omp; echo "argc="(count $argv) >> $log; for arg in $argv; echo "arg=$arg" >> $log; end; end

    echo "hello world" | _ompxeh_function

    @test "non-empty prompt passes two arguments" (grep -Fx -c 'argc=2' $log) -ge 1
    @test "non-empty prompt uses print mode" (grep -Fx -c 'arg=-p' $log) -ge 1
    @test "non-empty prompt preserves spaces in the prompt" (grep -Fx -c 'arg=hello world' $log) -ge 1
    rm -f $log
end

Loading