Skip to content

Add Fish custom prompts#4

Draft
hdp617 wants to merge 1 commit into
mainfrom
cursor/fish-custom-prompts-bb31
Draft

Add Fish custom prompts#4
hdp617 wants to merge 1 commit into
mainfrom
cursor/fish-custom-prompts-bb31

Conversation

@hdp617

@hdp617 hdp617 commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

Fish used default prompts while zsh/tmux show USER at <~/.name>. This adds custom Fish prompts aligned with that layout and wires in the existing fish_git_prompt configuration from 55-git-prompt.fish.

Changes

  • fish_prompt.fish — truncated cwd (prompt_pwd), ! on failure, > arrow (red for root).
  • fish_right_prompt.fishuser at machine + fish_git_prompt.
  • _machine_name.fish — reads ~/.name, falls back to hostname -s.
  • README: fix PATH filename and document the new prompt functions.

Test plan

  • chezmoi apply and open a new Fish session
  • Confirm left prompt shows cwd and >
  • Confirm right prompt shows user at <name> and git branch/state in a repo
Open in Web Open in Cursor 

fish_prompt: truncated cwd, failure marker, vi-style arrow.
fish_right_prompt: USER at ~/.name plus fish_git_prompt (styled in 55-git-prompt.fish).
_machine_name reads ~/.name with hostname fallback.

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 updates the README layout notes and introduces custom Fish shell prompt configurations, including a left prompt, a right prompt, and a helper function to resolve the machine name. The review feedback focuses on optimizing shell performance by avoiding spawning external processes (such as cat, hostname, id, and whoami) on every prompt render. It suggests using built-in Fish features like read, prompt_hostname, fish_is_root_user, and the $USER environment variable, as well as caching the resolved machine name.

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 +6
if test -f $HOME/.name
cat $HOME/.name
else
hostname -s
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.

medium

Spawning external processes like cat and hostname on every prompt render introduces unnecessary latency and slows down terminal responsiveness. We can optimize this by using the built-in read command to read the file without forking, using the built-in prompt_hostname function, and caching the resolved machine name in a global variable so it is only computed once per session.

    if not set -q __machine_name_cache
        if test -f $HOME/.name
            read -l name < $HOME/.name
            set -g __machine_name_cache (string trim $name)
        else
            set -g __machine_name_cache (prompt_hostname)
        end
    end
    echo -n $__machine_name_cache

Comment on lines +10 to +14
if test (id -u) -eq 0
echo -n (set_color red)'>'(set_color normal)' '
else
echo -n (set_color magenta)'>'(set_color normal)' '
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.

medium

Using (id -u) spawns an external process on every single prompt render, which can degrade shell performance. Fish provides a built-in function fish_is_root_user that checks user privileges extremely quickly without spawning any external processes.

    if fish_is_root_user
        echo -n (set_color red)'>'(set_color normal)' '
    else
        echo -n (set_color magenta)'>'(set_color normal)' '
    end

Comment on lines +2 to +6
if test (id -u) -eq 0
echo -n (set_color red)(whoami)(set_color normal)
else
echo -n (set_color magenta)(whoami)(set_color normal)
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.

medium

Spawning external processes like (id -u) and (whoami) on every right prompt render degrades terminal responsiveness. We can optimize this by using the built-in fish_is_root_user function and the standard $USER environment variable, avoiding external process forks entirely.

    if fish_is_root_user
        echo -n (set_color red)"$USER"(set_color normal)
    else
        echo -n (set_color magenta)"$USER"(set_color normal)
    end

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