[fish] Add custom prompt

This commit is contained in:
lhark 2019-02-24 22:21:07 -05:00
parent 275bfc1a94
commit aeeb952d58
3 changed files with 141 additions and 1 deletions

View file

@ -3,7 +3,8 @@
SETUVAR __fish_init_2_3_0:\x1d SETUVAR __fish_init_2_3_0:\x1d
SETUVAR fish_color_autosuggestion:555\x1ebrblack SETUVAR fish_color_autosuggestion:555\x1ebrblack
SETUVAR fish_color_cancel:\x2dr SETUVAR fish_color_cancel:\x2dr
SETUVAR fish_color_command:005fd7 #SETUVAR fish_color_command:005fd7
SETUVAR fish_color_command:green
SETUVAR fish_color_comment:990000 SETUVAR fish_color_comment:990000
SETUVAR fish_color_cwd:green SETUVAR fish_color_cwd:green
SETUVAR fish_color_cwd_root:red SETUVAR fish_color_cwd_root:red
@ -20,6 +21,7 @@ SETUVAR fish_color_quote:999900
SETUVAR fish_color_redirection:00afff SETUVAR fish_color_redirection:00afff
SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack SETUVAR fish_color_search_match:bryellow\x1e\x2d\x2dbackground\x3dbrblack
SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack SETUVAR fish_color_selection:white\x1e\x2d\x2dbold\x1e\x2d\x2dbackground\x3dbrblack
SETUVAR fish_color_status:red
SETUVAR fish_color_user:brgreen SETUVAR fish_color_user:brgreen
SETUVAR fish_color_valid_path:\x2d\x2dunderline SETUVAR fish_color_valid_path:\x2d\x2dunderline
SETUVAR fish_greeting:Welcome\x20to\x20fish\x2c\x20the\x20friendly\x20interactive\x20shell SETUVAR fish_greeting:Welcome\x20to\x20fish\x2c\x20the\x20friendly\x20interactive\x20shell

View file

@ -0,0 +1,91 @@
set -g fish_color_git_normal blue
set -g fish_color_git_ahead green
set -g fish_color_git_behind red
set -g fish_color_git_diverged magenta
set -g fish_color_git_staged green
set -g fish_color_git_unstaged yellow
set -g fish_color_git_untracked red
set -g fish_color_git_unmerged red
set -g fish_prompt_git_status_ahead '▲'
set -g fish_prompt_git_status_behind '▼'
set -g fish_prompt_git_status_diverged '⯁'
set -g fish_prompt_git_status_staged '●'
set -g fish_prompt_git_status_unstaged '●'
set -g fish_prompt_git_status_untracked '●'
set -g fish_prompt_git_status_unmerged 'M'
set -g fish_prompt_git_status_stashed 'S'
set -g fish_prompt_git_status_order ahead behind diverged staged unstaged untracked unmerged stashed
# Useful chars
# '✓'
# '⚡'
# '✚'
# '●'
# '▾'
# '✖'
# '➜'
# '⇒'
# '➤'
function __plaid_git_prompt --description 'Write out the git prompt'
# If git isn't installed, there's nothing we can do
# Return 1 so the calling prompt can deal with it
if not command -sq git
return 1
end
set -l branch (git rev-parse --abbrev-ref HEAD 2>/dev/null)
if test -z $branch
return
end
set -l index (git status --porcelain -b 2>/dev/null)
set -l rst (set_color normal)
if test -z "$index"
printf '%s[%s]%s' (set_color $fish_color_git_normal) $branch $rst
return
end
set -l gs
printf '%s[%s ' (set_color $fish_color_git_normal) $branch
for i in $index
if echo $i | grep '^[AMRCD]' >/dev/null
set -a gs staged
end
if echo $i | grep '^ [AMRCD]' >/dev/null
set -a gs unstaged
end
if echo $i | grep '^??' >/dev/null
set -a gs untracked
end
if echo $i | grep '^[ADU*][ADU*]' >/dev/null
set -a gs unmerged
end
if echo $i | grep '^## .*ahead' >/dev/null
set -a gs ahead
end
if echo $i | grep '^## .*behind' >/dev/null
set -a gs behind
end
if echo $i | grep '^## .*diverged' >/dev/null
set -a gs diverged
end
if git rev-parse --verify refs/stash >/dev/null 2>&1
set -a gs stashed
end
end
for i in $fish_prompt_git_status_order
if contains $i in $gs
set -l color_name fish_color_git_$i
set -l status_name fish_prompt_git_status_$i
printf '%s%s' (set_color $$color_name) $$status_name
end
end
printf '%s]%s' (set_color $fish_color_git_normal) $rst
end

View file

@ -0,0 +1,47 @@
set -g fish_color_user cyan
set -g fish_color_host green
set -g fish_color_cwd yellow
set -g fish_prompt_pwd_dir_length 0
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
set -l rst (set_color normal)
# User
set -l user (set_color --bold $fish_color_user)(whoami)$rst
# Host
set -l host (set_color --bold $fish_color_host)(prompt_hostname)$rst
# PWD
set -l ppwd (set_color $fish_color_cwd)(prompt_pwd)$rst
# Git
set -l pgit (__plaid_git_prompt)
# __fish_hg_prompt
printf '%s@%s:%s %s\n' $user $host $ppwd $pgit
switch $fish_bind_mode
case default
set_color --bold --background red black
echo -n '⮜N⮞'
case insert
set_color --bold green
echo -n '⮜I⮞'
case replace_one
set_color --bold --background yellow black
echo -n '⮜R⮞'
case visual
set_color --bold --background magenta black
echo -n '⮜V⮞'
end
set_color normal
if not test $last_status -eq 0
set_color $fish_color_error
end
printf ' '
set_color normal
end