Add Fish custom prompts#4
Conversation
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>
There was a problem hiding this comment.
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.
| if test -f $HOME/.name | ||
| cat $HOME/.name | ||
| else | ||
| hostname -s | ||
| end |
There was a problem hiding this comment.
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
| if test (id -u) -eq 0 | ||
| echo -n (set_color red)'>'(set_color normal)' ' | ||
| else | ||
| echo -n (set_color magenta)'>'(set_color normal)' ' | ||
| end |
There was a problem hiding this comment.
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
| 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 |
There was a problem hiding this comment.
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
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 existingfish_git_promptconfiguration from55-git-prompt.fish.Changes
fish_prompt.fish— truncated cwd (prompt_pwd),!on failure,>arrow (red for root).fish_right_prompt.fish—user at machine+fish_git_prompt._machine_name.fish— reads~/.name, falls back tohostname -s.Test plan
chezmoi applyand open a new Fish session>user at <name>and git branch/state in a repo