${(D)…}: Reverse filename expansion

(D) assumes that the scalar or array variable contains file paths. It replaces the prefix of these paths with placeholders like ~ and escapes the remainder of the path.

Examples

Print shortened, escaped filepath
1
2
3
4
5
path="$HOME/temp/file with spaces.txt"
echo "File path: ${(D)path}"
  
paths=("$HOME/file1.txt" "$HOME/file2.txt")
echo "File paths: " ${(D)paths}
Output:
1
2
File path: ~/temp/file\ with\ spaces.txt
File paths:  ~/file1.txt ~/file2.txt
BashSupport Pro 是一款支持 D** 的 **Zsh 集成开发环境 - 立即试用
© 2020–2024 Joachim Ansorg
声明
隐私政策
许可条款