2
0
mirror of https://github.com/spritsail/alpine.git synced 2024-11-05 09:26:23 +00:00
alpine/skel/usr/bin/ppwd
2018-04-17 12:54:50 +01:00

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"