2014-04-05 04:26:17 +08:00
|
|
|
# name: Integral
|
|
|
|
function _git_branch_name
|
|
|
|
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
|
|
|
|
end
|
|
|
|
|
2014-04-05 10:26:35 +08:00
|
|
|
function _upstream_count
|
|
|
|
echo (command git rev-list --count --left-right origin/(_git_branch_name)...HEAD ^/dev/null)
|
|
|
|
end
|
|
|
|
|
|
|
|
function _git_up_info
|
|
|
|
if [ (_upstream_count) ]
|
|
|
|
set -l count (_upstream_count)
|
2014-04-05 07:46:10 +08:00
|
|
|
|
2014-04-05 09:39:07 +08:00
|
|
|
switch $count
|
|
|
|
case "" # no upstream
|
|
|
|
echo ''
|
|
|
|
case "0?0" # equal to upstream
|
|
|
|
echo ''
|
|
|
|
case "0??" # ahead of upstream
|
|
|
|
echo 'u+'(echo $count | cut -f2)
|
|
|
|
case "??0" # behind upstream
|
|
|
|
echo 'u-'(echo $count | cut -f1)
|
|
|
|
case '???' # diverged from upstream
|
2014-04-05 10:26:35 +08:00
|
|
|
echo $count 'u+'(echo $count | cut -f2)'-'(echo $count | cut -f1)
|
|
|
|
case '*'
|
|
|
|
echo ''
|
2014-04-05 04:26:17 +08:00
|
|
|
end
|
2014-04-05 09:39:07 +08:00
|
|
|
end
|
2014-04-05 04:26:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function _is_git_dirty
|
|
|
|
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
|
|
|
|
end
|
|
|
|
|
|
|
|
function fish_prompt
|
|
|
|
set -l blue (set_color blue)
|
|
|
|
set -l yellow (set_color yellow)
|
|
|
|
set -l normal (set_color normal)
|
|
|
|
set -l green (set_color green)
|
|
|
|
|
|
|
|
set -l arrow "∫"
|
2014-04-05 05:14:21 +08:00
|
|
|
set -l cwd $blue(prompt_pwd)
|
2014-04-05 04:26:17 +08:00
|
|
|
|
|
|
|
if [ (_git_branch_name) ]
|
|
|
|
set -l git_branch (_git_branch_name)
|
2014-04-05 10:26:35 +08:00
|
|
|
set -l git_vs_upstream (_git_up_info)
|
2014-04-05 04:26:17 +08:00
|
|
|
|
|
|
|
if [ (_is_git_dirty) ]
|
2014-04-05 10:51:47 +08:00
|
|
|
set git_info $yellow'('$git_branch "±" "$git_vs_upstream"')' $normal
|
2014-04-05 10:31:48 +08:00
|
|
|
else if [ (_git_up_info) ]
|
2014-04-05 10:51:47 +08:00
|
|
|
set git_info $yellow'('$git_branch "$git_vs_upstream"')' $normal
|
2014-04-05 04:26:17 +08:00
|
|
|
else
|
2014-04-05 10:51:47 +08:00
|
|
|
set git_info $green'('$git_branch')' $normal
|
2014-04-05 04:26:17 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-05 10:51:47 +08:00
|
|
|
echo -n -s $cwd' '"$git_info" $normal $arrow ' '
|
2014-04-05 04:26:17 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function fish_right_prompt
|
|
|
|
set -l dark_gray (set_color 222)
|
|
|
|
|
|
|
|
echo -n -s $dark_gray ' ['(date +%H:%M:%S)'] '
|
|
|
|
|
|
|
|
end
|