diff options
Diffstat (limited to '.config/fish/functions/fish_right_prompt.fish')
| -rw-r--r-- | .config/fish/functions/fish_right_prompt.fish | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/.config/fish/functions/fish_right_prompt.fish b/.config/fish/functions/fish_right_prompt.fish new file mode 100644 index 0000000..0dbcc37 --- /dev/null +++ b/.config/fish/functions/fish_right_prompt.fish | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | function fish_right_prompt -d "Write out the right prompt" | ||
| 2 | |||
| 3 | if not set -q -g __fish_right_prompt_functions_defined | ||
| 4 | set -g __fish_right_prompt_functions_defined | ||
| 5 | function _git_branch_name | ||
| 6 | set -l branch (git symbolic-ref --quiet HEAD 2>/dev/null) | ||
| 7 | if set -q branch[1] | ||
| 8 | echo (string replace -r '^refs/heads/' '' $branch) | ||
| 9 | else | ||
| 10 | echo (git rev-parse --short HEAD 2>/dev/null) | ||
| 11 | end | ||
| 12 | end | ||
| 13 | |||
| 14 | function _is_git_dirty | ||
| 15 | not command git diff-index --cached --quiet HEAD -- &>/dev/null | ||
| 16 | or not command git diff --no-ext-diff --quiet --exit-code &>/dev/null | ||
| 17 | end | ||
| 18 | |||
| 19 | function _is_git_repo | ||
| 20 | type -q git | ||
| 21 | or return 1 | ||
| 22 | git rev-parse --git-dir >/dev/null 2>&1 | ||
| 23 | end | ||
| 24 | |||
| 25 | function _hg_branch_name | ||
| 26 | echo (hg branch 2>/dev/null) | ||
| 27 | end | ||
| 28 | |||
| 29 | function _is_hg_dirty | ||
| 30 | set -l stat (hg status -mard 2>/dev/null) | ||
| 31 | test -n "$stat" | ||
| 32 | end | ||
| 33 | |||
| 34 | function _is_hg_repo | ||
| 35 | fish_print_hg_root >/dev/null | ||
| 36 | end | ||
| 37 | |||
| 38 | function _repo_branch_name | ||
| 39 | _$argv[1]_branch_name | ||
| 40 | end | ||
| 41 | |||
| 42 | function _is_repo_dirty | ||
| 43 | _is_$argv[1]_dirty | ||
| 44 | end | ||
| 45 | |||
| 46 | function _repo_type | ||
| 47 | if _is_hg_repo | ||
| 48 | echo hg | ||
| 49 | return 0 | ||
| 50 | else if _is_git_repo | ||
| 51 | echo git | ||
| 52 | return 0 | ||
| 53 | end | ||
| 54 | return 1 | ||
| 55 | end | ||
| 56 | end | ||
| 57 | |||
| 58 | set -l yellow (set_color -o yellow) | ||
| 59 | set -l red (set_color -o red) | ||
| 60 | set -l blue (set_color -o blue) | ||
| 61 | |||
| 62 | set -l repo_info | ||
| 63 | if set -l repo_type (_repo_type) | ||
| 64 | set -l repo_branch $red(_repo_branch_name $repo_type) | ||
| 65 | set repo_info "$blue $repo_type:($repo_branch$blue)" | ||
| 66 | |||
| 67 | if _is_repo_dirty $repo_type | ||
| 68 | set -l dirty "$yellow ✗" | ||
| 69 | set repo_info "$repo_info$dirty" | ||
| 70 | end | ||
| 71 | end | ||
| 72 | |||
| 73 | set hour $blue(date '+%R') | ||
| 74 | echo -n -s $repo_info ' ' $hour | ||
| 75 | end | ||
