mirror of
https://github.com/spritsail/alpine.git
synced 2024-12-20 11:34:36 +00:00
19 lines
405 B
Bash
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" |