Adding starship prompt for fish

This commit is contained in:
Chris Cochrun 2021-04-21 08:32:52 -05:00
parent 2914131e45
commit 8d97ef1cd2

View file

@ -5,16 +5,6 @@ set TERM "xterm-256color"
set EDITOR "emacsclient -c -a" set EDITOR "emacsclient -c -a"
set VISUAL "emacsclient -c -a emacs" set VISUAL "emacsclient -c -a emacs"
### PROMPT ###
# name: scorphish
# This file is part of theme-scorphish
# Licensed under the MIT license:
# https://opensource.org/licenses/MIT
# Copyright (c) 2014, Pablo S. Blum de Aguiar <scorphus@gmail.com>
function fish_greeting -d "what's up, fish?" function fish_greeting -d "what's up, fish?"
# set_color $fish_color_autosuggestion[1] # set_color $fish_color_autosuggestion[1]
# uname -npsr # uname -npsr
@ -22,163 +12,165 @@ function fish_greeting -d "what's up, fish?"
# set_color normal # set_color normal
end end
function fish_title ## Instead of using a fish prompt, I'm using the starship-rs cross shell prompt.
if [ "$theme_display_virtualenv" = 'no' -o -z "$VIRTUAL_ENV" ]
printf '(%s) %s' $_ (prompt_pwd)
else
printf '(%s) %s' (basename "$VIRTUAL_ENV") (prompt_pwd)
end
end
function _prompt_whoami -a sep_color -a color -d "Display user@host if on a SSH session" # function fish_title
if set -q SSH_TTY # if [ "$theme_display_virtualenv" = 'no' -o -z "$VIRTUAL_ENV" ]
echo -n -s $color (whoami)@(hostnamectl --static) $sep_color '|' # printf '(%s) %s' $_ (prompt_pwd)
end # else
end # printf '(%s) %s' (basename "$VIRTUAL_ENV") (prompt_pwd)
# end
# end
function _git_branch_name # function _prompt_whoami -a sep_color -a color -d "Display user@host if on a SSH session"
echo (command git symbolic-ref HEAD 2> /dev/null | sed -e 's|^refs/heads/||') # if set -q SSH_TTY
end # echo -n -s $color (whoami)@(hostnamectl --static) $sep_color '|'
# end
# end
function _is_git_dirty # function _git_branch_name
echo (command git status -s --ignore-submodules=dirty 2> /dev/null) # echo (command git symbolic-ref HEAD 2> /dev/null | sed -e 's|^refs/heads/||')
end # end
function _git_ahead_count -a remote -a branch_name # function _is_git_dirty
echo (command git log $remote/$branch_name..HEAD 2> /dev/null | \ # echo (command git status -s --ignore-submodules=dirty 2> /dev/null)
grep '^commit' | wc -l | tr -d ' ') # end
end
function _git_dirty_remotes -a remote_color -a ahead_color # function _git_ahead_count -a remote -a branch_name
set current_branch (command git rev-parse --abbrev-ref HEAD 2> /dev/null) # echo (command git log $remote/$branch_name..HEAD 2> /dev/null | \
set current_ref (command git rev-parse HEAD 2> /dev/null) # grep '^commit' | wc -l | tr -d ' ')
# end
for remote in (git remote | grep 'origin\|upstream') # function _git_dirty_remotes -a remote_color -a ahead_color
# set current_branch (command git rev-parse --abbrev-ref HEAD 2> /dev/null)
# set current_ref (command git rev-parse HEAD 2> /dev/null)
set -l git_ahead_count (_git_ahead_count $remote $current_branch) # for remote in (git remote | grep 'origin\|upstream')
set remote_branch "refs/remotes/$remote/$current_branch" # set -l git_ahead_count (_git_ahead_count $remote $current_branch)
set remote_ref (git for-each-ref --format='%(objectname)' $remote_branch)
if test "$remote_ref" != ''
if test "$remote_ref" != $current_ref
if [ $git_ahead_count != 0 ]
echo -n "$remote_color!"
echo -n "$ahead_color+$git_ahead_count$normal"
end
end
end
end
end
function _prompt_git -a gray normal orange red yellow # set remote_branch "refs/remotes/$remote/$current_branch"
test "$theme_display_git" = no; and return # set remote_ref (git for-each-ref --format='%(objectname)' $remote_branch)
set -l git_branch (_git_branch_name) # if test "$remote_ref" != ''
test -z $git_branch; and return # if test "$remote_ref" != $current_ref
if test "$theme_display_git_dirty" = no # if [ $git_ahead_count != 0 ]
echo -n -s $gray '' $yellow $git_branch $gray ' ' # echo -n "$remote_color!"
return # echo -n "$ahead_color+$git_ahead_count$normal"
end # end
set dirty_remotes (_git_dirty_remotes $red $orange) # end
if [ (_is_git_dirty) ] # end
echo -n -s $gray '' $yellow $git_branch $red '*' $dirty_remotes $gray ' ' # end
else # end
echo -n -s $gray '' $yellow $git_branch $red $dirty_remotes $gray ' '
end
end
function _prompt_pwd # function _prompt_git -a gray normal orange red yellow
set_color -o cyan # test "$theme_display_git" = no; and return
printf '%s' (prompt_pwd) # set -l git_branch (_git_branch_name)
end # test -z $git_branch; and return
# if test "$theme_display_git_dirty" = no
# echo -n -s $gray '' $yellow $git_branch $gray ' '
# return
# end
# set dirty_remotes (_git_dirty_remotes $red $orange)
# if [ (_is_git_dirty) ]
# echo -n -s $gray '' $yellow $git_branch $red '*' $dirty_remotes $gray ' '
# else
# echo -n -s $gray '' $yellow $git_branch $red $dirty_remotes $gray ' '
# end
# end
function _prompt_status_arrows -a exit_code # function _prompt_pwd
if test $exit_code -ne 0 # set_color -o cyan
set arrow_colors green # printf '%s' (prompt_pwd)
else # end
set arrow_colors green
end
for arrow_color in $arrow_colors # function _prompt_status_arrows -a exit_code
set_color $arrow_color # if test $exit_code -ne 0
printf '»' # set arrow_colors green
end # else
end # set arrow_colors green
# end
function fish_prompt # for arrow_color in $arrow_colors
set -l exit_code $status # set_color $arrow_color
# printf '»'
# end
# end
set -l gray (set_color 666) # function fish_prompt
set -l blue (set_color blue) # set -l exit_code $status
set -l red (set_color red)
set -l normal (set_color normal)
set -l yellow (set_color yellow)
set -l orange (set_color ff9900)
set -l green (set_color green)
printf $gray'[' # set -l gray (set_color 666)
# set -l blue (set_color blue)
# set -l red (set_color red)
# set -l normal (set_color normal)
# set -l yellow (set_color yellow)
# set -l orange (set_color ff9900)
# set -l green (set_color green)
_prompt_whoami $gray $green # printf $gray'['
if test "$theme_display_pwd_on_second_line" != yes # _prompt_whoami $gray $green
_prompt_pwd
printf '%s' $gray
end
printf '%s] ⚡️ %0.3fs' $gray (math $CMD_DURATION / 1000) # if test "$theme_display_pwd_on_second_line" != yes
# _prompt_pwd
# printf '%s' $gray
# end
if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE # printf '%s] ⚡️ %0.3fs' $gray (math $CMD_DURATION / 1000)
set theme_display_git_on_first_line
end
if set -q theme_display_git_on_first_line # if set -q SCORPHISH_GIT_INFO_ON_FIRST_LINE
_prompt_git $gray $normal $orange $red $yellow # set theme_display_git_on_first_line
end # end
if test "$theme_display_pwd_on_second_line" = yes # if set -q theme_display_git_on_first_line
printf $gray'\n' # _prompt_git $gray $normal $orange $red $yellow
_prompt_pwd # end
printf $gray''
end
printf '\n' # if test "$theme_display_pwd_on_second_line" = yes
if not set -q theme_display_git_on_first_line # printf $gray'\n'
_prompt_git $gray $normal $orange $red $yellow # _prompt_pwd
end # printf $gray''
_prompt_status_arrows $exit_code # end
printf ' '
set_color normal # printf '\n'
end # if not set -q theme_display_git_on_first_line
# _prompt_git $gray $normal $orange $red $yellow
# end
# _prompt_status_arrows $exit_code
# printf ' '
function fish_right_prompt # set_color normal
set -l exit_code $status # end
if test $exit_code -ne 0
set_color red
else
set_color green
end
printf '%d' $exit_code
set_color -o 666
echo '|'
set_color -o 777
printf '%s' (date +%H:%M:%S)
set_color normal
end
### VI MODES # function fish_right_prompt
# Emulates vim's cursor shape behavior # set -l exit_code $status
# Set the normal and visual mode cursors to a block # if test $exit_code -ne 0
set fish_cursor_default block # set_color red
# Set the insert mode cursor to a line # else
set fish_cursor_insert line # set_color green
# Set the replace mode cursor to an underscore # end
set fish_cursor_replace_one underscore # printf '%d' $exit_code
# The following variable can be used to configure cursor shape in # set_color -o 666
# visual mode, but due to fish_cursor_default, is redundant here # echo '|'
set fish_cursor_visual block # set_color -o 777
# printf '%s' (date +%H:%M:%S)
# set_color normal
# end
### BANG BANG FUNCTIONS ### VI MODES
function __history_previous_command # Emulates vim's cursor shape behavior
# Set the normal and visual mode cursors to a block
set fish_cursor_default block
# Set the insert mode cursor to a line
set fish_cursor_insert line
# Set the replace mode cursor to an underscore
set fish_cursor_replace_one underscore
# The following variable can be used to configure cursor shape in
# visual mode, but due to fish_cursor_default, is redundant here
set fish_cursor_visual block
### BANG BANG FUNCTIONS
function __history_previous_command
switch (commandline -t) switch (commandline -t)
case "!" case "!"
commandline -t $history[1] commandline -t $history[1]
@ -205,8 +197,10 @@ function fish_user_key_bindings
bind -M insert '$' __history_previous_command_arguments bind -M insert '$' __history_previous_command_arguments
end end
starship init fish | source
### ALIASES ### ALIASES
alias yay "paru" alias yay "paru"
alias yeet "paru -Rns" alias yeet "paru -Rns"
alias ls "exa -l"
alias la "exa -la"