mirror of
https://github.com/mitchell/dotfiles.git
synced 2026-07-17 08:09:35 +00:00
refactor: simplify fish prompt and configs
This commit is contained in:
parent
fddae3ba36
commit
7da5ead1ed
32 changed files with 139 additions and 1156 deletions
|
|
@ -1,6 +1,5 @@
|
|||
function fish_prompt --description 'Write out the prompt'
|
||||
set -l last_status $status
|
||||
set -l color_cwd
|
||||
set -l suffix
|
||||
set -l user_prefix
|
||||
set -l git_branch
|
||||
|
|
@ -19,83 +18,34 @@ function fish_prompt --description 'Write out the prompt'
|
|||
end
|
||||
|
||||
# Set cwd color and prompt suffix, based on current user and fish_bind_mode.
|
||||
switch "$USER"
|
||||
case root toor
|
||||
if set -q fish_color_cwd_root
|
||||
set color_cwd $fish_color_cwd_root
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
end
|
||||
|
||||
set suffix '#'
|
||||
|
||||
if test $fish_key_bindings = 'fish_vi_key_bindings'
|
||||
switch "$fish_bind_mode"
|
||||
case 'insert'
|
||||
set suffix (set_color brblue) $suffix (set_color normal)
|
||||
case 'visual'
|
||||
set suffix (set_color bryellow) $suffix (set_color normal)
|
||||
end
|
||||
end
|
||||
case '*'
|
||||
set color_cwd $fish_color_cwd
|
||||
|
||||
set suffix '>'
|
||||
|
||||
if test $fish_key_bindings = 'fish_vi_key_bindings'
|
||||
switch "$fish_bind_mode"
|
||||
case 'insert'
|
||||
set suffix (set_color brblue) $suffix (set_color normal)
|
||||
case 'default'
|
||||
set suffix '^'
|
||||
case 'visual'
|
||||
set suffix (set_color bryellow) 'v' (set_color normal)
|
||||
end
|
||||
end
|
||||
set suffix '>'
|
||||
if test $fish_key_bindings = fish_vi_key_bindings
|
||||
switch "$fish_bind_mode"
|
||||
case insert
|
||||
set suffix (set_color brblue) $suffix (set_color normal)
|
||||
case default
|
||||
set suffix '<'
|
||||
case visual
|
||||
set suffix (set_color bryellow) v (set_color normal)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Set user_prefix, based on whether or not inside of ssh session.
|
||||
if test -n "$SSH_CLIENT"
|
||||
set user_prefix $USER @ (prompt_hostname) ' '
|
||||
end
|
||||
|
||||
# Show current git branch, based on git commands only.
|
||||
if git status >/dev/null 2>&1
|
||||
set -l branch_color green
|
||||
set -l git_status (git status)
|
||||
|
||||
if string match 'Changes not staged for commit:' $git_status >/dev/null
|
||||
or string match 'Untracked files:' $git_status >/dev/null
|
||||
set branch_color red
|
||||
else if string match 'Changes to be committed:' $git_status >/dev/null
|
||||
set branch_color yellow
|
||||
# Show current git branch.
|
||||
if set -l cur_branch (git branch --show-current 2>/dev/null)
|
||||
if test -z "$cur_branch"
|
||||
set cur_branch detached
|
||||
end
|
||||
|
||||
set -l cur_branch (string sub -s 3 (string match -r '^\* .*$' (git branch)))
|
||||
if string match -q '(HEAD detached*' $cur_branch
|
||||
set cur_branch 'detached'
|
||||
end
|
||||
|
||||
if test -n "$cur_branch"
|
||||
set -l cur_branch_len (string length $cur_branch)
|
||||
if test $cur_branch_len -gt 21
|
||||
set -l sub_str (string sub -l 18 $cur_branch)
|
||||
set cur_branch "$sub_str..."
|
||||
end
|
||||
end
|
||||
|
||||
if string match 'Your branch is ahead of*' $git_status >/dev/null
|
||||
set cur_branch $cur_branch \u21A5
|
||||
else if string match 'Your branch is behind*' $git_status >/dev/null
|
||||
set cur_branch $cur_branch \u21A7
|
||||
end
|
||||
|
||||
set git_branch ' on ' (set_color $branch_color) $cur_branch (set_color normal)
|
||||
set git_branch ' on ' (set_color $fish_color_cwd) $cur_branch (set_color normal)
|
||||
end
|
||||
|
||||
# Combine all prompt variables
|
||||
set -l cwd (set_color $color_cwd) (prompt_pwd) (set_color normal)
|
||||
set -l cwd (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
|
||||
set -l top_prompt $cwd $git_branch
|
||||
set -l bottom_prompt $user_prefix $jobs_num $exit_code $suffix ' '
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue