tenebrous /short_pwd

#!/bin/bash

# return a pwd string similar to vim's pathshorten()
maxlen="${1:-15}"
txt="${PWD//$HOME/~}"
if [ "$txt" = "~" ]; then
    echo "~"
else
    ispath="n"
    result=""
    base=$(basename "$txt")
    txt=$(dirname "$txt")
    for i in $(seq 0 ${#txt}); do
        c="${txt:$i:1}"
        if [ "$c" = "/" ]; then
            ispath="y"
            if [ "${txt:$i+1:1}" = "." ]; then
                result="$result${txt:$i:3}"
            else
                result="$result${txt:$i:2}"
            fi
        elif [ "$ispath" = "n" ]; then
            result="$result$c"
        fi    
    done

    if [ "${result}" != "/" ]; then
        if [ ${#result} -gt $maxlen ]; then
            echo -n "${result:0:$((maxlen - 3))}..."
        else
            echo -n "${result}"
        fi
    fi
    echo "/${base}"
fi