Make vim StatuslineGit() return branch for current file
dblume

dblume commited on 2024-03-13 23:55:18
Showing 2 changed files, with 3 additions and 3 deletions.


Use "git -C <path> ..."
... ...
@@ -73,7 +73,7 @@ set tags=tags;/
73 73
 set history=500
74 74
 
75 75
 function! StatuslineGit()
76
-  let l:branchname = system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
76
+  let l:branchname = system("git -C " . expand('%:p:h') . " rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
77 77
   return strlen(l:branchname) > 0 ? ' | branch:'.l:branchname : ''
78 78
 endfunction
79 79
 
... ...
@@ -91,11 +91,11 @@ au InsertLeave * hi statusline term=bold,reverse cterm=bold,reverse ctermfg=24 c
91 91
 
92 92
 set tags=tags;/
93 93
 
94
-set history=50
94
+set history=500
95 95
 set laststatus=2
96 96
 
97 97
 function! StatuslineGit()
98
-  let l:branchname = system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
98
+  let l:branchname = system("git -C " . expand('%:p:h') . " rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
99 99
   return strlen(l:branchname) > 0 ? ' | branch:'.l:branchname : ''
100 100
 endfunction
101 101
 
102 102