Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Created October 6, 2014 17:06
Show Gist options
  • Select an option

  • Save inxilpro/d55553620048f3782bf2 to your computer and use it in GitHub Desktop.

Select an option

Save inxilpro/d55553620048f3782bf2 to your computer and use it in GitHub Desktop.
~/.config/fish/functions/
## Function to show a segment
function prompt_segment -d "Function to show a segment"
# Get colors
set -l bg $argv[1]
set -l fg $argv[2]
# Set 'em
set_color -b $bg
set_color $fg
# Print text
if [ -n "$argv[3]" ]
echo -n -s $argv[3]
end
end
## Function to show current status
function show_status -d "Function to show the current status"
if [ $RETVAL -ne 0 ]
prompt_segment red white " ☓ "
end
end
## Show user if not "inxilpro"
function show_user -d "Show user"
if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
set -l HOST (hostname -s)
prompt_segment black yellow (whoami)
# Skip @ bit if hostname == username
if [ "$USER" != "$HOST" ]
prompt_segment black white "@"
prompt_segment black green "$HOST"
end
end
end
# Show directory
function show_pwd -d "Show the current directory"
set -l pwd (prompt_pwd)
prompt_segment black blue " $pwd "
end
# Show prompt w/ privilege cue
function show_prompt -d "Shows prompt with cue for current priv"
set -l uid (id -u $USER)
if [ $uid -eq 0 ]
prompt_segment red white " ! "
set_color normal
echo -n -s " "
else
prompt_segment normal white " \$ "
end
set_color normal
end
## SHOW PROMPT
function fish_prompt
set -g RETVAL $status
show_status
show_user
show_pwd
show_prompt
end
function get_git_status -d "Gets the current git status"
if command git rev-parse --is-inside-work-tree >/dev/null 2>&1
set -l dirty (command git status -s --ignore-submodules=dirty | wc -l | sed -e 's/^ *//' -e 's/ *$//' 2> /dev/null)
set -l ref (command git symbolic-ref HEAD | sed "s-refs/heads/--" | sed -e 's/^ *//' -e 's/ *$//' 2> /dev/null)
set -l branch (command git show-ref --head -s --abbrev | head -n1 2> /dev/null)
if [ "$dirty" != "0" ]
set_color -b black
set_color red
echo "$dirty changed file "
if [ "$dirty" != "1" ]
echo "s"
end
set_color -b red
set_color white
else
set_color -b cyan
set_color white
end
echo " $ref "
set_color normal
end
end
function fish_right_prompt -d "Prints right prompt"
get_git_status
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment