Thursday, 28 March 2019

[bash] String manipulation within

In stead of turning to subprocesses with sed and the like. Works at least as of version 4.2.46(2)

# _LAST_PATCH being something like 00.0042. It is a real
# world example and as such not everything makes sense. _MAJOR for instance
# is just dead weight.
shopt -s extglob                    # To get support for more sophisticated pattern
_MAJOR=${_LAST_PATCH%%.+([0-9])}    # Remove longest pattern match from behind
_MINOR=${_LAST_PATCH##+([0-9]).}    # Remove longest pattern match from front
_MINOR=${_MINOR##+(0)}              # Remove leading 0s
_MAJOR=${_MAJOR:-0}                 # If nothing remains, set to 0
_MINOR=${_MINOR:-0}
shopt -u extglob

# Generate the new minor number
((_MINOR += 1))                     # Increment _MINOR
_MINOR=$(printf %04d ${_MINOR})     # left padding with 0. printf is a bash internal!

[git] Create a local branch from another branch

From the active branch git checkout -b <LOCAL_BRANCH> From a donator branch git checkout -b <LOCAL_BRANCH> <DONATING_BRANCH...