estou a usaroh meuzsh. Estou tentando carregar um difftemasbase no caminho do diretório atual ( pwd
)
Lógicas
Sesenhaem ou contém sustring /Sites/work/
load af-magic
, caso contrário load robbyrussell
.
.zshrc
eu tentei
STR=$(pwd)
SUB='/Users/john/Sites/work'
if [[ "$STR" =~ .*"$SUB".* ]]; then
echo "It's there."
ZSH_THEME="af-magic"
else
ZSH_THEME="robbyrussell"
fi
Resultado
continuou carregandorobbyrussell
Ex.
Responder1
Se você olharo código oh-meu-zsh, essa ZSH_THEME
variável é usada pelo código de inicialização oh-my-zsh para gerar um arquivo por tema.
Portanto, se quiser que o tema mude sempre que o diretório de trabalho atual chegar a algum diretório, você precisa:
- para alterar essa variável sempre que o diretório atual mudar
- reproduza a mesma fonte de arquivos de tema quando a variável for alterada.
Então, algo como:
load-omz-theme() {
# copied and improved from oh-my-zsh
if (( $# > 0 )) ZSH_THEME=$1
if [[ -n $ZSH_THEME ]]; then
if [[ -f $ZSH_CUSTOM/$ZSH_THEME.zsh-theme ]]; then
source "$ZSH_CUSTOM/$ZSH_THEME.zsh-theme"
elif [[ -f $ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme ]]; then
source "$ZSH_CUSTOM/themes/$ZSH_THEME.zsh-theme"
else
source "$ZSH/themes/$ZSH_THEME.zsh-theme"
fi
fi
}
adapt-theme() {
local previous_theme=$ZSH_THEME
case $PWD in
($SUB*) ZSH_THEME=af-magic;;
(*) ZSH_THEME=robbyrussell;;
esac
[[ $ZSH_THEME = $previous_theme ]] || load-omz-theme
}
chpwd_functions+=(adapt-theme)
Aliás, [[ "$STR" =~ .*"$SUB".* ]]
é sintaxe bash, não sintaxe zsh. Em zsh
, citar variáveis em regexps não desativa os operadores regexp nele.