-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashgit
42 lines (36 loc) · 1.3 KB
/
bashgit
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
#!/bin/bash
# This is as implementation of git support in bash
function parse_git_commits {
status=`git status -s -b 2> /dev/null | head -n 1`
[[ $status == \#\#* ]] && echo "`sed -n "s/.*ahead \([0-9]*\).*/\+\1/p" <<< "$status"``sed -n "s/.*behind \([0-9]*\).*/\-\1/p" <<< "$status"`"
}
function parse_git_dirty {
[[ -n "`git status -s 2> /dev/null`" ]] && echo "*"
}
function parse_git_branch {
status=`git status -s -b 2> /dev/null | head -n 1`
[[ $status == \#\#* ]] && echo "[$(parse_git_dirty)`echo "$status" | cut -d " " -f2 | cut -d "." -f1`$(parse_git_commits)]"
}
git_ls()
{
status=`git status -s 2> /dev/null`
if [[ -z "$status" ]]; then
`which ls` "$@"
else
declare -a fandfs
declare -a types
while read -r line; do
fandfs+=("`echo "$line" | cut -d "/" -f1 | sed -e s/\ \ /\ /g | cut -d " " -f2`")
types+=("`echo "$line" | cut -d "/" -f1 | sed -e s/\ \ /\ /g | cut -d " " -f1`")
done <<< "$status"
fandfs=(`echo "${fandfs[@]}" | tr ' ' '\n' | sort -u | sed -e 's/[]\/()$*.^|[]/\\\&/g'`)
command="sed"
for file in "${fandfs[@]}"; do
command="$command -e s/\(\s\|^\)\(\x1B\[[0-9;]*[JKmsu]\)*$file/\1\2$file\*/g";
done
export COLUMNS="`tput cols`"
`which ls` -C "$@" | $command
fi
}
alias ls=git_ls
echo "BASH GIT FUNCTIONS ADDED"