oh-my-fish/themes/fisk/fish_prompt.fish

57 lines
1.4 KiB
Fish
Raw Normal View History

2015-02-16 17:50:40 +08:00
function fish_prompt --description 'Write out the prompt'
set last_ret $status
2015-04-04 05:37:40 +08:00
# Palette
set -l base01 55f
set -l base02 55a
set -l base03 777
set -l c_error f77
set -l c_success 7f7
set -l c_yellow ff5
set -l c_magenta f0d
2015-02-16 17:50:40 +08:00
# Just calculate these once, to save a few cycles when displaying the prompt
if not set -q __fish_prompt_hostname
set -g __fish_prompt_hostname (hostname|cut -d . -f 1)
end
if not set -q __fish_prompt_cwd
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
end
2015-04-03 22:53:22 +08:00
if set -q VIRTUAL_ENV
2015-04-04 05:43:56 +08:00
set venv (_fisk_concat " " (set_color $c_magenta) "(" (basename "$VIRTUAL_ENV") ")" (set_color normal))
2015-02-16 17:50:40 +08:00
else
set venv ""
end
2015-04-04 05:37:40 +08:00
set ret_color $c_success
2015-02-16 17:50:40 +08:00
2015-04-04 05:37:40 +08:00
if test $last_ret -gt 0
set ret_color $c_error
2015-02-16 17:50:40 +08:00
end
2015-04-04 05:43:56 +08:00
set -l ret_part (_fisk_concat \
2015-04-04 05:37:40 +08:00
(set_color $base03) '[' \
2015-02-16 17:50:40 +08:00
(set_color $ret_color) $last_ret \
2015-04-04 05:37:40 +08:00
(set_color $base03) ']' \
2015-02-16 17:50:40 +08:00
)
2015-04-04 05:43:56 +08:00
set -l user_part (_fisk_concat \
2015-04-04 05:37:40 +08:00
(set_color $base01) $USER \
(set_color $base02) @ \
(set_color $base01) $__fish_prompt_hostname \
2015-02-16 17:50:40 +08:00
)
2015-04-04 05:39:08 +08:00
# Virtualenv, git, &c.
2015-04-04 05:43:56 +08:00
set -l context_part (_fisk_concat \
2015-04-04 05:37:40 +08:00
$__fish_prompt_cwd (prompt_pwd) $venv (set_color -o $c_yellow) (__fish_git_prompt) \
2015-02-16 17:50:40 +08:00
)
2015-04-04 05:43:56 +08:00
set -l prompt_end (_fisk_concat (set_color $base01) '➞')
2015-02-16 17:50:40 +08:00
2015-04-04 05:43:56 +08:00
echo -n (_fisk_concat $ret_part " " $user_part " " $context_part " " $prompt_end (set_color normal) " ")
2015-02-16 17:50:40 +08:00
end