02d07f3e3dba0d50b1d907a8062bbaca18f88478

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

Message

fix: use `$USERNAME` guaranteed to always be defined in zsh

Fixes #9701

Diff

  1diff --git a/lib/completion.zsh b/lib/completion.zsh
  2index 2b62785d50e798d4a6e7b25d6e954bafbb65a7a3..ebaab08564c47d87575ca1c71bdadfe0c13b15ec 100644
  3--- a/lib/completion.zsh
  4+++ b/lib/completion.zsh
  5@@ -32,9 +32,9 @@ zstyle ':completion:*' list-colors ''
  6 zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
  7 
  8 if [[ "$OSTYPE" = solaris* ]]; then
  9-  zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm"
 10+  zstyle ':completion:*:*:*:*:processes' command "ps -u $USERNAME -o pid,user,comm"
 11 else
 12-  zstyle ':completion:*:*:*:*:processes' command "ps -u $USER -o pid,user,comm -w -w"
 13+  zstyle ':completion:*:*:*:*:processes' command "ps -u $USERNAME -o pid,user,comm -w -w"
 14 fi
 15 
 16 # disable named-directories autocompletion
 17diff --git a/lib/diagnostics.zsh b/lib/diagnostics.zsh
 18index 001de42b7ab5ef9d1a5c0b9528b4f35c9d6f4913..650520797bed1bf1d0d0182b9d9c6ac9cc8cd2d5 100644
 19--- a/lib/diagnostics.zsh
 20+++ b/lib/diagnostics.zsh
 21@@ -112,7 +112,7 @@ function _omz_diag_dump_one_big_text() {
 22   command uname -a
 23   builtin echo OSTYPE=$OSTYPE
 24   builtin echo ZSH_VERSION=$ZSH_VERSION
 25-  builtin echo User: $USER
 26+  builtin echo User: $USERNAME
 27   builtin echo umask: $(umask)
 28   builtin echo
 29   _omz_diag_dump_os_specific_version
 30diff --git a/plugins/emacs/emacsclient.sh b/plugins/emacs/emacsclient.sh
 31index 0aa8d6f40896475fd9c3e3386bbec0c1ed0de949..04a2c2afd518a87281dec087c97a4a1ab1306038 100755
 32--- a/plugins/emacs/emacsclient.sh
 33+++ b/plugins/emacs/emacsclient.sh
 34@@ -20,8 +20,8 @@ _emacsfun()
 35 # tempfile. (first argument will be `--no-wait` passed in by the plugin.zsh)
 36 if [ "$#" -ge "2" -a "$2" = "-" ]
 37 then
 38-    tempfile="$(mktemp --tmpdir emacs-stdin-$USER.XXXXXXX 2>/dev/null \
 39-                || mktemp -t emacs-stdin-$USER)" # support BSD mktemp
 40+    tempfile="$(mktemp --tmpdir emacs-stdin-$USERNAME.XXXXXXX 2>/dev/null \
 41+                || mktemp -t emacs-stdin-$USERNAME)" # support BSD mktemp
 42     cat - > "$tempfile"
 43     _emacsfun --no-wait $tempfile
 44 else
 45diff --git a/plugins/screen/screen.plugin.zsh b/plugins/screen/screen.plugin.zsh
 46index 7009e7a91bcdf1294353af7e9394b2ef97feedeb..c1db8ad928811f2bcdcc0daa6d9935e66a7174fd 100644
 47--- a/plugins/screen/screen.plugin.zsh
 48+++ b/plugins/screen/screen.plugin.zsh
 49@@ -2,7 +2,7 @@
 50 # of the tab window should be.
 51 if [[ "$TERM" == screen* ]]; then
 52   if [[ $_GET_PATH == '' ]]; then
 53-    _GET_PATH='echo $PWD | sed "s/^\/Users\//~/;s/^\/home\//~/;s/^~$USER/~/"'
 54+    _GET_PATH='echo $PWD | sed "s/^\/Users\//~/;s/^\/home\//~/;s/^~$USERNAME/~/"'
 55   fi
 56   if [[ $_GET_HOST == '' ]]; then
 57     _GET_HOST='echo $HOST | sed "s/\..*//"'
 58@@ -51,4 +51,4 @@ if [[ "$TERM" == screen* ]]; then
 59     eval "tab_hardstatus=$TAB_HARDSTATUS_PREFIX:$TAB_HARDSTATUS_PROMPT"
 60     screen_set $tab_title $tab_hardstatus
 61   }
 62-fi
 63+fi
 64diff --git a/plugins/ssh-agent/ssh-agent.plugin.zsh b/plugins/ssh-agent/ssh-agent.plugin.zsh
 65index 430647135d805a90fd3102ba15c5facea33c8897..d45406f63837dfc7adc770e73855df4aa436e3da 100644
 66--- a/plugins/ssh-agent/ssh-agent.plugin.zsh
 67+++ b/plugins/ssh-agent/ssh-agent.plugin.zsh
 68@@ -61,11 +61,11 @@ zstyle -b :omz:plugins:ssh-agent agent-forwarding _agent_forwarding
 69 
 70 if [[ $_agent_forwarding == "yes" && -n "$SSH_AUTH_SOCK" ]]; then
 71 	# Add a nifty symlink for screen/tmux if agent forwarding
 72-	[[ -L $SSH_AUTH_SOCK ]] || ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USER-screen
 73+	[[ -L $SSH_AUTH_SOCK ]] || ln -sf "$SSH_AUTH_SOCK" /tmp/ssh-agent-$USERNAME-screen
 74 elif [[ -f "$_ssh_env_cache" ]]; then
 75 	# Source SSH settings, if applicable
 76 	. $_ssh_env_cache > /dev/null
 77-	if [[ $USER == "root" ]]; then
 78+	if [[ $USERNAME == "root" ]]; then
 79 		FILTER="ax"
 80 	else
 81 		FILTER="x"
 82diff --git a/plugins/systemadmin/README.md b/plugins/systemadmin/README.md
 83index 243db03f2e8cf786c9620850bcbb5d88d316bb91..052fc6edc131e65099435994431d351b44332af5 100644
 84--- a/plugins/systemadmin/README.md
 85+++ b/plugins/systemadmin/README.md
 86@@ -10,17 +10,17 @@ plugins=(... systemadmin)
 87 
 88 ## Aliases
 89 
 90-| Alias   | Command                                                                | Description                                                        |
 91-|---------|------------------------------------------------------------------------|--------------------------------------------------------------------|
 92-| ping    | `ping -c 5`                                                            | Sends only 5 ICMP Messages                                         |
 93-| clr     | `clear; echo Currently logged in on $TTY, as $USER in directory $PWD.` | Clears the screen and prints the current user, TTY, and directory  |
 94-| path    | `print -l $path`                                                       | Displays PATH with each entry on a separate line                   |
 95-| mkdir   | `mkdir -pv`                                                            | Automatically create parent directories and display verbose output |
 96-| psmem   | `ps -e -orss=,args= \| sort -b -k1 -nr`                                | Display the processes using the most memory                        |
 97-| psmem10 | `ps -e -orss=,args= \| sort -b -k1 -nr \| head -10`                    | Display the top 10 processes using the most memory                 |
 98-| pscpu   | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr`             | Display the top processes using the most CPU                       |
 99-| pscpu10 | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr \| head -10` | Display the top 10 processes using the most CPU                    |
100-| hist10  | `print -l ${(o)history%% *} \| uniq -c \| sort -nr \| head -n 10`      | Display the top 10 most used commands in the history               |
101+| Alias   | Command                                                                    | Description                                                        |
102+|---------|----------------------------------------------------------------------------|--------------------------------------------------------------------|
103+| ping    | `ping -c 5`                                                                | Sends only 5 ICMP Messages                                         |
104+| clr     | `clear; echo Currently logged in on $TTY, as $USERNAME in directory $PWD.` | Clears the screen and prints the current user, TTY, and directory  |
105+| path    | `print -l $path`                                                           | Displays PATH with each entry on a separate line                   |
106+| mkdir   | `mkdir -pv`                                                                | Automatically create parent directories and display verbose output |
107+| psmem   | `ps -e -orss=,args= \| sort -b -k1 -nr`                                    | Display the processes using the most memory                        |
108+| psmem10 | `ps -e -orss=,args= \| sort -b -k1 -nr \| head -10`                        | Display the top 10 processes using the most memory                 |
109+| pscpu   | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr`                 | Display the top processes using the most CPU                       |
110+| pscpu10 | `ps -e -o pcpu,cpu,nice,state,cputime,args \|sort -k1 -nr \| head -10`     | Display the top 10 processes using the most CPU                    |
111+| hist10  | `print -l ${(o)history%% *} \| uniq -c \| sort -nr \| head -n 10`          | Display the top 10 most used commands in the history               |
112 
113 ## Functions
114 
115diff --git a/plugins/systemadmin/systemadmin.plugin.zsh b/plugins/systemadmin/systemadmin.plugin.zsh
116index 03064c0350a3d45605604949c381b126170004d9..08136abda19565ec005136efbcf9a2a2fdb7cdbd 100644
117--- a/plugins/systemadmin/systemadmin.plugin.zsh
118+++ b/plugins/systemadmin/systemadmin.plugin.zsh
119@@ -21,7 +21,7 @@ function retlog() {
120 }
121 
122 alias ping='ping -c 5'
123-alias clr='clear; echo Currently logged in on $TTY, as $USER in directory $PWD.'
124+alias clr='clear; echo Currently logged in on $TTY, as $USERNAME in directory $PWD.'
125 alias path='print -l $path'
126 alias mkdir='mkdir -pv'
127 # get top process eating memory
128diff --git a/themes/adben.zsh-theme b/themes/adben.zsh-theme
129index b9ac77d007c8817bf0266592fa4d96b6f92cddab..7321df72434c372d39bb1f97434b202ca32f2ef2 100644
130--- a/themes/adben.zsh-theme
131+++ b/themes/adben.zsh-theme
132@@ -89,8 +89,8 @@ function precmd {
133 
134 # Context: user@directory or just directory
135 prompt_context () {
136-    if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
137-        echo -n "${PR_RESET}${PR_RED}$USER@%m${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
138+    if [[ "$USERNAME" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
139+        echo -n "${PR_RESET}${PR_RED}$USERNAME@%m${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
140     else
141         echo -n "${PR_RESET}${PR_BRIGHT_YELLOW}%~%<<${PR_RESET}"
142     fi
143diff --git a/themes/agnoster.zsh-theme b/themes/agnoster.zsh-theme
144index 99707f684825cd8e4b591183ff7a500fa07a513e..fe7ddbac639e24a645e32791af8cc1ba310f266f 100644
145--- a/themes/agnoster.zsh-theme
146+++ b/themes/agnoster.zsh-theme
147@@ -88,7 +88,7 @@ prompt_end() {
148 
149 # Context: user@hostname (who am I and where am I)
150 prompt_context() {
151-  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
152+  if [[ "$USERNAME" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
153     prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"
154   fi
155 }
156diff --git a/themes/avit.zsh-theme b/themes/avit.zsh-theme
157index 921ed99d3d1a5239232716562c16d00b431bca0c..1e20d8f9fd8b02daf9f637f61d0d0c4865acc480 100644
158--- a/themes/avit.zsh-theme
159+++ b/themes/avit.zsh-theme
160@@ -17,7 +17,7 @@ function _user_host() {
161   local me
162   if [[ -n $SSH_CONNECTION ]]; then
163     me="%n@%m"
164-  elif [[ $LOGNAME != $USER ]]; then
165+  elif [[ $LOGNAME != $USERNAME ]]; then
166     me="%n"
167   fi
168   if [[ -n $me ]]; then
169diff --git a/themes/flazz.zsh-theme b/themes/flazz.zsh-theme
170index c0a7fb5d0a9824cb17374cd90ee22262198803e9..e21b52ef5e9eec35a8acf5ecc2d158f2216d4e23 100644
171--- a/themes/flazz.zsh-theme
172+++ b/themes/flazz.zsh-theme
173@@ -1,4 +1,4 @@
174-if [ "$USER" = "root" ]
175+if [ "$USERNAME" = "root" ]
176 then CARETCOLOR="red"
177 else CARETCOLOR="blue"
178 fi
179diff --git a/themes/obraun.zsh-theme b/themes/obraun.zsh-theme
180index 7af44056f606654d564f839f36d14f8e60ed01b6..cc2769e4bf7a9887483869c31e15a7a8a8c800db 100644
181--- a/themes/obraun.zsh-theme
182+++ b/themes/obraun.zsh-theme
183@@ -1,4 +1,4 @@
184-if [ "$USER" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="blue"; fi
185+if [ "$USERNAME" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="blue"; fi
186 
187 local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
188 
189diff --git a/themes/re5et.zsh-theme b/themes/re5et.zsh-theme
190index 95af1e2ee3bf110fe16e03555526b12067fe4dd3..bdf342f491b43abc0169444c23b75a876bea7d5d 100644
191--- a/themes/re5et.zsh-theme
192+++ b/themes/re5et.zsh-theme
193@@ -1,4 +1,4 @@
194-if [ "$USER" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="magenta"; fi
195+if [ "$USERNAME" = "root" ]; then CARETCOLOR="red"; else CARETCOLOR="magenta"; fi
196 
197 local return_code="%(?..%{$fg_bold[red]%}:( %?%{$reset_color%})"
198 
199diff --git a/themes/sunrise.zsh-theme b/themes/sunrise.zsh-theme
200index 2111576c3bfb33f91c9984d3ed2b6fb2693a6fa2..11f6af127a84d1892b6d4d32534b1f419ee38be8 100644
201--- a/themes/sunrise.zsh-theme
202+++ b/themes/sunrise.zsh-theme
203@@ -9,7 +9,7 @@ Y=$fg_no_bold[yellow]
204 B=$fg_no_bold[blue]
205 RESET=$reset_color
206 
207-if [ "$USER" = "root" ]; then
208+if [ "$USERNAME" = "root" ]; then
209     PROMPTCOLOR="%{$R%}" PROMPTPREFIX="-!-";
210 else
211     PROMPTCOLOR="" PROMPTPREFIX="---";
212diff --git a/tools/install.sh b/tools/install.sh
213index d4ecb7afed2be061b85c907f25e824aace9fff13..cfc2808fe93b5dd3f3f6fd89947bc875d1e74f8d 100755
214--- a/tools/install.sh
215+++ b/tools/install.sh
216@@ -227,7 +227,7 @@ EOF
217   if [ -n "$SHELL" ]; then
218     echo "$SHELL" > ~/.shell.pre-oh-my-zsh
219   else
220-    grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
221+    grep "^$USERNAME:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
222   fi
223 
224   # Actually change the default shell to zsh