Skip to content

Instantly share code, notes, and snippets.

View filipsalomonsson's full-sized avatar

Filip Salomonsson filipsalomonsson

View GitHub Profile
<?php
/**
* Compare two strings by length first (descending),
* alphabetically second (ascending)
*/
function strlen_cmp($a, $b) {
$diff = strlen($a) - strlen($b);
return ($diff != 0) ? -$diff : strcmp($a, $b);
}
function parse_git_branch {
git_status="$(git status 2> /dev/null)"
pattern="^# On branch ([^${IFS}]*)"
if [[ ! ${git_status}} =~ "working directory clean" ]]; then
state="*"
fi
# add an else if or two here if you want to get more specific
if [[ ${git_status} =~ ${pattern} ]]; then
branch=${BASH_REMATCH[1]}