Remove calls to grep/egrep

master
Dan Nguyen 10 years ago
parent 3a9239d227
commit e4c6b0ab9e
  1. 24
      gitstatus.sh

@ -5,9 +5,6 @@
# #
# Alan K. Stebbens <aks@stebbens.org> [http://github.com/aks] # Alan K. Stebbens <aks@stebbens.org> [http://github.com/aks]
# helper functions
count_lines() { echo "$1" | egrep -c $3 "^$2" ; }
if [ -z "${__GIT_PROMPT_DIR}" ]; then if [ -z "${__GIT_PROMPT_DIR}" ]; then
SOURCE="${BASH_SOURCE[0]}" SOURCE="${BASH_SOURCE[0]}"
while [ -h "${SOURCE}" ]; do while [ -h "${SOURCE}" ]; do
@ -23,17 +20,27 @@ gitstatus=`LC_ALL=C git status --porcelain --branch`
# if the status is fatal, exit now # if the status is fatal, exit now
[[ "$?" -ne 0 ]] && exit 0 [[ "$?" -ne 0 ]] && exit 0
num_staged=`count_lines "$gitstatus" "(\?\?|##| )" "-v"` num_staged=0
num_changed=`count_lines "$gitstatus" ".M"` num_changed=0
num_conflicts=`count_lines "$gitstatus" "U"` num_conflicts=0
num_untracked=`count_lines "$gitstatus" "\?\?"` num_untracked=0
while IFS='' read -r line || [[ -n "$line" ]]; do
status=${line:0:2}
case "$status" in
\#\#) branch_line="$line" ;;
*M) ((num_changed++)) ;;
U*) ((num_conflicts++)) ;;
\?\?) ((num_untracked++)) ;;
*) ((num_staged++)) ;;
esac
done <<< "$gitstatus"
if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then if [[ "$__GIT_PROMPT_IGNORE_STASH" = "1" ]]; then
num_stashed=0 num_stashed=0
else else
stash_file="`git rev-parse --git-dir`/logs/refs/stash" stash_file="`git rev-parse --git-dir`/logs/refs/stash"
if [[ -e "${stash_file}" ]]; then if [[ -e "${stash_file}" ]]; then
num_stashed=`wc -l "${stash_file}" | cut -d' ' -f 1` num_stashed=`cat "${stash_file} | wc -l`
else else
num_stashed=0 num_stashed=0
fi fi
@ -46,7 +53,6 @@ fi
remote= remote=
branch_line=`echo "$gitstatus" | grep "^##"`
IFS="." read -ra line <<< "${branch_line/\#\# }" IFS="." read -ra line <<< "${branch_line/\#\# }"
branch="${line[0]}" branch="${line[0]}"

Loading…
Cancel
Save