Skip to content

Port zsh shell helpers to Fish#6

Draft
hdp617 wants to merge 1 commit into
mainfrom
cursor/port-fish-helpers-bb31
Draft

Port zsh shell helpers to Fish#6
hdp617 wants to merge 1 commit into
mainfrom
cursor/port-fish-helpers-bb31

Conversation

@hdp617

@hdp617 hdp617 commented Jul 9, 2026

Copy link
Copy Markdown
Owner

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

  • Add Fish functions: cdgr, fpr, serve, jump, xin, nonascii, syspip / syspip3.
  • Update README function list and note remaining zsh-only items (syspip2, screen cd hack).

Test plan

  • cdgr from a git subdirectory lands at repo root
  • fpr user branch fetches to user/branch ref
  • serve 9000 serves cwd on port 9000
  • syspip install … runs without PIP_REQUIRE_VIRTUALENV
Open in Web Open in Cursor 

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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines +2 to +4
cd $argv[1]; or return
set -e argv[1]
command $argv

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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

Comment on lines +5 to +7
function syspip3
env PIP_REQUIRE_VIRTUALENV= pip3 $argv
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using $argv[1] limits the function to only checking the first file passed. Using $argv instead allows the function to support checking multiple files, or reading from standard input if no files are provided.

    env LC_ALL=C grep -n '[^[:print:][:space:]]' $argv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants