4ed6fd2b8b6a0efb2f84f00a64503282aca260e7

Author
Florian Klink <flokli@flokli.de>
Committer
GitHub <noreply@github.com>
Date

Message

pygmalion: use pure zsh instead of perl (#9210)

My system doesn't have `perl` in $PATH, so using this theme clutters the
shell output quite a bit.

Turns out, the same thing can be accomplished in pure zsh (with
extendedglob).

Co-Authored-By: Marc Cornellà <marc.cornella@live.com>

Diff

 1diff --git a/themes/pygmalion-virtualenv.zsh-theme b/themes/pygmalion-virtualenv.zsh-theme
 2index 605e3d10ceed956b244ac02e10261a62f3cd5783..47b0b4fb14a82174236a4c5813bc2aaeaf011881 100644
 3--- a/themes/pygmalion-virtualenv.zsh-theme
 4+++ b/themes/pygmalion-virtualenv.zsh-theme
 5@@ -17,6 +17,8 @@ function _virtualenv_prompt_info {
 6 }
 7 
 8 prompt_setup_pygmalion(){
 9+  setopt localoptions extendedglob
10+
11   ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}"
12   ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
13   ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}"
14@@ -25,16 +27,18 @@ prompt_setup_pygmalion(){
15   base_prompt='$(_virtualenv_prompt_info)%{$fg[magenta]%}%n%{$reset_color%}%{$fg[cyan]%}@%{$reset_color%}%{$fg[yellow]%}%m%{$reset_color%}%{$fg[red]%}:%{$reset_color%}%{$fg[cyan]%}%0~%{$reset_color%}%{$fg[red]%}|%{$reset_color%}'
16   post_prompt='%{$fg[cyan]%}⇒%{$reset_color%}  '
17 
18-  base_prompt_nocolor=$(echo "$base_prompt" | perl -pe "s/%\{[^}]+\}//g")
19-  post_prompt_nocolor=$(echo "$post_prompt" | perl -pe "s/%\{[^}]+\}//g")
20+  base_prompt_nocolor=${base_prompt//\%\{[^\}]##\}}
21+  post_prompt_nocolor=${post_prompt//\%\{[^\}]##\}}
22 
23   autoload -U add-zsh-hook
24   add-zsh-hook precmd prompt_pygmalion_precmd
25 }
26 
27 prompt_pygmalion_precmd(){
28+  setopt localoptions extendedglob
29+
30   local gitinfo=$(git_prompt_info)
31-  local gitinfo_nocolor=$(echo "$gitinfo" | perl -pe "s/%\{[^}]+\}//g")
32+  local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}}
33   local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")"
34   local prompt_length=${#exp_nocolor}
35 
36diff --git a/themes/pygmalion.zsh-theme b/themes/pygmalion.zsh-theme
37index bd58db5f6d23651b03c8d1aa06e1ff933db8ed2c..b13adfd5fb79d39cfb3c389be7dae68b9df5eb4d 100644
38--- a/themes/pygmalion.zsh-theme
39+++ b/themes/pygmalion.zsh-theme
40@@ -1,6 +1,8 @@
41 # Yay! High voltage and arrows!
42 
43 prompt_setup_pygmalion(){
44+  setopt localoptions extendedglob
45+
46   ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}"
47   ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
48   ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}"
49@@ -9,16 +11,18 @@ prompt_setup_pygmalion(){
50   base_prompt='%{$fg[magenta]%}%n%{$reset_color%}%{$fg[cyan]%}@%{$reset_color%}%{$fg[yellow]%}%m%{$reset_color%}%{$fg[red]%}:%{$reset_color%}%{$fg[cyan]%}%0~%{$reset_color%}%{$fg[red]%}|%{$reset_color%}'
51   post_prompt='%{$fg[cyan]%}⇒%{$reset_color%}  '
52 
53-  base_prompt_nocolor=$(echo "$base_prompt" | perl -pe "s/%\{[^}]+\}//g")
54-  post_prompt_nocolor=$(echo "$post_prompt" | perl -pe "s/%\{[^}]+\}//g")
55+  base_prompt_nocolor=${base_prompt//\%\{[^\}]##\}}
56+  post_prompt_nocolor=${post_prompt//\%\{[^\}]##\}}
57 
58   autoload -U add-zsh-hook
59   add-zsh-hook precmd prompt_pygmalion_precmd
60 }
61 
62 prompt_pygmalion_precmd(){
63+  setopt localoptions extendedglob
64+
65   local gitinfo=$(git_prompt_info)
66-  local gitinfo_nocolor=$(echo "$gitinfo" | perl -pe "s/%\{[^}]+\}//g")
67+  local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}}
68   local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")"
69   local prompt_length=${#exp_nocolor}
70