Skip to content

Instantly share code, notes, and snippets.

@davidxia
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidxia/9038290 to your computer and use it in GitHub Desktop.
Save davidxia/9038290 to your computer and use it in GitHub Desktop.
davidxia fish theme
# name: davidxia
# A Powerline-inspired theme for FISH
#
# # README
#
# In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://gist.github.com/1595572).
## Set this options in your config.fish (if you want to :])
set -g theme_display_user yes
# set -g default_user your_normal_user
set -g current_bg NONE
set segment_separator \u2B80
set right_segment_separator \u2B82
# ===========================
# Helper methods
# ===========================
set -g __fish_git_prompt_showdirtystate 'yes'
set -g __fish_git_prompt_char_dirtystate '±'
set -g __fish_git_prompt_char_cleanstate ''
function parse_git_dirty
set -l submodule_syntax
set submodule_syntax "--ignore-submodules=dirty"
set git_dirty (command git status -s $submodule_syntax 2> /dev/null)
if [ -n "$git_dirty" ]
if [ $__fish_git_prompt_showdirtystate = "yes" ]
echo -n "$__fish_git_prompt_char_dirtystate"
end
else
if [ $__fish_git_prompt_showdirtystate = "yes" ]
echo -n "$__fish_git_prompt_char_cleanstate"
end
end
end
# ===========================
# Segments functions
# ===========================
function prompt_segment -d "Function to draw a segment"
set -l bg
set -l fg
if [ -n "$argv[1]" ]
set bg $argv[1]
else
set bg normal
end
if [ -n "$argv[2]" ]
set fg $argv[2]
else
set fg normal
end
if [ "$current_bg" != 'NONE' -a "$argv[1]" != "$current_bg" ]
set_color -b $bg
set_color $current_bg
echo -n "$segment_separator "
set_color -b $bg
set_color $fg
else
set_color -b $bg
set_color $fg
echo -n " "
end
set current_bg $argv[1]
if [ -n "$argv[3]" ]
echo -n -s $argv[3] " "
end
end
function right_prompt_segment -d "Function to draw a right segment"
set -l bg
set -l fg
if [ -n "$argv[1]" ]
set bg $argv[1]
else
set bg normal
end
if [ -n "$argv[2]" ]
set fg $argv[2]
else
set fg normal
end
if [ "$current_bg" != 'NONE' -a "$argv[1]" != "$current_bg" ]
set_color -b $bg
set_color $current_bg
echo -n "$right_segment_separator "
set_color -b $bg
set_color $fg
else
set_color -b $bg
set_color $fg
echo -n " "
end
set current_bg $argv[1]
if [ -n "$argv[3]" ]
echo -n -s $argv[3] " "
end
end
function prompt_finish -d "Close open segments"
if [ -n $current_bg ]
set_color -b normal
set_color $current_bg
echo -n "$segment_separator "
end
set -g current_bg NONE
end
function prompt_newline -d "Newline"
printf "\f\r"
set -g current_bg yellow
set_color -b $current_bg
echo -n " "
end
function right_prompt_finish -d "Close open segments"
if [ -n $current_bg ]
set_color -b normal
set_color $current_bg
end
set -g current_bg NONE
end
# ===========================
# Theme components
# ===========================
function prompt_user -d "Display actual user if different from $default_user"
if [ "$theme_display_user" = "yes" ]
if [ "$USER" != "$default_user" -o -n "$SSH_CLIENT" ]
set USER_PROMPT (whoami)@(hostname -s)
prompt_segment green black $USER_PROMPT
end
end
end
function prompt_dir -d "Display the actual directory"
prompt_segment blue white (prompt_pwd)
end
function prompt_git -d "Display the actual git state"
set -l ref
set -l dirty
if command git rev-parse --is-inside-work-tree >/dev/null 2>&1
set dirty (parse_git_dirty)
set ref (command git symbolic-ref HEAD 2> /dev/null)
set ref (command git symbolic-ref HEAD 2> /dev/null)
if [ $status -gt 0 ]
set -l branch (command git show-ref --head -s --abbrev |head -n1 2> /dev/null)
set ref "➦ $branch "
end
set branch_symbol "⭠"
set -l branch (echo $ref | sed "s-refs/heads/-$branch_symbol -")
if [ "$dirty" != "" ]
prompt_segment yellow black "$branch $dirty"
else
prompt_segment green black "$branch $dirty"
end
end
end
function prompt_virtualenvwrapper -d "Display virtualenv if any"
if set -q VIRTUAL_ENV
set -l virtualenv_status "("(basename "$VIRTUAL_ENV")")"
prompt_segment purple white "$virtualenv_status"
end
end
function prompt_status -d "the symbols for a non zero exit status, root and background jobs"
if [ $RETVAL -ne 0 ]
prompt_segment black red "✘"
end
# if superuser (uid == 0)
set -l uid (id -u $USER)
if [ $uid -eq 0 ]
prompt_segment black yellow "⚡"
end
# Jobs display
if [ (jobs -l | wc -l) -gt 0 ]
prompt_segment black cyan "⚙"
end
end
function prompt_time -d "Display the time"
set_color white --background normal
echo -n "$right_segment_separator"
set time (date "+%H:%M:%S")
right_prompt_segment white 585858 "$time"
end
function prompt_date -d "Display the time"
# set_color 585858 --background white
echo -n "$right_segment_separator"
set dt (date "+%Y-%m-%d")
set_color white --background 585858
echo -n " $dt "
end
# ===========================
# Apply theme
# ===========================
function fish_prompt -d "Display custom fish prompt"
set -g RETVAL $status
prompt_status
prompt_user
prompt_dir
prompt_git
prompt_virtualenvwrapper
prompt_finish
prompt_newline
prompt_finish
end
function fish_right_prompt
prompt_time
prompt_date
right_prompt_finish
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment