config/fish/functions/fish_prompt.fish

94 lines
1.6 KiB
Fish
Raw Normal View History

#!/bin/fish
set PROMPTDIRS "~":$HOME
#
# This function takes the $PROMPTDIRS variable and tries to shorten the
# input (i.e. $argv[1]) w.r.t. the variable.
#
# e.g. If $PROMPTDIRS contains the pair $PR:$HOME/Projects,
#
# (prompt_abbr ~/Projects/Applications)
#
# will show "$PR/Applications", and ~/Projects will be converted to $PR.
#
# To set multiple $PROMPTDIRS entry, use successive (where $ABBR is some
# directory to be abbreviated)
#
# set PROMPTDIRS \$ABBR:$ABBR $PROMPTDIRS
#
# with the outermost directory being set first.
#
function prompt_abbr
set in $argv[1]
for d in $PROMPTDIRS
set -l kv (string split -m 1 ":" $d)
switch "$in"
case "$kv[2]/*"
set in (string replace $kv[2] $kv[1] $in)
break
case "$kv[2]"
set in "$kv[1]"
break
case "*"
end
end
echo "$in"
end
function fish_prompt
# set_color white
2024-10-03 17:26:46 -07:00
# printf '['
set -l FishStatusCodeCache $status
set_color -o 00FF00 -b 333333
2024-10-03 17:26:46 -07:00
printf (whoami)
set_color normal
set_color -b 333333
2024-10-03 17:26:46 -07:00
printf '@'
set_color AFD75F
2024-10-03 17:26:46 -07:00
printf (prompt_hostname)
set_color white
2024-10-03 17:26:46 -07:00
printf ':'
set_color 8787FF
2024-10-03 17:26:46 -07:00
printf (prompt_abbr $PWD)
2024-10-03 17:26:46 -07:00
set -l vcs_prompt (fish_vcs_prompt)
if test -n "$vcs_prompt"
printf " "
set_color 5F87D7
printf '\uf126'
printf (fish_vcs_prompt)
end
if test $FishStatusCodeCache -eq 0
#set_color 18C412
else
set_color E84505
2024-10-03 17:26:46 -07:00
printf " [$FishStatusCodeCache]"
end
# set_color white
2024-10-03 17:26:46 -07:00
# printf "]"
set_color 999999
printf " "
printf (date '+%Y/%m/%d %H:%M:%S')
printf "\n"
#set_color -o white
#printf "> "
set_color normal
2024-10-03 17:26:46 -07:00
set_color -o green
printf "⮀ "
set_color normal
end