2012-10-16 09:45:46 +08:00
|
|
|
# name: Robbyrussell
|
2014-06-20 21:51:09 +08:00
|
|
|
# author: Bruno Ferreira Pinto, Pawel Zubrycki
|
2012-10-16 09:45:46 +08:00
|
|
|
|
2013-05-14 01:17:31 +08:00
|
|
|
function fish_prompt
|
2012-10-16 09:45:46 +08:00
|
|
|
|
2016-11-02 10:19:45 +08:00
|
|
|
if not set -q -g __fish_robbyrussell_functions_defined
|
|
|
|
set -g __fish_robbyrussell_functions_defined
|
|
|
|
function _git_branch_name
|
2017-02-17 13:21:12 +08:00
|
|
|
set -l branch (git symbolic-ref --quiet HEAD ^/dev/null)
|
|
|
|
if set -q branch[1]
|
|
|
|
echo (string replace -r '^refs/heads/' '' $branch)
|
|
|
|
else
|
|
|
|
echo (git rev-parse --short HEAD ^/dev/null)
|
|
|
|
end
|
2016-11-02 10:19:45 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
function _is_git_dirty
|
|
|
|
echo (git status -s --ignore-submodules=dirty ^/dev/null)
|
|
|
|
end
|
|
|
|
|
|
|
|
function _is_git_repo
|
|
|
|
type -q git
|
|
|
|
or return 1
|
|
|
|
git status -s >/dev/null ^/dev/null
|
|
|
|
end
|
|
|
|
|
|
|
|
function _hg_branch_name
|
|
|
|
echo (hg branch ^/dev/null)
|
|
|
|
end
|
|
|
|
|
|
|
|
function _is_hg_dirty
|
|
|
|
echo (hg status -mard ^/dev/null)
|
|
|
|
end
|
|
|
|
|
|
|
|
function _is_hg_repo
|
|
|
|
type -q hg
|
|
|
|
or return 1
|
|
|
|
hg summary >/dev/null ^/dev/null
|
|
|
|
end
|
|
|
|
|
|
|
|
function _repo_branch_name
|
|
|
|
eval "_$argv[1]_branch_name"
|
|
|
|
end
|
|
|
|
|
|
|
|
function _is_repo_dirty
|
|
|
|
eval "_is_$argv[1]_dirty"
|
|
|
|
end
|
|
|
|
|
|
|
|
function _repo_type
|
|
|
|
if _is_hg_repo
|
|
|
|
echo 'hg'
|
|
|
|
else if _is_git_repo
|
|
|
|
echo 'git'
|
|
|
|
end
|
|
|
|
end
|
2013-05-14 01:17:31 +08:00
|
|
|
end
|
2014-06-20 21:51:09 +08:00
|
|
|
|
2016-11-02 10:19:45 +08: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 normal (set_color normal)
|
2014-06-20 21:51:09 +08:00
|
|
|
|
2016-11-02 10:19:45 +08:00
|
|
|
set -l arrow "$red➜ "
|
|
|
|
if [ $USER = 'root' ]
|
|
|
|
set arrow "$red# "
|
2014-06-20 21:51:09 +08:00
|
|
|
end
|
|
|
|
|
2016-11-02 10:19:45 +08:00
|
|
|
set -l cwd $cyan(basename (prompt_pwd))
|
2012-10-16 09:45:46 +08:00
|
|
|
|
2016-11-02 10:19:45 +08:00
|
|
|
set -l repo_type (_repo_type)
|
|
|
|
if [ $repo_type ]
|
|
|
|
set -l repo_branch $red(_repo_branch_name $repo_type)
|
|
|
|
set repo_info "$blue $repo_type:($repo_branch$blue)"
|
2012-10-16 09:45:46 +08:00
|
|
|
|
2016-11-02 10:19:45 +08:00
|
|
|
if [ (_is_repo_dirty $repo_type) ]
|
|
|
|
set -l dirty "$yellow ✗"
|
|
|
|
set repo_info "$repo_info$dirty"
|
|
|
|
end
|
2012-10-16 09:45:46 +08:00
|
|
|
end
|
|
|
|
|
2016-11-02 10:19:45 +08:00
|
|
|
echo -n -s $arrow ' '$cwd $repo_info $normal ' '
|
2012-10-16 09:45:46 +08:00
|
|
|
end
|