function svnmore() {
    svn cat "$@" 2>&1 | more
}

function catman() {
    [ -s "$@" ] || {
        echo "Missing or empty file: $@" 1>&2
        return 1
    }
    unzip -p "$@" META-INF/MANIFEST.MF
}
function hms() {
    local strin strdec
    local strh strm strs
    [ $# = 1 ] || {
        echo 'SYNTAX: hms ss||ss.dec||mm:ss|mm:ss.dec|hh:mm:ss|hh:mm:ss.dec' 1>&2
        return 2
    }
    strin="$1"; shift
    case "$strin" in *.*) strdec=${strin##*.}; strin=${strin%%.*};; esac
    case $strin in
        *[^0-9:]*)
            echo 'SYNTAX: hms ss||ss.dec||mm:ss|mm:ss.dec|hh:mm:ss|hh:mm:ss.dec' 1>&2
            return 2;;
    esac
    case "$strin" in
        *:*:*) strh=${strin%%:*}; strs=${strin##*:}
               strin=${strin%:*}; strm=${strin##*:};;
        *:*) strm=${strin%%:*}; strs=${strin##*:};;
        *) strs=$strin;;
    esac
    case "$strs" in 0[0-9]) strs=${strs#0};; esac
    case "$strm" in 0[0-9]) strm=${strm#0};; esac
    case "$strh" in 0[0-9]) strh=${strh#0};; esac
    #echo "($strh/$strm/$strs $strdec)"
    [ -n "$strm" ] && ((strs = strs + 60 * strm))
    [ -n "$strh" ] && ((strs = strs + 60 * 60 * strh))
    echo "$strs${strdec:+.$strdec}"
    return 0
}

function backup() {
    for arg in "$@"; do
        [ -e "${arg}.orig" ] && {
            read -p "Overwrite '${arg}' [Y]? "
            case "$REPLY" in '');; [Yy]*);; *)
                echo 'Skipping '${arg}'.'; continue;;
            esac
        }
        cp -fav "$arg" "${arg}.orig"
    done
}

trimInto_TRIMMED() {
    unset _TRIMMED
    local var="$*"
    # remove leading whitespace characters
    var="${var#"${var%%[![:space:]]*}"}"
    # remove trailing whitespace characters
    _TRIMMED="${var%"${var##*[![:space:]]}"}"   
    [ "$_TRIMMED" != "$*" ]
}

function lstail () {
    local TAIL_SWITCH
    [ $# -gt 0 ] && case "$1" in -[0-9]*) TAIL_SWITCH="$1"; shift;; esac
    ls -ltr "$@" | tail $TAIL_SWITCH
}

gvimm() {
    mapfile -t files < <(
        git status --porcelain |
        perl -nwe 'next unless s/^A. // || s/^ M //; s/\\"/"/g if s/^"(.+)"$/$1/; print;'
    )
    gvim "${files[@]}"
}
