all repos

dotfiles @ 5fb063a71531336f492287c227e54abca00f076f

i use rach linux btw

dotfiles/config/fish/functions/prompt_vcs.fish (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
updates, 1 month ago
1
function prompt_vcs
2
  set -l dir $PWD
3
  set -l depth 0
4
5
  while test "$dir" != / -a $depth -lt 20
6
    if test -d "$dir/.jj"
7
      _prompt_vcs_jj
8
      return
9
    else if test -d "$dir/.git"
10
      _prompt_vcs_git $dir
11
      return
12
    end
13
    set dir (path dirname $dir)
14
  end
15
end
16
17
function _prompt_vcs_seg -a label
18
  printf '%s%s%s' (set_color blue) $label (set_color normal)
19
end
20
21
function _prompt_vcs_jj
22
  command -sq jj; or return
23
  set -l head (jj log --no-graph -r @ -T 'change_id.shortest()' 2>/dev/null)
24
  test -n "$head"; and printf '%s%s%s%s' (set_color normal) (set_color white) 'jj: ' (set_color blue) $head (set_color normal)
25
end
26
27
function _prompt_vcs_git -a root
28
  set -l git_dir "$root/.git"
29
  if test -f "$git_dir"
30
    read -l gitdir_line < "$git_dir"
31
    set git_dir (string replace 'gitdir: ' '' -- $gitdir_line)
32
  end
33
34
  set -l head_file "$git_dir/HEAD"
35
  test -f "$head_file"; or return
36
  read -l head < "$head_file"
37
38
  set -l m (string match -r '^ref: refs/heads/(.*)' -- $head)
39
  _prompt_vcs_seg (test -n "$m[2]"; and echo $m[2]; or string sub -l 7 -- $head)
40
end