78 lines
1.6 KiB
Bash
Executable File
78 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# check if there's .git dir in a parent dir
|
|
isgit() {
|
|
_path="$PWD"
|
|
while [ -n "$_path" ]
|
|
do
|
|
if [ -d "$_path/.git" ]
|
|
then
|
|
return 0
|
|
fi
|
|
_path="${_path%/*}"
|
|
done
|
|
return 1
|
|
}
|
|
|
|
if ! isgit
|
|
then echo "no git repository"
|
|
return
|
|
fi
|
|
|
|
_width=$(tput cols)
|
|
[ $_width -lt 43 ] \
|
|
&& _width=43 \
|
|
|| _width=$(( _width - 3 ))
|
|
|
|
_origin=$(git remote get-url origin \
|
|
2> /dev/null)
|
|
[ -n "$_origin" ] \
|
|
&& echo "# origin: $_origin"
|
|
|
|
_upstream=$(git remote get-url upstream \
|
|
2> /dev/null)
|
|
|
|
[ -n "$_upstream" ] \
|
|
&& echo "# upstream: $_upstream"
|
|
|
|
_base=$(git --no-pager log \
|
|
--abbrev-commit \
|
|
--pretty=format:'%h | %an: %s' \
|
|
HEAD~2...origin/HEAD~1 \
|
|
2> /dev/null)
|
|
|
|
_branch=$(git --no-pager branch \
|
|
--no-color \
|
|
--show-current \
|
|
2> /dev/null)
|
|
|
|
[ -n "$_base" ] \
|
|
&& printf '%s\n' "# branch ($_branch) fork point: $_base" \
|
|
| sed "s/\(.\{$_width\}\).*/\1.../"
|
|
|
|
_log=$(git --no-pager log \
|
|
--reverse \
|
|
--abbrev-commit \
|
|
--date=format:'%d.%m.%y %H:%S' \
|
|
--pretty=format:'%h|%ad|%an: %s' \
|
|
...origin/HEAD \
|
|
2>/dev/null)
|
|
if [ -n "$_log" ]
|
|
then
|
|
echo "# local commits"
|
|
printf '%s\n' "$_log" | sed "s/\(.\{$_width\}\).*/\1.../"
|
|
else
|
|
echo "# no local commits"
|
|
fi
|
|
|
|
_stat=$(git --no-pager status \
|
|
--short 2>/dev/null)
|
|
|
|
if [ -n "$_stat" ]
|
|
then
|
|
echo "# local changes:"
|
|
echo "$_stat"
|
|
else
|
|
echo "# no local changes"
|
|
fi
|