-
Notifications
You must be signed in to change notification settings - Fork 0
feat(fish): list fish abbreviations and aliases with descriptions #219
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8fae1e2
feat(fish): add fish_shortcuts to list abbreviations and aliases
shunkakinoki 8675112
Apply suggestion from @Copilot
shunkakinoki 5c87de3
Merge branch 'main' into feat/fish-shortcuts-20250924-205912
shunkakinoki 3a11ffb
fix(fish): correct function name from __hm_load_env_file to _hm_load_…
shunkakinoki c16492f
feat(fish): add --description to all missing function files
shunkakinoki 085463c
refactor(fish): streamline abbreviation and alias parsing in _fish_sh…
shunkakinoki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| function _clxe_function | ||
| function _clxe_function --description "Run Codex with a free-form prompt using the local gpt-oss:120b model" | ||
| # Run Codex with a free-form prompt (spaces allowed) using the local gpt-oss:120b model | ||
| # Usage: clxe <prompt words...> | ||
| # Usage: clxe [<prompt words...>] | ||
|
|
||
| if test (count $argv) -eq 0 | ||
| echo "Usage: clxe <prompt...>" >&2 | ||
| return 2 | ||
| codex --profile 'gpt-oss-120b' --full-auto -c model_reasoning_summary_format=experimental | ||
| else | ||
| set -l prompt (string join " " -- $argv) | ||
| codex --profile 'gpt-oss-120b' --full-auto -c model_reasoning_summary_format=experimental -- "$prompt" | ||
| end | ||
|
|
||
| set -l prompt (string join " " -- $argv) | ||
| codex --profile 'gpt-oss-120b' --full-auto -c model_reasoning_summary_format=experimental -- "$prompt" | ||
| end |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| function _cxe_function | ||
| function _cxe_function --description "Run Codex with a free-form prompt" | ||
| # Run Codex with a free-form prompt (spaces allowed) | ||
| # Usage: cxe <prompt words...> | ||
| # Usage: cxe [<prompt words...>] | ||
|
|
||
| if test (count $argv) -eq 0 | ||
| echo "Usage: cxe <prompt...>" >&2 | ||
| return 2 | ||
| codex --model 'gpt-5-codex' --full-auto -c model_reasoning_summary_format=experimental | ||
| else | ||
| set -l prompt (string join " " -- $argv) | ||
| codex --model 'gpt-5-codex' --full-auto -c model_reasoning_summary_format=experimental -- "$prompt" | ||
| end | ||
|
|
||
| set -l prompt (string join " " -- $argv) | ||
| codex --model 'gpt-5-codex' --full-auto -c model_reasoning_summary_format=experimental -- "$prompt" | ||
| end |
247 changes: 247 additions & 0 deletions
247
home-manager/programs/fish/functions/_fish_shortcuts.fish
This file contains hidden or 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,247 @@ | ||
| function _fish_shortcuts --description "List fish abbreviations and aliases with inferred descriptions" | ||
| # Prints all abbreviations and aliases currently active in this shell. | ||
| # For items that expand to a function, attempts to extract a description from: | ||
| # 1) the function's --description flag, or | ||
| # 2) the first leading comment lines inside the function body. | ||
|
|
||
| function __fish__get_func_desc --argument-names fname | ||
| if not functions -q $fname | ||
| return 1 | ||
| end | ||
|
|
||
| # Get the full function definition as a single string | ||
| set -l def (functions $fname | string collect) | ||
|
|
||
| # Try to extract --description from the function header | ||
| set -l d (string match -r --groups-only -- '--description(?:=| )\"([^\"]*)\"' "$def") | ||
| if test -n "$d" | ||
| echo $d | ||
| return 0 | ||
| end | ||
|
|
||
| set d (string match -r --groups-only -- "--description(?:=| )'([^']*)'" "$def") | ||
| if test -n "$d" | ||
| echo $d | ||
| return 0 | ||
| end | ||
|
|
||
| return 1 | ||
| end | ||
|
|
||
| function __fish__format_row --argument-names kind name expansion desc | ||
| # kind: "abbr" | "alias" | ||
| if test -n "$desc" | ||
| printf "%s\t%-20s -> %-40s # %s\n" $kind $name $expansion $desc | ||
| else | ||
| printf "%s\t%-20s -> %s\n" $kind $name $expansion | ||
| end | ||
| end | ||
|
|
||
| set -l any_output 0 | ||
|
|
||
| # Abbreviations | ||
| if type -q abbr | ||
| set -l abbr_list (abbr --list 2>/dev/null) | ||
|
|
||
| set -l abbr_lines (abbr --show 2>/dev/null | string split "\n") | ||
| set -l abbr_names | ||
| set -l abbr_expansions | ||
|
|
||
| for line in $abbr_lines | ||
| set line (string trim -- $line) | ||
| if test -z "$line" | ||
| continue | ||
| end | ||
|
|
||
| set -l parsed_name "" | ||
| set -l parsed_expansion "" | ||
|
|
||
| if type -q python3 | ||
| set -lx __FISH_SHORTCUT_LINE "$line" | ||
| set -l parsed (python3 -c " | ||
| import os, shlex | ||
|
|
||
| line = os.environ['__FISH_SHORTCUT_LINE'] | ||
| tokens = shlex.split(line) | ||
| name = '' | ||
| expansion = '' | ||
|
|
||
| try: | ||
| idx = tokens.index('--') | ||
| except ValueError: | ||
| pass | ||
| else: | ||
| if idx + 1 < len(tokens): | ||
| name = tokens[idx + 1] | ||
| rest = tokens[idx + 2:] | ||
| if '--function' in tokens: | ||
| try: | ||
| pos = tokens.index('--function') | ||
| except ValueError: | ||
| pos = -1 | ||
| if pos != -1 and pos + 1 < len(tokens): | ||
| expansion = tokens[pos + 1] | ||
| if not expansion and rest: | ||
| expansion = ' '.join(rest) | ||
|
|
||
| print(name) | ||
| print(expansion) | ||
| ") | ||
| set -e __FISH_SHORTCUT_LINE | ||
| if test (count $parsed) -ge 1 | ||
| set parsed_name $parsed[1] | ||
| end | ||
| if test (count $parsed) -ge 2 | ||
| set parsed_expansion $parsed[2] | ||
| end | ||
| end | ||
|
|
||
| if test -z "$parsed_name" | ||
| set parsed_name (string match -r --groups-only '^abbr\b.* -- (\S+)' -- "$line") | ||
| end | ||
|
|
||
| if test -z "$parsed_name" | ||
| continue | ||
| end | ||
|
|
||
| if test -z "$parsed_expansion" | ||
| set parsed_expansion (string match -r --groups-only "'([^']*)'" -- "$line") | ||
| end | ||
| if test -z "$parsed_expansion" | ||
| set parsed_expansion (string match -r --groups-only "\"([^\"]*)\"" -- "$line") | ||
| end | ||
| if test -z "$parsed_expansion" | ||
| set -l fallback (string replace -r -- '^abbr\b.* -- \S+\s*' '' -- "$line") | ||
| set fallback (string trim -- $fallback) | ||
| if test -n "$fallback" | ||
| set parsed_expansion $fallback | ||
| end | ||
| end | ||
|
|
||
| set -a abbr_names $parsed_name | ||
| set -a abbr_expansions $parsed_expansion | ||
| end | ||
|
|
||
| for a in $abbr_list | ||
| set -l expansion "" | ||
| for idx in (seq (count $abbr_names)) | ||
| if test "$abbr_names[$idx]" = "$a" | ||
| set expansion $abbr_expansions[$idx] | ||
| break | ||
| end | ||
| end | ||
|
|
||
| if test -n "$expansion" | ||
| set expansion (string trim --chars="'\"" -- $expansion) | ||
| end | ||
|
|
||
| set -l desc "" | ||
| # If the expansion is a single token and is a function, derive description | ||
| if test -n "$expansion" | ||
| set -l first_token (string split ' ' -- $expansion)[1] | ||
| if test (count (string split ' ' -- $expansion)) -eq 1; and functions -q $first_token | ||
| set desc (__fish__get_func_desc $first_token) | ||
| end | ||
| end | ||
|
|
||
| __fish__format_row abbr $a "$expansion" "$desc" | ||
| set any_output 1 | ||
| end | ||
| end | ||
|
|
||
| # Aliases | ||
| if type -q alias | ||
| for line in (alias 2>/dev/null) | ||
| # line format typically: alias NAME 'EXPANSION...' | ||
| set -l name "" | ||
| set -l expansion "" | ||
|
|
||
| set -l alias_parts (string split -m 2 ' ' -- $line) | ||
| if test (count $alias_parts) -ge 2 | ||
| set name $alias_parts[2] | ||
| end | ||
| if test (count $alias_parts) -ge 3 | ||
| set expansion (string trim --chars="'" -- $alias_parts[3]) | ||
| end | ||
|
|
||
| if test -z "$name" | ||
| # Skip lines we fail to parse (unexpected alias output format) | ||
| continue | ||
| end | ||
|
|
||
| set -l desc "" | ||
| if test -n "$expansion" | ||
| set -l first_token (string split ' ' -- $expansion)[1] | ||
| if test (count (string split ' ' -- $expansion)) -eq 1; and functions -q $first_token | ||
| set desc (__fish__get_func_desc $first_token) | ||
| end | ||
| end | ||
|
|
||
| __fish__format_row alias $name "$expansion" "$desc" | ||
| set any_output 1 | ||
| end | ||
| end | ||
|
|
||
| # Functions stored alongside this helper | ||
| set -l script_path (status current-filename) | ||
| set -l script_realpath "" | ||
| if test -n "$script_path" | ||
| if type -q realpath | ||
| set script_realpath (realpath "$script_path" 2>/dev/null) | ||
| end | ||
| if test -z "$script_realpath" | ||
| set script_realpath $script_path | ||
| end | ||
| end | ||
|
|
||
| set -l functions_dir "" | ||
| set -l functions_parent "" | ||
| if test -n "$script_realpath" | ||
| set functions_dir (path dirname $script_realpath) | ||
| set functions_parent (path dirname $functions_dir) | ||
| end | ||
|
|
||
| if test -n "$functions_dir"; and test -d "$functions_dir" | ||
| set -l function_files $functions_dir/*.fish | ||
| if test "$function_files" = "$functions_dir/*.fish" | ||
| set function_files | ||
| end | ||
|
|
||
| for file in $function_files | ||
| if test -z "$file"; or test ! -f "$file" | ||
| continue | ||
| end | ||
|
|
||
| set -l base (path basename $file) | ||
| set -l fname (path change-extension '' -- $base) | ||
|
|
||
| # Avoid re-sourcing ourselves repeatedly | ||
| if test "$fname" = (status function) | ||
| continue | ||
| end | ||
|
|
||
| if not functions -q $fname | ||
| builtin source $file 2>/dev/null | ||
| end | ||
|
|
||
| set -l desc (__fish__get_func_desc $fname) | ||
| set -l rel_path "$base" | ||
| if test -n "$functions_parent" | ||
| set rel_path (string join '' "functions/" $base) | ||
| end | ||
|
|
||
| __fish__format_row func $fname "$rel_path" "$desc" | ||
| set any_output 1 | ||
| end | ||
| end | ||
|
|
||
| if test $any_output -eq 0 | ||
| echo "No abbreviations or aliases found." | ||
| end | ||
| end | ||
|
|
||
| if not functions -q fish_shortcuts | ||
| function fish_shortcuts --wraps _fish_shortcuts --description "Alias for _fish_shortcuts" | ||
| _fish_shortcuts $argv | ||
| end | ||
| end | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| function _gco_function | ||
| function _gco_function --description "Checkout default branch and pull latest changes" | ||
| git checkout (git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') && git pull | ||
| end |
This file contains hidden or 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
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...ms/fish/functions/__hm_load_env_file.fish → ...ams/fish/functions/_hm_load_env_file.fish
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.