2021-04-01 12:24:27 +00:00
|
|
|
# name: Arrow
|
2014-06-20 13:51:09 +00:00
|
|
|
# author: Bruno Ferreira Pinto, Pawel Zubrycki
|
2012-10-16 01:45:46 +00:00
|
|
|
|
2013-05-13 17:17:31 +00:00
|
|
|
function fish_prompt
|
2017-03-13 23:02:14 +00:00
|
|
|
set -l __last_command_exit_status $status
|
2012-10-16 01:45:46 +00:00
|
|
|
|
2021-04-01 12:24:27 +00:00
|
|
|
if not set -q -g __fish_arrow_functions_defined
|
|
|
|
set -g __fish_arrow_functions_defined
|
2016-11-02 02:19:45 +00:00
|
|
|
function _git_branch_name
|
2018-04-28 16:15:52 +00:00
|
|
|
set -l branch (git symbolic-ref --quiet HEAD 2>/dev/null)
|
2017-02-17 05:21:12 +00:00
|
|
|
if set -q branch[1]
|
|
|
|
echo (string replace -r '^refs/heads/' '' $branch)
|
|
|
|
else
|
2018-04-28 16:15:52 +00:00
|
|
|
echo (git rev-parse --short HEAD 2>/dev/null)
|
2017-02-17 05:21:12 +00:00
|
|
|
end
|
2016-11-02 02:19:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _is_git_dirty
|
2021-04-01 12:07:04 +00:00
|
|
|
not command git diff-index --cached --quiet HEAD -- &>/dev/null
|
|
|
|
or not command git diff --no-ext-diff --quiet --exit-code &>/dev/null
|
2016-11-02 02:19:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _is_git_repo
|
|
|
|
type -q git
|
|
|
|
or return 1
|
2018-11-29 18:33:43 +00:00
|
|
|
git rev-parse --git-dir >/dev/null 2>&1
|
2016-11-02 02:19:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _hg_branch_name
|
2018-04-28 16:15:52 +00:00
|
|
|
echo (hg branch 2>/dev/null)
|
2016-11-02 02:19:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _is_hg_dirty
|
2021-04-01 12:07:04 +00:00
|
|
|
set -l stat (hg status -mard 2>/dev/null)
|
|
|
|
test -n "$stat"
|
2016-11-02 02:19:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _is_hg_repo
|
2018-11-30 19:58:34 +00:00
|
|
|
fish_print_hg_root >/dev/null
|
2016-11-02 02:19:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _repo_branch_name
|
2018-11-29 18:33:43 +00:00
|
|
|
_$argv[1]_branch_name
|
2016-11-02 02:19:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _is_repo_dirty
|
2018-11-29 18:33:43 +00:00
|
|
|
_is_$argv[1]_dirty
|
2016-11-02 02:19:45 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function _repo_type
|
|
|
|
if _is_hg_repo
|
2020-03-09 18:36:12 +00:00
|
|
|
echo hg
|
2018-11-29 18:33:43 +00:00
|
|
|
return 0
|
2016-11-02 02:19:45 +00:00
|
|
|
else if _is_git_repo
|
2020-03-09 18:36:12 +00:00
|
|
|
echo git
|
2018-11-29 18:33:43 +00:00
|
|
|
return 0
|
2016-11-02 02:19:45 +00:00
|
|
|
end
|
2018-11-29 18:33:43 +00:00
|
|
|
return 1
|
2016-11-02 02:19:45 +00:00
|
|
|
end
|
2013-05-13 17:17:31 +00:00
|
|
|
end
|
2014-06-20 13:51:09 +00:00
|
|
|
|
2016-11-02 02:19:45 +00:00
|
|
|
set -l cyan (set_color -o cyan)
|
|
|
|
set -l yellow (set_color -o yellow)
|
|
|
|
set -l red (set_color -o red)
|
2017-03-13 23:02:14 +00:00
|
|
|
set -l green (set_color -o green)
|
2016-11-02 02:19:45 +00:00
|
|
|
set -l blue (set_color -o blue)
|
|
|
|
set -l normal (set_color normal)
|
2014-06-20 13:51:09 +00:00
|
|
|
|
2017-03-13 23:02:14 +00:00
|
|
|
set -l arrow_color "$green"
|
|
|
|
if test $__last_command_exit_status != 0
|
|
|
|
set arrow_color "$red"
|
|
|
|
end
|
|
|
|
|
|
|
|
set -l arrow "$arrow_color➜ "
|
2021-04-01 12:15:10 +00:00
|
|
|
if fish_is_root_user
|
2017-03-13 23:02:14 +00:00
|
|
|
set arrow "$arrow_color# "
|
2014-06-20 13:51:09 +00:00
|
|
|
end
|
|
|
|
|
2016-11-02 02:19:45 +00:00
|
|
|
set -l cwd $cyan(basename (prompt_pwd))
|
2012-10-16 01:45:46 +00:00
|
|
|
|
2020-05-15 05:56:06 +00:00
|
|
|
set -l repo_info
|
2018-11-29 18:33:43 +00:00
|
|
|
if set -l repo_type (_repo_type)
|
2016-11-02 02:19:45 +00:00
|
|
|
set -l repo_branch $red(_repo_branch_name $repo_type)
|
|
|
|
set repo_info "$blue $repo_type:($repo_branch$blue)"
|
2012-10-16 01:45:46 +00:00
|
|
|
|
2021-04-01 12:07:04 +00:00
|
|
|
if _is_repo_dirty $repo_type
|
2016-11-02 02:19:45 +00:00
|
|
|
set -l dirty "$yellow ✗"
|
|
|
|
set repo_info "$repo_info$dirty"
|
|
|
|
end
|
2012-10-16 01:45:46 +00:00
|
|
|
end
|
|
|
|
|
2016-11-02 02:19:45 +00:00
|
|
|
echo -n -s $arrow ' '$cwd $repo_info $normal ' '
|
2012-10-16 01:45:46 +00:00
|
|
|
end
|