From 74177c5320b2a1b2f8c4c695c05984b57fd7c6ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 9 Oct 2014 13:44:54 +0200 Subject: [PATCH 1/3] Change all whoami calls for $USER variable This avoid spawning additional processes, as the $USER variable will **always** contain the current logged-in user. --- lib/completion.zsh | 4 ++-- plugins/systemadmin/systemadmin.plugin.zsh | 2 +- themes/adben.zsh-theme | 5 ++--- themes/agnoster.zsh-theme | 6 ++---- themes/flazz.zsh-theme | 2 +- themes/obraun.zsh-theme | 2 +- themes/re5et.zsh-theme | 2 +- themes/sunrise.zsh-theme | 2 +- themes/ys.zsh-theme | 2 +- 9 files changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/completion.zsh b/lib/completion.zsh index 83b6efb6..3a19a4eb 100644 --- a/lib/completion.zsh +++ b/lib/completion.zsh @@ -27,9 +27,9 @@ zstyle ':completion:*:*:*:*:*' menu select zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01' if [ "$OSTYPE[0,7]" = "solaris" ] then - zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm" + zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm" else - zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w" + zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w" fi # disable named-directories autocompletion diff --git a/plugins/systemadmin/systemadmin.plugin.zsh b/plugins/systemadmin/systemadmin.plugin.zsh index f5e44c66..e0b1773a 100644 --- a/plugins/systemadmin/systemadmin.plugin.zsh +++ b/plugins/systemadmin/systemadmin.plugin.zsh @@ -30,7 +30,7 @@ function retlog() { } alias ping='ping -c 5' -alias clr='clear;echo "Currently logged in on $(tty), as $(whoami) in directory $(pwd)."' +alias clr='clear;echo "Currently logged in on $(tty), as $USER in directory $(pwd)."' alias path='echo -e ${PATH//:/\\n}' alias mkdir='mkdir -pv' # get top process eating memory diff --git a/themes/adben.zsh-theme b/themes/adben.zsh-theme index aa3093f6..6869c8a2 100644 --- a/themes/adben.zsh-theme +++ b/themes/adben.zsh-theme @@ -89,9 +89,8 @@ function precmd { # Context: user@directory or just directory prompt_context () { - local user=`whoami` - if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then - echo -n "${PR_RESET}${PR_RED}$user@%m${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}" + if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then + echo -n "${PR_RESET}${PR_RED}$USER@%m${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}" else echo -n "${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}" fi diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme index 2b33c48b..7a62bd86 100644 --- a/themes/agnoster.zsh-theme +++ b/themes/agnoster.zsh-theme @@ -60,10 +60,8 @@ prompt_end() { # Context: user@hostname (who am I and where am I) prompt_context() { - local user=`whoami` - - if [[ "$user" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then - prompt_segment black default "%(!.%{%F{yellow}%}.)$user@%m" + if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then + prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@%m" fi } diff --git a/themes/flazz.zsh-theme b/themes/flazz.zsh-theme index 280794f2..c0a7fb5d 100644 --- a/themes/flazz.zsh-theme +++ b/themes/flazz.zsh-theme @@ -1,4 +1,4 @@ -if [ "$(whoami)" = "root" ] +if [ "$USER" = "root" ] then CARETCOLOR="red" else CARETCOLOR="blue" fi diff --git a/themes/obraun.zsh-theme b/themes/obraun.zsh-theme index 08d13766..7af44056 100644 --- a/themes/obraun.zsh-theme +++ b/themes/obraun.zsh-theme @@ -1,4 +1,4 @@ -if [ "$(whoami)" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="blue"; fi +if [ "$USER" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="blue"; fi local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" diff --git a/themes/re5et.zsh-theme b/themes/re5et.zsh-theme index 5bded76a..95af1e2e 100644 --- a/themes/re5et.zsh-theme +++ b/themes/re5et.zsh-theme @@ -1,4 +1,4 @@ -if [ "$(whoami)" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="magenta"; fi +if [ "$USER" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="magenta"; fi local return_code="%(?..%{$fg_bold[red]%}:( %?%{$reset_color%})" diff --git a/themes/sunrise.zsh-theme b/themes/sunrise.zsh-theme index 4bea20a1..28befd01 100644 --- a/themes/sunrise.zsh-theme +++ b/themes/sunrise.zsh-theme @@ -10,7 +10,7 @@ Y=$fg_no_bold[yellow] B=$fg_no_bold[blue] RESET=$reset_color -if [ "$(whoami)" = "root" ]; then +if [ "$USER" = "root" ]; then PROMPTCOLOR="%{$R%}" PREFIX="-!-"; else PROMPTCOLOR="" PREFIX="---"; diff --git a/themes/ys.zsh-theme b/themes/ys.zsh-theme index a44f295f..65448964 100644 --- a/themes/ys.zsh-theme +++ b/themes/ys.zsh-theme @@ -33,7 +33,7 @@ ${git_info} \ %{$fg[white]%}[%*] %{$terminfo[bold]$fg[red]%}$ %{$reset_color%}" -if [[ "$(whoami)" == "root" ]]; then +if [[ "$USER" == "root" ]]; then PROMPT=" %{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \ %{$bg[yellow]%}%{$fg[cyan]%}%n%{$reset_color%} \ From 4310a15de5d0587ef135f9e12857620c4788dec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 9 Oct 2014 13:55:50 +0200 Subject: [PATCH 2/3] Change all pwd calls for $PWD variable This avoids spawning additional processes as $PWD **always** contains the current working directory. --- plugins/dirhistory/dirhistory.plugin.zsh | 6 +++--- plugins/jump/jump.plugin.zsh | 6 +++--- plugins/pow/pow.plugin.zsh | 8 ++++---- plugins/svn/svn.plugin.zsh | 2 +- plugins/systemadmin/systemadmin.plugin.zsh | 2 +- plugins/vim-interaction/vim-interaction.plugin.zsh | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/plugins/dirhistory/dirhistory.plugin.zsh b/plugins/dirhistory/dirhistory.plugin.zsh index 504d7ec1..d101cfca 100644 --- a/plugins/dirhistory/dirhistory.plugin.zsh +++ b/plugins/dirhistory/dirhistory.plugin.zsh @@ -3,7 +3,7 @@ # that the user has changed to in the past, and ALT-RIGHT undoes ALT-LEFT. # -dirhistory_past=(`pwd`) +dirhistory_past=($PWD) dirhistory_future=() export dirhistory_past export dirhistory_future @@ -50,7 +50,7 @@ function push_future() { # Called by zsh when directory changes function chpwd() { - push_past `pwd` + push_past $PWD # If DIRHISTORY_CD is not set... if [[ -z "${DIRHISTORY_CD+x}" ]]; then # ... clear future. @@ -73,7 +73,7 @@ function dirhistory_back() { pop_past cw if [[ "" == "$cw" ]]; then # Someone overwrote our variable. Recover it. - dirhistory_past=(`pwd`) + dirhistory_past=($PWD) return fi diff --git a/plugins/jump/jump.plugin.zsh b/plugins/jump/jump.plugin.zsh index 1b23b5d4..b16814fe 100644 --- a/plugins/jump/jump.plugin.zsh +++ b/plugins/jump/jump.plugin.zsh @@ -14,12 +14,12 @@ jump() { mark() { if (( $# == 0 )); then - MARK=$(basename "$(pwd)") + MARK=$(basename "$PWD") else MARK="$1" fi - if read -q \?"Mark $(pwd) as ${MARK}? (y/n) "; then - mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$MARK" + if read -q \?"Mark $PWD as ${MARK}? (y/n) "; then + mkdir -p "$MARKPATH"; ln -s "$PWD" "$MARKPATH/$MARK" fi } diff --git a/plugins/pow/pow.plugin.zsh b/plugins/pow/pow.plugin.zsh index d85c8877..ded3336a 100644 --- a/plugins/pow/pow.plugin.zsh +++ b/plugins/pow/pow.plugin.zsh @@ -21,13 +21,13 @@ rack_root(){ setopt chaselinks - local orgdir="$(pwd)" - local basedir="$(pwd)" + local orgdir="$PWD" + local basedir="$PWD" while [[ $basedir != '/' ]]; do test -e "$basedir/config.ru" && break builtin cd ".." 2>/dev/null - basedir="$(pwd)" + basedir="$PWD" done builtin cd "$orgdir" 2>/dev/null @@ -56,7 +56,7 @@ kapow(){ compctl -W ~/.pow -/ kapow powit(){ - local basedir="$(pwd)" + local basedir="$PWD" local vhost=$1 [ ! -n "$vhost" ] && vhost=$(rack_root_detect) if [ ! -h ~/.pow/$vhost ] diff --git a/plugins/svn/svn.plugin.zsh b/plugins/svn/svn.plugin.zsh index ef6da5bd..ba281d79 100644 --- a/plugins/svn/svn.plugin.zsh +++ b/plugins/svn/svn.plugin.zsh @@ -77,7 +77,7 @@ function svn_dirty() { function svn_dirty_choose_pwd () { if in_svn; then - root=`pwd` + root=$PWD if $(svn status $root 2> /dev/null | grep -Eq '^\s*[ACDIM!?L]'); then # Grep exits with 0 when "One or more lines were selected", return "dirty". echo $1 diff --git a/plugins/systemadmin/systemadmin.plugin.zsh b/plugins/systemadmin/systemadmin.plugin.zsh index e0b1773a..4ae70dfa 100644 --- a/plugins/systemadmin/systemadmin.plugin.zsh +++ b/plugins/systemadmin/systemadmin.plugin.zsh @@ -30,7 +30,7 @@ function retlog() { } alias ping='ping -c 5' -alias clr='clear;echo "Currently logged in on $(tty), as $USER in directory $(pwd)."' +alias clr='clear;echo "Currently logged in on $(tty), as $USER in directory $PWD."' alias path='echo -e ${PATH//:/\\n}' alias mkdir='mkdir -pv' # get top process eating memory diff --git a/plugins/vim-interaction/vim-interaction.plugin.zsh b/plugins/vim-interaction/vim-interaction.plugin.zsh index 5142f1f9..b0b9414c 100644 --- a/plugins/vim-interaction/vim-interaction.plugin.zsh +++ b/plugins/vim-interaction/vim-interaction.plugin.zsh @@ -9,7 +9,7 @@ function resolveFile if [ -f "$1" ]; then echo $(readlink -f "$1") elif [[ "${1#/}" == "$1" ]]; then - echo "$(pwd)/$1" + echo "$PWD/$1" else echo $1 fi From 95d795e8cad7d1a754dfad520309d7a41b69275f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Thu, 9 Oct 2014 17:05:48 +0200 Subject: [PATCH 3/3] Change all hostname calls for $HOST or $SHORT_HOST --- plugins/profiles/profiles.plugin.zsh | 2 +- themes/candy-kingdom.zsh-theme | 2 +- themes/dieter.zsh-theme | 2 +- themes/fino-time.zsh-theme | 2 +- themes/fino.zsh-theme | 2 +- themes/kardan.zsh-theme | 2 +- themes/michelebologna.zsh-theme | 2 +- themes/ys.zsh-theme | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/profiles/profiles.plugin.zsh b/plugins/profiles/profiles.plugin.zsh index 8faae6b5..4b3d6a85 100644 --- a/plugins/profiles/profiles.plugin.zsh +++ b/plugins/profiles/profiles.plugin.zsh @@ -2,7 +2,7 @@ # This will look for a custom profile for the local machine and each domain or # subdomain it belongs to. (e.g. com, example.com and foo.example.com) -parts=(${(s:.:)$(hostname)}) +parts=(${(s:.:)$HOST}) for i in {${#parts}..1}; do profile=${(j:.:)${parts[$i,${#parts}]}} file=$ZSH_CUSTOM/profiles/$profile diff --git a/themes/candy-kingdom.zsh-theme b/themes/candy-kingdom.zsh-theme index 718977d9..88912875 100644 --- a/themes/candy-kingdom.zsh-theme +++ b/themes/candy-kingdom.zsh-theme @@ -13,7 +13,7 @@ patches: