c172624398918577bcb212d07b0036f4058cb5c6

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

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

Diff

 1diff --git a/themes/af-magic.zsh-theme b/themes/af-magic.zsh-theme
 2index 1d2af34584c688abc449374ea16b9ee4518003e6..d939d546f9cb67cdd82b366464d18963d03923f4 100644
 3--- a/themes/af-magic.zsh-theme
 4+++ b/themes/af-magic.zsh-theme
 5@@ -1,47 +1,46 @@
 6 # af-magic.zsh-theme
 7-# Repo: https://github.com/andyfleming/oh-my-zsh
 8-# Direct Link: https://github.com/andyfleming/oh-my-zsh/blob/master/themes/af-magic.zsh-theme
 9+#
10+# Author: Andy Fleming
11+# URL: http://andyfleming.com/
12 
13-
14-# settings
15-typeset +H return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
16-typeset +H my_gray="$FG[237]"
17-typeset +H my_orange="$FG[214]"
18-
19-# separator dashes size
20+# dashed separator size
21 function afmagic_dashes {
22-	local PYTHON_ENV="$VIRTUAL_ENV"
23-	[[ -z "$PYTHON_ENV" ]] && PYTHON_ENV="$CONDA_DEFAULT_ENV"
24-
25-	if [[ -n "$PYTHON_ENV" && "$PS1" = \(* ]]; then
26-		echo $(( COLUMNS - ${#PYTHON_ENV} - 3 ))
27-	else
28-		echo $COLUMNS
29-	fi
30+  # check either virtualenv or condaenv variables
31+  local python_env="${VIRTUAL_ENV:-$CONDA_DEFAULT_ENV}"
32+
33+  # if there is a python virtual environment and it is displayed in
34+  # the prompt, account for it when returning the number of dashes
35+  if [[ -n "$python_env" && "$PS1" = \(* ]]; then
36+    echo $(( COLUMNS - ${#python_env} - 3 ))
37+  else
38+    echo $COLUMNS
39+  fi
40 }
41 
42-# primary prompt
43-PS1='$FG[237]${(l.$(afmagic_dashes)..-.)}%{$reset_color%}
44-$FG[032]%~$(git_prompt_info)$(hg_prompt_info) $FG[105]%(!.#.»)%{$reset_color%} '
45-PS2='%{$fg[red]%}\ %{$reset_color%}'
46-RPS1='${return_code}'
47+# primary prompt: dashed separator, directory and vcs info
48+PS1="${FG[237]}\${(l.\$(afmagic_dashes)..-.)}%{$reset_color%}
49+${FG[032]}%~\$(git_prompt_info)\$(hg_prompt_info) ${FG[105]}%(!.#.»)%{$reset_color%} "
50+PS2="%{$fg[red]%}\ %{$reset_color%}"
51 
52-# right prompt
53-(( $+functions[virtualenv_prompt_info] )) && RPS1+='$(virtualenv_prompt_info)'
54-RPS1+=' $my_gray%n@%m%{$reset_color%}%'
55+# right prompt: return code, virtualenv and context (user@host)
56+RPS1="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
57+if (( $+functions[virtualenv_prompt_info] )); then
58+  RPS1+='$(virtualenv_prompt_info)'
59+fi
60+RPS1+=" ${FG[237]}%n@%m%{$reset_color%}"
61 
62 # git settings
63-ZSH_THEME_GIT_PROMPT_PREFIX="$FG[075]($FG[078]"
64+ZSH_THEME_GIT_PROMPT_PREFIX="${FG[075]}(${FG[078]}"
65 ZSH_THEME_GIT_PROMPT_CLEAN=""
66-ZSH_THEME_GIT_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
67-ZSH_THEME_GIT_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"
68+ZSH_THEME_GIT_PROMPT_DIRTY="${FG[214]}*%{$reset_color%}"
69+ZSH_THEME_GIT_PROMPT_SUFFIX="${FG[075]})%{$reset_color%}"
70 
71 # hg settings
72-ZSH_THEME_HG_PROMPT_PREFIX="$FG[075]($FG[078]"
73+ZSH_THEME_HG_PROMPT_PREFIX="${FG[075]}(${FG[078]}"
74 ZSH_THEME_HG_PROMPT_CLEAN=""
75-ZSH_THEME_HG_PROMPT_DIRTY="$my_orange*%{$reset_color%}"
76-ZSH_THEME_HG_PROMPT_SUFFIX="$FG[075])%{$reset_color%}"
77+ZSH_THEME_HG_PROMPT_DIRTY="${FG[214]}*%{$reset_color%}"
78+ZSH_THEME_HG_PROMPT_SUFFIX="${FG[075]})%{$reset_color%}"
79 
80 # virtualenv settings
81-ZSH_THEME_VIRTUALENV_PREFIX=" $FG[075]["
82+ZSH_THEME_VIRTUALENV_PREFIX=" ${FG[075]}["
83 ZSH_THEME_VIRTUALENV_SUFFIX="]%{$reset_color%}"