Last active
August 29, 2015 14:04
-
-
Save niedhui/16b057990f1161c5158c to your computer and use it in GitHub Desktop.
fish_prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.config/fish/functions/fish_prompt.fish | |
function _git_branch_name | |
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||') | |
end | |
function _git_status_symbol | |
set -l git_status (git status --porcelain ^/dev/null) | |
if test -n "$git_status" | |
# Is there anyway to preserve newlines so we can reuse $git_status? | |
if git status --porcelain ^/dev/null | grep '^.[^ ]' >/dev/null | |
echo '*' # dirty | |
else | |
echo '#' # all staged | |
end | |
else | |
echo '' # clean | |
end | |
end | |
function fish_prompt | |
set -l cyan (set_color cyan) | |
set -l normal (set_color normal) | |
set -l cwd (set_color $fish_color_cwd)(prompt_pwd) | |
set -l git_status (_git_status_symbol)(_git_branch_name) | |
if test -n "$git_status" | |
set git_status " $git_status" | |
end | |
echo -n $cwd$cyan$git_status$normal'> ' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment