busybox/skel/usr/bin/ppwd

19 lines
405 B
Bash

#!/bin/sh
set -e -o pipefail
dir="$(echo -n "${1:-$PWD}" | sed "s|$HOME|~|")"
if [ "$dir" = '~' -o "$dir" = '/' ]; then
echo "$dir"
exit 0
fi
parts="$(echo "$dir" | tr '/' '\n' | sed '$d')"
last="$(echo "$dir" | tr '/' '\n' | tail -n 1)"
for d in "$parts"; do
out="$out$(echo "$d" | sed -E '/^\./s/^(.{2}).*/\1/;/^[^\.]/s/^(.{1}).*/\1/')\n"
done
echo -en "$out" | tr '\n' '/'
echo "$last"