replace starship with custom fish prompt

This commit is contained in:
2026-03-05 15:05:58 +00:00
parent 17563547d8
commit 77cae177b9
11 changed files with 373 additions and 174 deletions
+2 -1
View File
@@ -65,7 +65,6 @@ status is-interactive; and begin
nerdfetch
if test "$TERM" != dumb
eval (starship init fish)
fzf --fish | source
end
@@ -170,5 +169,7 @@ if test (uname) = Darwin
# opencode
fish_add_path /Users/thomasglopes/.opencode/bin
end
+57
View File
@@ -0,0 +1,57 @@
# Prompt configuration
function _prompt_config
# Colors
if not set -q prompt_color_surface; and not set -Uq prompt_color_surface
set -U prompt_color_surface 1b2122
end
if not set -q prompt_color_primary; and not set -Uq prompt_color_primary
set -U prompt_color_primary 81d3df
end
if not set -q prompt_color_secondary; and not set -Uq prompt_color_secondary
set -U prompt_color_secondary b1cbcf
end
if not set -q prompt_color_tertiary; and not set -Uq prompt_color_tertiary
set -U prompt_color_tertiary b9c6ea
end
if not set -q prompt_color_error; and not set -Uq prompt_color_error
set -U prompt_color_error ffb4ab
end
if not set -q prompt_color_primary_fixed; and not set -Uq prompt_color_primary_fixed
set -U prompt_color_primary_fixed 9df0fb
end
if not set -q prompt_color_tertiary_fixed; and not set -Uq prompt_color_tertiary_fixed
set -U prompt_color_tertiary_fixed d9e2ff
end
# Behavior
if not set -q prompt_show_username; and not set -Uq prompt_show_username
set -U prompt_show_username true
end
if not set -q prompt_show_time; and not set -Uq prompt_show_time
set -U prompt_show_time true
end
if not set -q prompt_time_format; and not set -Uq prompt_time_format
set -U prompt_time_format "%I:%M%P"
end
if not set -q prompt_dir_truncation; and not set -Uq prompt_dir_truncation
set -U prompt_dir_truncation 3
end
# Symbols
if not set -q prompt_symbol; and not set -Uq prompt_symbol
set -U prompt_symbol "󱞪"
end
if not set -q prompt_user_symbol; and not set -Uq prompt_user_symbol
set -U prompt_user_symbol "󰧱"
end
# Directory substitutions
if not set -q prompt_dir_substitutions; and not set -Uq prompt_dir_substitutions
set -U prompt_dir_substitutions \
"Documents:󰈙" \
"Downloads: " \
"Music: " \
"Pictures: "
end
end
@@ -0,0 +1,22 @@
# Format current directory with substitutions and truncation
function _prompt_directory
set -l dir (pwd | string replace $HOME "~")
for sub in $prompt_dir_substitutions
set -l parts (string split ":" $sub)
set -l name $parts[1]
set -l icon $parts[2]
set dir (string replace -a "/$name" "/$icon" $dir)
set dir (string replace "^$name" "$icon" $dir)
end
if test $prompt_dir_truncation -gt 0
set -l parts (string split "/" $dir)
if test (count $parts) -gt $prompt_dir_truncation
set parts "…" $parts[(math 2 - $prompt_dir_truncation)..-1]
end
set dir (string join "/" $parts)
end
echo $dir
end
+15
View File
@@ -0,0 +1,15 @@
# Build a prompt segment with rounded corners
function _prompt_segment
set content $argv[1]
set bg $argv[2]
set fg $argv[3]
test -z "$content"; and return
set bg (string replace -a "#" "" $bg)
set bg (string replace -a '"' '' $bg)
set fg (string replace -a "#" "" $fg)
set fg (string replace -a '"' '' $fg)
echo (set_color $bg)(set_color -b $bg $fg)" $content "(set_color normal)(set_color $bg)(set_color normal)
end
@@ -0,0 +1,3 @@
# Disable fish's built-in vi mode indicator (we render our own mode pill in fish_prompt)
function fish_mode_prompt
end
+173
View File
@@ -0,0 +1,173 @@
# Custom Fish prompt - simple version
# Configure via: prompt-config
function _prompt_git_branch
git branch --show-current 2>/dev/null
end
function _prompt_git_icon
set -l remotes (git remote -v 2>/dev/null | awk '{print $2}')
test -z "$remotes"; and return
for remote in $remotes
if not string match -q "*github.com*" $remote
printf '\ue702'
return
end
end
printf '\uf113'
end
function _prompt_git_status
git rev-parse --git-dir >/dev/null 2>&1; or return
set -l staged (git diff --cached --numstat 2>/dev/null | wc -l)
set -l modified (git diff --numstat 2>/dev/null | wc -l)
set -l untracked (git ls-files --others --exclude-standard 2>/dev/null | wc -l)
set -l stashed (git stash list 2>/dev/null | wc -l)
set -l ahead_behind (git rev-list --left-right --count @{upstream}...HEAD 2>/dev/null)
set -l ahead (echo $ahead_behind | awk '{print $2}')
set -l behind (echo $ahead_behind | awk '{print $1}')
set -l status_parts
if test "$staged" -gt 0
set status_parts $status_parts "++($staged)"
end
if test "$modified" -gt 0
set status_parts $status_parts "!($modified)"
end
if test "$untracked" -gt 0
set status_parts $status_parts "?($untracked)"
end
if test "$stashed" -gt 0
set status_parts $status_parts "\$"
end
if test -n "$ahead" -a "$ahead" -gt 0
if test -n "$behind" -a "$behind" -gt 0
set status_parts $status_parts "⇕[⇡($ahead)⇣($behind)]"
else
set status_parts $status_parts "⇡($ahead)"
end
else if test -n "$behind" -a "$behind" -gt 0
set status_parts $status_parts "⇣($behind)"
end
if test -z "$status_parts"
echo "✓"
else
string join "" $status_parts
end
end
function _prompt_mode_text
switch $fish_bind_mode
case default
echo "N"
case insert
echo "I"
case visual
echo "V"
case replace-one
echo "R"
case '*'
echo "$fish_bind_mode"
end
end
function _prompt_mode_color
switch $fish_bind_mode
case default
echo $prompt_color_error
case insert
echo $prompt_color_tertiary_fixed
case visual
echo $prompt_color_primary_fixed
case replace-one
echo $prompt_color_error
case '*'
echo $prompt_color_tertiary_fixed
end
end
function fish_prompt
# keep vertical spacing consistent (including empty Enter)
echo
_prompt_config
set -l bg $prompt_color_surface
set -l left_parts
# vi mode indicator pill on left
set -l mode_text (_prompt_mode_text)
set -l mode_color (_prompt_mode_color)
set left_parts $left_parts (_prompt_segment "$mode_text" $bg $mode_color)
# Username
if test "$prompt_show_username" = true
set left_parts $left_parts (_prompt_segment "$prompt_user_symbol $USER" $bg $prompt_color_tertiary_fixed)
end
# Directory
set -l dir (_prompt_directory)
set left_parts $left_parts (_prompt_segment "$dir" $bg $prompt_color_primary)
# Git branch with dynamic icon
set -l branch (_prompt_git_branch)
if test -n "$branch"
set -l git_icon (_prompt_git_icon)
set left_parts $left_parts (_prompt_segment "$git_icon $branch" $bg $prompt_color_primary_fixed)
end
# Git status
set -l git_status (_prompt_git_status)
if test -n "$git_status"
set -l fg_color $prompt_color_error
if test "$git_status" = "✓"
set fg_color $prompt_color_tertiary_fixed
end
set left_parts $left_parts (_prompt_segment "$git_status" $bg $fg_color)
end
set -l left_line (string join " " $left_parts)
# Right-aligned time pill
set -l right_line ""
if test "$prompt_show_time" = true
set -l time_str (date "+$prompt_time_format")
set right_line (_prompt_segment "󰴈 $time_str" $bg $prompt_color_secondary)
end
if test -n "$right_line"
set -l cols $COLUMNS
test -z "$cols"; and set cols (tput cols 2>/dev/null)
test -z "$cols"; and set cols 80
set -l left_width (string length -V -- $left_line)
set -l right_width (string length -V -- $right_line)
set -l gap (math $cols - $left_width - $right_width)
if test $gap -lt 1
set gap 1
end
set -l spaces (string repeat -n $gap " ")
echo "$left_line$spaces$right_line"
else
echo $left_line
end
# Second line: input prompt
set -l tertiary_clean (string replace -a "#" "" $prompt_color_tertiary)
set tertiary_clean (string replace -a '"' '' $tertiary_clean)
set_color $tertiary_clean
echo -n "$prompt_symbol "
set_color normal
end
@@ -0,0 +1,3 @@
# Right prompt disabled (time is shown inline in fish_prompt)
function fish_right_prompt
end
+80
View File
@@ -0,0 +1,80 @@
# Customize prompt settings
# Usage: prompt-config [setting] [value]
# Examples:
# prompt-config # Show current settings
# prompt-config show_username false
# prompt-config color_primary ff6b6b
# prompt-config reset
function prompt-config
if test (count $argv) -eq 0
echo "Current prompt settings:"
echo ""
echo "Colors:"
echo " surface: $prompt_color_surface"
echo " primary: $prompt_color_primary"
echo " secondary: $prompt_color_secondary"
echo " tertiary: $prompt_color_tertiary"
echo " error: $prompt_color_error"
echo " primary_fixed: $prompt_color_primary_fixed"
echo " tertiary_fixed: $prompt_color_tertiary_fixed"
echo ""
echo "Behavior:"
echo " show_username: $prompt_show_username"
echo " show_time: $prompt_show_time"
echo " time_format: $prompt_time_format"
echo " dir_truncation: $prompt_dir_truncation"
echo ""
echo "Symbols:"
echo " prompt_symbol: $prompt_symbol"
echo " user_symbol: $prompt_user_symbol"
echo ""
echo "Usage: prompt-config <setting> <value>"
echo " prompt-config reset"
return
end
if test "$argv[1]" = "reset"
set -e prompt_color_surface
set -e prompt_color_primary
set -e prompt_color_secondary
set -e prompt_color_tertiary
set -e prompt_color_error
set -e prompt_color_primary_fixed
set -e prompt_color_tertiary_fixed
set -e prompt_show_username
set -e prompt_show_time
set -e prompt_time_format
set -e prompt_dir_truncation
set -e prompt_symbol
set -e prompt_user_symbol
echo "Prompt settings reset."
return
end
if test (count $argv) -lt 2
echo "Usage: prompt-config <setting> <value>"
return 1
end
set -l setting $argv[1]
set -l value $argv[2..-1]
set -l varname prompt_$setting
set -U $varname $value
echo "Set $setting = $value"
end
complete -c prompt-config -f
complete -c prompt-config -n __fish_use_subcommand -a "reset" -d "Reset to defaults"
complete -c prompt-config -n __fish_use_subcommand -a "show_username" -d "Show username (true/false)"
complete -c prompt-config -n __fish_use_subcommand -a "show_time" -d "Show time (true/false)"
complete -c prompt-config -n __fish_use_subcommand -a "time_format" -d "Time format (e.g. %H:%M)"
complete -c prompt-config -n __fish_use_subcommand -a "dir_truncation" -d "Directory truncation depth"
complete -c prompt-config -n __fish_use_subcommand -a "symbol" -d "Prompt symbol"
complete -c prompt-config -n __fish_use_subcommand -a "user_symbol" -d "Username icon"
complete -c prompt-config -n __fish_use_subcommand -a "color_surface" -d "Surface color"
complete -c prompt-config -n __fish_use_subcommand -a "color_primary" -d "Primary color"
complete -c prompt-config -n __fish_use_subcommand -a "color_secondary" -d "Secondary color"
complete -c prompt-config -n __fish_use_subcommand -a "color_tertiary" -d "Tertiary color"
complete -c prompt-config -n __fish_use_subcommand -a "color_error" -d "Error color"