Port zsh shell helpers to Fish#6
Conversation
Add cdgr, fpr, serve, jump, xin, nonascii, and syspip/syspip3 as Fish autoload functions mirroring ~/.shell/aliases.sh behavior. Co-authored-by: Huy Pham <hdp617@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request adds several new Fish shell utility functions (cdgr, fpr, jump, nonascii, serve, syspip, syspip3, and xin) and updates the documentation in README.md. The review feedback highlights several improvements for robustness and compatibility: xin should use pushd/popd to keep directory changes temporary; syspip3 needs to be moved to its own file to work with Fish's autoloading; cdgr should use standard git rev-parse and handle errors to avoid unexpectedly navigating to $HOME; jump requires argument validation for the same reason; and nonascii should accept $argv instead of $argv[1] to support multiple files.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| cd $argv[1]; or return | ||
| set -e argv[1] | ||
| command $argv |
There was a problem hiding this comment.
In Fish, functions run in the current shell context. Calling cd inside this function will permanently change the user's working directory, defeating the purpose of xin (which is to execute a command in a directory temporarily).
We should use pushd and popd (redirecting output to /dev/null to keep it quiet) to ensure the directory change is temporary and restored afterward. We should also validate that the required arguments are provided.
if test (count $argv) -lt 2
echo "Usage: xin <directory> <command> [args...]" >&2
return 1
end
pushd $argv[1] >/dev/null; or return
set -e argv[1]
$argv
popd >/dev/null
| function syspip3 | ||
| env PIP_REQUIRE_VIRTUALENV= pip3 $argv | ||
| end |
There was a problem hiding this comment.
In Fish, autoloaded functions are loaded by filename. Because syspip3 is defined inside syspip.fish instead of its own file, calling syspip3 in a fresh shell session will fail with Unknown command unless syspip has already been executed in that session.
To fix this, syspip3 should be removed from this file and placed in its own file named dot_config/fish/functions/syspip3.fish.
| @@ -0,0 +1,3 @@ | |||
| function cdgr | |||
| cd (git root) | |||
There was a problem hiding this comment.
Using git root is not a standard Git command and relies on a custom alias that may not be configured on all systems. Additionally, if the command fails or is run outside of a Git repository, it outputs nothing to stdout, causing cd to be executed with no arguments, which unexpectedly changes the directory to $HOME.
Using git rev-parse --show-toplevel is the standard, portable way to find the repository root, and we should verify that a path was returned before attempting to change directories.
set -l root (git rev-parse --show-toplevel 2>/dev/null)
if test -n "$root"
cd $root
else
echo "error: not in a git repository" >&2
return 1
end
| @@ -0,0 +1,3 @@ | |||
| function jump | |||
| cd (dirname $argv[1]) | |||
There was a problem hiding this comment.
If jump is called with no arguments, $argv[1] is empty, causing dirname to fail and output nothing. This results in cd being executed with no arguments, which unexpectedly changes the directory to $HOME.
We should validate that an argument is provided and that the target directory exists before attempting to change directories.
if test (count $argv) -lt 1
echo "Usage: jump <file_or_directory>" >&2
return 1
end
set -l dir (dirname $argv[1])
if test -d "$dir"
cd "$dir"
else
echo "error: no such directory: $dir" >&2
return 1
end
| @@ -0,0 +1,3 @@ | |||
| function nonascii | |||
| env LC_ALL=C grep -n '[^[:print:][:space:]]' $argv[1] | |||
Summary
Several utilities lived only in
~/.shell/aliases.sh(sourced by zsh). This ports them to Fish autoload functions so the primary shell has parity.Changes
cdgr,fpr,serve,jump,xin,nonascii,syspip/syspip3.syspip2, screencdhack).Test plan
cdgrfrom a git subdirectory lands at repo rootfpr user branchfetches touser/branchrefserve 9000serves cwd on port 9000syspip install …runs withoutPIP_REQUIRE_VIRTUALENV