summaryrefslogtreecommitdiff
path: root/fish/functions/vcs_string.fish
blob: 56ae1f9f02d9ce54888f42aa2f9aeb531b865673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function vcs_string
  set -l green (set_color -o 00A000)
  set -l yellow (set_color -o FF9900)
  set -l red (set_color -o red)
  set -l blue (set_color -o blue)
  set -l brown (set_color brown)
  set -l normal (set_color normal)

  set -l nstr " $red●"
  set -l mstr " $yellow●"
  set -l rstr " $green●"
  set vcs_str ""

  if begin test -d ".git"; or test -d "../.git"; or test -d "../../.git"; end;
    set -l outp (git status)
    set vcs_str "×"
    set vcs_inf (echo $outp | head -n 1 | cut -d' ' -f 3)

    if echo $outp | grep -q "Untracked files:";
      set vcs_new $nstr;
    end
    if echo $outp | grep -q 'Changes not staged for commit:';
      set vcs_mod $mstr;
    end
    if echo $outp | grep -q 'Changes to be committed:';
      set vcs_rec $rstr
    end
  else if begin test -d "_darcs"; or test -d "../_darcs"; or test -d "../../_darcs"; end;
    set fls (darcs show files)
    set vcs_str "+"
    set vcs_inf (darcs show repo | grep Default | cut -d : -f 3-)
    # TODO: Find a way to use darcs to set vcs_new
    # This is very inefficient, have to basically check all files in
    # the current directory to see if they match the listing.
    # for f in ./*;
    #   if not echo $fls | grep -q $f;
    #     set vcs_new $nstr
    #     break
    #   end
    # end
    if not darcs what | grep -q "No changes";
      set vcs_rec $rstr
    end
  end

  if not [ "$vcs_str" = "" ];
	  echo -ne "$normal$vcs_str$normal{$blue$vcs_inf$vcs_rec$vcs_mod$vcs_new$normal}"
  end
  return 0
end