Resultado

Resultado

Estoy usandoohmyzsh. Estoy intentando cargar una diferencia.temasbasado en la ruta del directorio actual ( pwd)

Lógicas

Sipersona con discapacidaden o contiene /Sites/work/carga de cadena af-magic, de lo contrario carga robbyrussell.

.zshrc

He intentado

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

siguió cargandorobbyrussell

Ex.

ingrese la descripción de la imagen aquí

Respuesta1

Si mirasel código oh-my-zsh, esa ZSH_THEMEvariable es utilizada por el código de inicialización de oh-my-zsh para generar un archivo por tema.

Entonces, si desea que el tema cambie cada vez que el directorio de trabajo actual llegue a algún directorio, necesita:

  1. para cambiar esa variable cada vez que cambia el directorio actual
  2. reproducir el mismo origen de archivos temáticos cuando la variable cambia.

Entonces 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)

Por cierto, [[ "$STR" =~ .*"$SUB".* ]]es sintaxis bash, no sintaxis zsh. En zsh, citar variables en expresiones regulares no deshabilita los operadores de expresiones regulares que contiene.

información relacionada