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/shell/fish/prompt.fish

61 lines
1.4 KiB
Fish
Raw Normal View History

2020-01-16 17:01:59 -06:00
#!/usr/bin/env fish
# TODO: if root, background instead?
set MAX_PATH_PIECE_CHARS $BASH_PROMPT_MAX_PATH_PIECE_CHARS 3
# prompt rendering functions
function preprocess_pwd
test (pwd) = / && echo "/" && return 1
test (pwd) = $NICE_HOME && echo "~" && return 0
# with ellipsis
# echo "$(<<< "$p" cut -c2- | awk '{split($0,p,"/");for(k in p){if(k==length(p)){printf "/%s",p[k]}else{if(length(p[k])>'"
# $((MAX_PATH_PIECE_CHARS+1))"'){printf "/%.'"$((MAX_PATH_PIECE_CHARS))"'s…",p[k]}else{printf "/%s",p[k]}}}}')"
2020-01-16 17:01:59 -06:00
# without ellipsis
echo (pwd) | cut -c2- | \
awk '{split($0,p,"/");for(k in p){if(k==length(p)){printf "/%s",p[k]}else{printf "/%.'$MAX_PATH_PIECE_CHARS[1]'s",p[k]}}}'
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