This repository has been archived on 2024-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/common/fish/prompt.fish

61 lines
1.2 KiB
Fish
Raw Permalink Normal View History

2021-11-03 12:01:43 -05:00
set MAX_PATH_PIECE_CHARS 3
2020-01-16 17:01:59 -06:00
2021-11-03 12:01:43 -05:00
function get_hostname
has_command hostname && hostname || cat /etc/hostname
end
2020-01-16 17:01:59 -06:00
2021-11-03 12:01:43 -05:00
function fish_greeting
set_color -b black brblack
printf "%s@%s %s\n" $USER (get_hostname) (date)
end
2020-01-16 17:01:59 -06:00
function preprocess_pwd
test (pwd) = / && echo "/" && return 1
test (pwd) = $NICE_HOME && echo "~" && return 0
2022-05-10 13:23:32 -05:00
pwd | cut -c2- | \
awk '{n=split($0,p,"/");for(i=1;i<=n;i++){if(i==n){printf "/%s",p[i]}else{printf "/%.'$MAX_PATH_PIECE_CHARS[1]'s",p[i]}}}'
2020-01-16 17:01:59 -06:00
end
function fish_prompt
2020-04-21 16:38:58 -05:00
set last_cmd_status $status
if test (id -u) -eq 0
if test $last_cmd_status -eq 0
set_color -b blue black
else
set_color -b red black
end
2020-05-18 15:34:35 -05:00
printf " SUDO $USER@$hostname "
2020-01-16 17:01:59 -06:00
else
2020-04-21 16:38:58 -05:00
if test $last_cmd_status -eq 0
set_color blue
else
set_color red
end
printf %s@%s $USER (echo $hostname | cut -d '.' -f1)
2020-01-16 17:01:59 -06:00
end
2020-04-21 16:38:58 -05:00
set_color normal
printf " "
2020-01-16 17:01:59 -06:00
set_color magenta
2020-04-21 16:38:58 -05:00
printf (preprocess_pwd)""
set_color normal
printf " "
2020-01-16 17:01:59 -06:00
end
2020-01-17 03:02:53 -06:00
function fish_mode_prompt; end
2020-01-24 12:45:49 -06:00
# function fish_right_prompt
# set_color brblack
# switch $fish_bind_mode
# case default
# echo 'N'
# case insert
# echo 'I'
# case replace_one
# echo 'R'
# case replace
# echo 'R'
# case visual
# echo 'V'
# end
# end