From 4ed6fd2b8b6a0efb2f84f00a64503282aca260e7 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 29 Aug 2020 00:27:06 +0200 Subject: pygmalion: use pure zsh instead of perl (#9210) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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à --- themes/pygmalion-virtualenv.zsh-theme | 10 +++++++--- themes/pygmalion.zsh-theme | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'themes') diff --git a/themes/pygmalion-virtualenv.zsh-theme b/themes/pygmalion-virtualenv.zsh-theme index 605e3d10c..47b0b4fb1 100644 --- a/themes/pygmalion-virtualenv.zsh-theme +++ b/themes/pygmalion-virtualenv.zsh-theme @@ -17,6 +17,8 @@ function _virtualenv_prompt_info { } prompt_setup_pygmalion(){ + setopt localoptions extendedglob + ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}" @@ -25,16 +27,18 @@ prompt_setup_pygmalion(){ 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%}' post_prompt='%{$fg[cyan]%}⇒%{$reset_color%} ' - base_prompt_nocolor=$(echo "$base_prompt" | perl -pe "s/%\{[^}]+\}//g") - post_prompt_nocolor=$(echo "$post_prompt" | perl -pe "s/%\{[^}]+\}//g") + base_prompt_nocolor=${base_prompt//\%\{[^\}]##\}} + post_prompt_nocolor=${post_prompt//\%\{[^\}]##\}} autoload -U add-zsh-hook add-zsh-hook precmd prompt_pygmalion_precmd } prompt_pygmalion_precmd(){ + setopt localoptions extendedglob + local gitinfo=$(git_prompt_info) - local gitinfo_nocolor=$(echo "$gitinfo" | perl -pe "s/%\{[^}]+\}//g") + local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}} local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")" local prompt_length=${#exp_nocolor} diff --git a/themes/pygmalion.zsh-theme b/themes/pygmalion.zsh-theme index bd58db5f6..b13adfd5f 100644 --- a/themes/pygmalion.zsh-theme +++ b/themes/pygmalion.zsh-theme @@ -1,6 +1,8 @@ # Yay! High voltage and arrows! prompt_setup_pygmalion(){ + setopt localoptions extendedglob + ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[yellow]%}⚡%{$reset_color%}" @@ -9,16 +11,18 @@ prompt_setup_pygmalion(){ 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%}' post_prompt='%{$fg[cyan]%}⇒%{$reset_color%} ' - base_prompt_nocolor=$(echo "$base_prompt" | perl -pe "s/%\{[^}]+\}//g") - post_prompt_nocolor=$(echo "$post_prompt" | perl -pe "s/%\{[^}]+\}//g") + base_prompt_nocolor=${base_prompt//\%\{[^\}]##\}} + post_prompt_nocolor=${post_prompt//\%\{[^\}]##\}} autoload -U add-zsh-hook add-zsh-hook precmd prompt_pygmalion_precmd } prompt_pygmalion_precmd(){ + setopt localoptions extendedglob + local gitinfo=$(git_prompt_info) - local gitinfo_nocolor=$(echo "$gitinfo" | perl -pe "s/%\{[^}]+\}//g") + local gitinfo_nocolor=${gitinfo//\%\{[^\}]##\}} local exp_nocolor="$(print -P \"$base_prompt_nocolor$gitinfo_nocolor$post_prompt_nocolor\")" local prompt_length=${#exp_nocolor} -- cgit v1.2.3-70-g09d2 From a7f5170d68c0b75a9864763a90ac11e51ec67c81 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Mon, 31 Aug 2020 17:38:30 +0200 Subject: Remove perl dependency --- plugins/timer/timer.plugin.zsh | 5 ++++- themes/fishy.zsh-theme | 15 +++++++++------ themes/trapd00r.zsh-theme | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'themes') diff --git a/plugins/timer/timer.plugin.zsh b/plugins/timer/timer.plugin.zsh index 1be7516a3..b261f71c5 100644 --- a/plugins/timer/timer.plugin.zsh +++ b/plugins/timer/timer.plugin.zsh @@ -1,5 +1,8 @@ +zmodload zsh/datetime + __timer_current_time() { - perl -MTime::HiRes=time -e'print time' + zmodload zsh/datetime + echo $EPOCHREALTIME } __timer_format_duration() { diff --git a/themes/fishy.zsh-theme b/themes/fishy.zsh-theme index 00a60f45b..f6dae6181 100644 --- a/themes/fishy.zsh-theme +++ b/themes/fishy.zsh-theme @@ -1,12 +1,15 @@ # ZSH Theme emulating the Fish shell's default prompt. _fishy_collapsed_wd() { - echo $(pwd | perl -pe ' - BEGIN { - binmode STDIN, ":encoding(UTF-8)"; - binmode STDOUT, ":encoding(UTF-8)"; - }; s|^$ENV{HOME}|~|g; s|/([^/.])[^/]*(?=/)|/$1|g; s|/\.([^/])[^/]*(?=/)|/.$1|g -') + local -a pwd=("${(s:/:)PWD/#$HOME/~}") + for i in {1..$(($#pwd-1))}; do + if [[ "$pwd[$i]" = .* ]]; then + pwd[$i]="${${pwd[$i]}[1,2]}" + else + pwd[$i]="${${pwd[$i]}[1]}" + fi + done + echo "${(j:/:)pwd}" } local user_color='green'; [ $UID -eq 0 ] && user_color='red' diff --git a/themes/trapd00r.zsh-theme b/themes/trapd00r.zsh-theme index 7a589a699..4e3238393 100644 --- a/themes/trapd00r.zsh-theme +++ b/themes/trapd00r.zsh-theme @@ -2,7 +2,7 @@ # # This theme needs a terminal supporting 256 colors as well as unicode. # In order to avoid external dependencies, it also has a zsh version of -# the perl script at https://github.com/trapd00r/utils/blob/master/zsh_path, +# the previously used perl script https://github.com/trapd00r/utils/blob/master/zsh_path, # which splits up the current path and makes it fancy. # # By default it spans over two lines like so: -- cgit v1.2.3-70-g09d2 From 7256c03ce1c54bd08ecab954c91a0231386556a6 Mon Sep 17 00:00:00 2001 From: Marc Cornellà Date: Wed, 2 Sep 2020 15:15:24 +0200 Subject: fishy: fix one-level directory bug and bad array assignment in zsh 5.0.1 --- themes/fishy.zsh-theme | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'themes') diff --git a/themes/fishy.zsh-theme b/themes/fishy.zsh-theme index f6dae6181..2b8d559e5 100644 --- a/themes/fishy.zsh-theme +++ b/themes/fishy.zsh-theme @@ -1,14 +1,17 @@ # ZSH Theme emulating the Fish shell's default prompt. _fishy_collapsed_wd() { - local -a pwd=("${(s:/:)PWD/#$HOME/~}") - for i in {1..$(($#pwd-1))}; do - if [[ "$pwd[$i]" = .* ]]; then - pwd[$i]="${${pwd[$i]}[1,2]}" - else - pwd[$i]="${${pwd[$i]}[1]}" - fi - done + local i pwd + pwd=("${(s:/:)PWD/#$HOME/~}") + if (( $#pwd > 1 )); then + for i in {1..$(($#pwd-1))}; do + if [[ "$pwd[$i]" = .* ]]; then + pwd[$i]="${${pwd[$i]}[1,2]}" + else + pwd[$i]="${${pwd[$i]}[1]}" + fi + done + fi echo "${(j:/:)pwd}" } -- cgit v1.2.3-70-g09d2