Skip to content

Commit

Permalink
Make old Fossil branch name work without sed
Browse files Browse the repository at this point in the history
Not only is getting rid of sed a good thing (for speed), but also I
learned that Fossil branch names can contain any character. This makes
the matching of what is a branch name impossible, but this new way is
more durable than it probably needs to be.

Anyway, if a user doesn't have Fossil 2.7+, let's hope they upgrade.
  • Loading branch information
Rycieos committed Nov 25, 2020
1 parent bf2b9c6 commit 6d94db6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion liquidprompt
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,17 @@ _lp_fossil_branch() {

# branch current command added in fossil 2.7
if ! branch="$(\fossil branch current 2>/dev/null)"; then
branch=$(\fossil branch list 2>/dev/null | sed -n 's/^\*\s\s*\(\w*\)$/\1/p')
# Almost any character can be in a branch name, but we have no way of
# knowing if a newline is part of the name or not. In fact, there is no
# way to prevent a branch containing the string '\n* ' to not break
# this. Just hope that no one crazy enough to do that to their branch
# names is running Fossil <2.7
branch="$(\fossil branch list 2>/dev/null)"
branch="${branch#*$'\n\* '}"
# If the current branch is the first in the list, the above check would
# not have removed anything
branch="${branch#\* }"
branch="${branch%%$'\n'*}"
fi

if [[ -n "$branch" ]]; then
Expand Down

0 comments on commit 6d94db6

Please sign in to comment.