Browse Source

[zsh] Add workarounds to make 'sudo zsh' usable

Emmanuel Bouthenot 2 years ago
parent
commit
380c8be2d1
1 changed files with 17 additions and 0 deletions
  1. 17 0
      .zshrc

+ 17 - 0
.zshrc

@@ -6,6 +6,17 @@
 #  but WITHOUT ANY WARRANTY
 #
 
+### Workaround for https://github.com/zplug/zplug/issues/397
+COMPINIT_ARGS=
+if [ "${UID}" = 0 ] && [ -n "${SUDO_UID}" ] ; then
+    if ! grep -q COMPINIT_ARGS ~/.zplug/base/core/load.zsh ; then
+        sed -i -r 's/^(\s+)compinit -d/\1compinit $COMPINIT_ARGS -d/' ~/.zplug/base/core/load.zsh
+    fi
+    COMPINIT_ARGS="-u"
+fi
+export COMPINIT_ARGS
+###
+
 source ~/.zplug/init.zsh
 
 export ZSHDOTDIR=~/.zsh
@@ -37,3 +48,9 @@ if ! zplug check --verbose; then
 fi
 
 zplug load
+
+# Fixing zplug permissions while using 'sudo zsh'
+if [ "${UID}" = 0 ] && [ -n "${SUDO_UID}" ] ; then
+    find ~/.zplug/ -not -user "${SUDO_UID}" -exec chown -R "${SUDO_UID}:${SUDO_GID}" {} \;
+fi
+