2
0
mirror of https://github.com/spritsail/alpine.git synced 2024-12-20 11:34:36 +00:00
alpine/skel/usr/bin/ppwd

19 lines
405 B
Plaintext
Raw Normal View History

2018-04-17 11:22:52 +00:00
#!/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"