mirror of
https://github.com/rydesun/dotfiles.git
synced 2025-12-26 14:44:58 +08:00
30 lines
750 B
Bash
30 lines
750 B
Bash
() {
|
|
[[ $# == 0 ]] && local pwd="$PWD" || local pwd=$1
|
|
[[ -z "$pwd" || "$pwd" == "/" ]] && echo $pwd && return
|
|
|
|
pwd="${pwd%/}"
|
|
local home="${HOME%/}"
|
|
[[ "$pwd" == "$home" ]] && echo "~" && return
|
|
|
|
local offset=${#home}
|
|
[[ "$pwd" == "$home/"* ]] && pwd="~${pwd:$offset}"
|
|
|
|
local names=("${(s:/:)pwd}")
|
|
local sum=${#names}
|
|
((sum <= 3)) && echo "$pwd" && return
|
|
|
|
|
|
for i in {3..$((sum-1))}; do
|
|
local name=${names[$i]}
|
|
[[ ${#name} == 1 ]] && continue
|
|
|
|
local first_c=${name:0:1}
|
|
[[ $first_c == '.' ]] && name=${name:0:2} || name=${name:0:1}
|
|
names[$i]=$Z_PROMPT_COLLAPSED_PWD$name$Z_PROMPT_PWD_L
|
|
done
|
|
|
|
local IFS="/"
|
|
echo "${names[*]}"
|
|
}
|
|
|
|
# vim:set filetype=zsh:
|