gitstatus script, to possibly use in prompt later on
This commit is contained in:
parent
b9bb220bec
commit
353ae2ab01
2 changed files with 29 additions and 34 deletions
|
@ -1,34 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
import os
|
||||
import pygit2
|
||||
|
||||
def test_status(num, stat_key):
|
||||
if num & stat_key:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
if os.path.isdir(".git"):
|
||||
repo = pygit2.Repository(".git")
|
||||
files = repo.status()
|
||||
staged = 0
|
||||
unstaged = 0
|
||||
confl = 0
|
||||
for filename in files:
|
||||
staged += test_status(files[filename], pygit2.GIT_STATUS_INDEX_NEW)
|
||||
staged += test_status(files[filename], pygit2.GIT_STATUS_INDEX_DELETED)
|
||||
staged += test_status(files[filename], pygit2.GIT_STATUS_INDEX_MODIFIED)
|
||||
unstaged += test_status(files[filename], pygit2.GIT_STATUS_WT_NEW)
|
||||
unstaged += test_status(files[filename], pygit2.GIT_STATUS_WT_DELETED)
|
||||
unstaged += test_status(files[filename], pygit2.GIT_STATUS_WT_MODIFIED)
|
||||
confl += test_status(files[filename], pygit2.GIT_STATUS_CONFLICTED)
|
||||
result = str()
|
||||
if staged > 0:
|
||||
result += 's' + str(staged)
|
||||
if unstaged > 0:
|
||||
result += '+' + str(unstaged)
|
||||
if confl > 0:
|
||||
result += 'x' + str(confl)
|
||||
if not result:
|
||||
result += '.'
|
||||
print(result)
|
29
gitstatus.zsh
Executable file
29
gitstatus.zsh
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env zsh
|
||||
git_status=''
|
||||
staged_count=0
|
||||
unstaged_count=0
|
||||
untracked_count=0
|
||||
ifs_temp=$IFS
|
||||
IFS=
|
||||
if ! raw_status=$(git status --porcelain -bu 2>/dev/null); then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while read line; do
|
||||
if [[ $line[1,2] == '##' ]]; then
|
||||
IFS='.'
|
||||
read branch _ _ origin <<< $line[4,-1]
|
||||
fi
|
||||
[[ $line[1,2] =~ '.[MD]' ]] && (( unstaged_count++ ))
|
||||
[[ $line[1,2] =~ '[MDARC].' ]] && (( staged_count++ ))
|
||||
[[ $line[1,2] == '??' ]] && (( untracked_count++ ))
|
||||
done <<< $raw_status
|
||||
|
||||
(( $unstaged_count > 0 )) && git_status+="u$unstaged_count"
|
||||
(( $staged_count > 0 )) && git_status+="s$staged_count"
|
||||
(( $untracked_count > 0 )) && git_status+="+$untracked_count"
|
||||
[[ -z $git_status ]] && git_status='.'
|
||||
|
||||
full_status="[ $branch {$origin} $git_status ]"
|
||||
|
||||
printf '%s' $full_status
|
Loading…
Reference in a new issue