-
Notifications
You must be signed in to change notification settings - Fork 0
fix: add fish omp shortcuts #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0fd6070
1157fcc
084257d
9cd8da0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
| 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 |
| 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 | ||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To improve test isolation, it's a good practice to scope mock functions and temporary files. By wrapping the test logic that uses the |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To improve test isolation and avoid redefining the
ompmock function in the global scope, it's better to wrap each test case in abegin...endblock. This scopes the mock function and log file variables locally to each test, making the tests more robust and self-contained.