-
Notifications
You must be signed in to change notification settings - Fork 0
Add Fish custom prompts #4
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| function _machine_name | ||
| if test -f $HOME/.name | ||
| cat $HOME/.name | ||
| else | ||
| hostname -s | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| function fish_prompt | ||
| set -l cmd_status $status | ||
|
|
||
| echo -n (set_color green)(prompt_pwd)(set_color normal)' ' | ||
|
|
||
| if test $cmd_status -ne 0 | ||
| echo -n (set_color red)'!'(set_color normal)' ' | ||
| end | ||
|
|
||
| if test (id -u) -eq 0 | ||
| echo -n (set_color red)'>'(set_color normal)' ' | ||
| else | ||
| echo -n (set_color magenta)'>'(set_color normal)' ' | ||
| end | ||
|
Comment on lines
+10
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| function fish_right_prompt | ||
| 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 | ||
|
Comment on lines
+2
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spawning external processes like |
||
|
|
||
| echo -n (set_color blue)' at '(set_color normal) | ||
| echo -n (set_color cyan)(_machine_name)(set_color normal)' ' | ||
|
|
||
| fish_git_prompt | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spawning external processes like
catandhostnameon every prompt render introduces unnecessary latency and slows down terminal responsiveness. We can optimize this by using the built-inreadcommand to read the file without forking, using the built-inprompt_hostnamefunction, and caching the resolved machine name in a global variable so it is only computed once per session.