浏览代码

style(af-magic): fix code style and remove unnecessary variables

Marc Cornellà 2 年之前
父节点
当前提交
c172624398
共有 1 个文件被更改,包括 31 次插入32 次删除
  1. 31 32
      themes/af-magic.zsh-theme

+ 31 - 32
themes/af-magic.zsh-theme

@@ -1,47 +1,46 @@
 # af-magic.zsh-theme
-# Repo: https://github.com/andyfleming/oh-my-zsh
-# Direct Link: https://github.com/andyfleming/oh-my-zsh/blob/master/themes/af-magic.zsh-theme
+#
+# Author: Andy Fleming
+# URL: http://andyfleming.com/
 
-
-# settings
-typeset +H return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
-typeset +H my_gray="$FG[237]"
-typeset +H my_orange="$FG[214]"
-
-# separator dashes size
+# dashed separator size
 function afmagic_dashes {
-	local PYTHON_ENV="$VIRTUAL_ENV"
-	[[ -z "$PYTHON_ENV" ]] && PYTHON_ENV="$CONDA_DEFAULT_ENV"
-
-	if [[ -n "$PYTHON_ENV" && "$PS1" = \(* ]]; then
-		echo $(( COLUMNS - ${#PYTHON_ENV} - 3 ))
-	else
-		echo $COLUMNS
-	fi
+  # check either virtualenv or condaenv variables
+  local python_env="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}"
+
+  # if there is a python virtual environment and it is displayed in
+  # the prompt, account for it when returning the number of dashes
+  if [[ -n "$python_env" && "$PS1" = \(* ]]; then
+    echo $(( COLUMNS - ${#python_env} - 3 ))
+  else
+    echo $COLUMNS
+  fi
 }
 
-# primary prompt
-PS1='$FG[237]${(l.$(afmagic_dashes)..-.)}%{$reset_color%}
-$FG[032]%~$(git_prompt_info)$(hg_prompt_info) $FG[105]%(!.#.»)%{$reset_color%} '
-PS2='%{$fg[red]%}\ %{$reset_color%}'
-RPS1='${return_code}'
+# primary prompt: dashed separator, directory and vcs info
+PS1="${FG[237]}\${(l.\$(afmagic_dashes)..-.)}%{$reset_color%}
+${FG[032]}%~\$(git_prompt_info)\$(hg_prompt_info) ${FG[105]}%(!.#.»)%{$reset_color%} "
+PS2="%{$fg[red]%}\ %{$reset_color%}"
 
-# right prompt
-(( $+functions[virtualenv_prompt_info] )) && RPS1+='$(virtualenv_prompt_info)'
-RPS1+=' $my_gray%n@%m%{$reset_color%}%'
+# right prompt: return code, virtualenv and context (user@host)
+RPS1="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
+if (( $+functions[virtualenv_prompt_info] )); then
+  RPS1+='$(virtualenv_prompt_info)'
+fi
+RPS1+=" ${FG[237]}%n@%m%{$reset_color%}"
 
 # git settings
-ZSH_THEME_GIT_PROMPT_PREFIX="$FG[075]($FG[078]"
+ZSH_THEME_GIT_PROMPT_PREFIX="${FG[075]}(${FG[078]}"
 ZSH_THEME_GIT_PROMPT_CLEAN=""
-ZSH_THEME_GIT_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
-ZSH_THEME_GIT_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"
+ZSH_THEME_GIT_PROMPT_DIRTY="${FG[214]}*%{$reset_color%}"
+ZSH_THEME_GIT_PROMPT_SUFFIX="${FG[075]})%{$reset_color%}"
 
 # hg settings
-ZSH_THEME_HG_PROMPT_PREFIX="$FG[075]($FG[078]"
+ZSH_THEME_HG_PROMPT_PREFIX="${FG[075]}(${FG[078]}"
 ZSH_THEME_HG_PROMPT_CLEAN=""
-ZSH_THEME_HG_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
-ZSH_THEME_HG_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"
+ZSH_THEME_HG_PROMPT_DIRTY="${FG[214]}*%{$reset_color%}"
+ZSH_THEME_HG_PROMPT_SUFFIX="${FG[075]})%{$reset_color%}"
 
 # virtualenv settings
-ZSH_THEME_VIRTUALENV_PREFIX=" $FG[075]["
+ZSH_THEME_VIRTUALENV_PREFIX=" ${FG[075]}["
 ZSH_THEME_VIRTUALENV_SUFFIX="]%{$reset_color%}"