shoestrap/assets/default/fish/functions/fish_prompt.fish

80 lines
2.0 KiB
Fish
Raw Permalink Normal View History

# name: ifij (forked from RobbyRussel)
2015-06-03 20:53:20 +00:00
#
# You can override some default options in your config.fish:
# set -g theme_display_git_untracked no
function _status_color
# Returns a color for successful or failed previous command
if test $last_status -eq 0
echo (set_color -o green)
else
echo (set_color -o red)
end
end
2015-06-03 20:53:20 +00:00
function _git_branch_name
# Returns the name of the current git branch
2015-06-03 20:53:20 +00:00
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _is_git_dirty
# Returns whether or not there is anything uncommitted
2015-06-03 20:53:20 +00:00
set -l show_untracked (git config --bool bash.showUntrackedFiles)
set untracked ''
if [ "$theme_display_git_untracked" = 'no' -o "$show_untracked" = 'false' ]
set untracked '--untracked-files=no'
end
echo (command git status -s --ignore-submodules=dirty $untracked ^/dev/null)
end
function _git_info
# Returns what is to be displayed for the git info
if [ (_git_branch_name) ]
if [ (_is_git_dirty) ]
set branch_color (set_color -o red)
else
set branch_color (set_color -o yellow)
end
set -l git_branch (_git_branch_name)
echo " $branch_color($git_branch)"(set_color normal)
end
end
function _hostname
# Returns the hostname if not using tmux since tmux will display
if [ -z $TMUX ]
2015-08-26 21:31:05 +00:00
echo (hostname -s)" "
end
end
2015-06-03 20:53:20 +00:00
function _prompt_char
# Gives a colored prompt char for user or root
echo -n (_status_color)
2015-06-03 20:53:20 +00:00
if [ (whoami) = 'root' ]
echo -n '#'
2015-06-03 20:53:20 +00:00
else
echo -n '$'
2015-06-03 20:53:20 +00:00
end
echo -n (set_color normal)
2015-06-03 20:53:20 +00:00
end
function fish_prompt
# Build full left side prompt
# NOTE: this becomes a global variable
set -g last_status $status
2015-06-03 20:53:20 +00:00
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l red (set_color -o red)
set -l blue (set_color -o blue)
set -l green (set_color -o green)
set -l normal (set_color normal)
2015-11-03 19:43:06 +00:00
# set -l arrow (_status_color) "➜ $normal"
set -l cwd (basename (prompt_pwd))
2015-06-03 20:53:20 +00:00
echo -n -s $arrow (_hostname) $cwd (_git_info) (_prompt_char) ' '
2015-06-03 20:53:20 +00:00
end