]> git.draconx.ca Git - zshconf.git/commitdiff
Add functions for manipulating PATH, and use them to set the default.
authorNick Bowler <nbowler@elliptictech.com>
Wed, 23 Sep 2009 14:36:17 +0000 (10:36 -0400)
committerNick Bowler <nbowler@elliptictech.com>
Wed, 23 Sep 2009 14:36:17 +0000 (10:36 -0400)
zprofile
zshenv [new file with mode: 0644]

index 2a4978d9bc591a49cfc67bb8430263d517e0b516..dba3a21854ea7b43fe821c9e51126b9570d66d10 100644 (file)
--- a/zprofile
+++ b/zprofile
@@ -15,21 +15,8 @@ export PAGER=${PAGER:-/usr/bin/less}
 # 077 would be more secure, but 022 is generally quite realistic
 umask 022
 
 # 077 would be more secure, but 022 is generally quite realistic
 umask 022
 
-# Set up PATH depending on whether we're root or a normal user.
-# There's no real reason to exclude sbin paths from the normal user,
-# but it can make tab-completion easier when they aren't in the
-# user's PATH to pollute the executable namespace.
-#
-# It is intentional in the following line to use || instead of -o.
-# This way the evaluation can be short-circuited and calling whoami is
-# avoided.
-if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
-       PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}"
-else
-       PATH="/usr/local/bin:/usr/bin:/bin:${PATH}"
-fi
-export PATH="$HOME/bin:$PATH"
-unset ROOTPATH
+# Setup the default path.
+path_front /{bin,sbin} /usr/{bin,sbin} /usr/local/{bin,sbin} $HOME/bin
 
 shopts=$-
 setopt nullglob
 
 shopts=$-
 setopt nullglob
diff --git a/zshenv b/zshenv
new file mode 100644 (file)
index 0000000..09b4a03
--- /dev/null
+++ b/zshenv
@@ -0,0 +1,22 @@
+# Common functions used by all startup scripts.
+#
+# Copyright (C) 2009 Nick Bowler
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.  This file is offered as-is,
+# without any warranty.
+
+path_front() {
+       local i
+       for i in $@; do
+               path=($i ${path:#$i})
+       done
+}
+
+path_back() {
+       local i
+       for i in $@; do
+               path=(${path:#$i} $i)
+       done
+}