Skip to content

Instantly share code, notes, and snippets.

#! /bin/zsh
# 进度条
width=$[(COLUMNS - 10) * 7 / 8] # 获取屏幕宽度,除了 '#' 号,还要预留几个位置给其他字符
count=0
total=71
float gap=$[total * 1.0 / width] # 每隔多少个,进度条增加一
bar=""
pathshorten() {
local parts=() # 用于存储缩短后的路径部分
local head=${(%):-"%-1~"} # ${(%):-word} 把 word 展开
local tail=${${(D)PWD}#$head} # ${(D)PWD} 缩短替换目录
if [[ $1 == '-u' ]] { # 尝试找到每个目录部分的唯一最短前缀,确保路径的唯一性
local base=${~head} # 展开为实际路径(不能加双引号!!)
# 将 tail 按 '/' 分割,并处理每一部分
# 空 tail 则替换成 '/',因为之后要用 ':h' 处理。"/":h 为空,而 "":h 为 "."