Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a function to wrap git #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions bash-powerline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,20 @@ __powerline() {
__git_info() {
[[ $POWERLINE_GIT = 0 ]] && return # disabled
hash git 2>/dev/null || return # git not found
local git_eng="env LANG=C git" # force git output in English to make our work easier
git_eng() {
# Force 'git' English output.
env LANG=C git "$@"
}

# get current branch name
local ref=$($git_eng symbolic-ref --short HEAD 2>/dev/null)
local ref=$(git_eng symbolic-ref --short HEAD 2>/dev/null)

if [[ -n "$ref" ]]; then
# prepend branch symbol
ref=$SYMBOL_GIT_BRANCH$ref
else
# get tag name or short unique hash
ref=$($git_eng describe --tags --always 2>/dev/null)
ref=$(git_eng describe --tags --always 2>/dev/null)
fi

[[ -n "$ref" ]] || return # not a git repo
Expand All @@ -53,7 +56,7 @@ __powerline() {
marks="$SYMBOL_GIT_MODIFIED$marks"
break
fi
done < <($git_eng status --porcelain --branch 2>/dev/null) # note the space between the two <
done < <(git_eng status --porcelain --branch 2>/dev/null) # note the space between the two <

# print the git branch segment without a trailing newline
printf " $ref$marks"
Expand Down