
おおまかに言えば、これは私のzsh左プロンプトです。
# Libraries
autoload -Uz colors && colors
# User color
if [ "$(whoami)" = "root" ]; then
COLOR="red"
elif [ "$(whoami)" != "root" ]; then
COLOR="magenta"
fi
# Directory icon
if [ "$()" = "Documents" ]; then
ICON=""
if [ "$()" = "Pictures" ]; then
ICON=""
if [ "$()" = "Videos" ]; then
ICON=""
else
ICON="%~"
fi
export PS1="%B%{$fg[$COLOR]%}$ICON %{$reset_color%}%b"
表示する代わりに
~/Documents/git/project1 >>>
見せたい
"ICON" git/project1 >>>
"ICON"
ユーザーの現在のディレクトリに適した(事前に決定された)アイコンはどこにありますか?ユーザーがこれらの「選択された」ディレクトリの1つにない場合は、相対パスを表示するだけです(例:私のスクリプト)。
このスクリプトはどのようにしてユーザーの現在のディレクトリを読み取り、端末に表示する(または表示しない)アイコンを決定しますか?
答え1
次のことができます。
typeset -A dir_to_icon
and_below='(|/*)'
dir_to_icon=(
~/Documents$and_below '