Permalink
Browse files

add some path manipulation functions/aliases

Signed-off-by: Christopher Hall <hsw@openmoko.com>
  • Loading branch information...
1 parent 925e9a6 commit 7a6b87d0f3e1bddf3bedfbbda81d8a54c291ed6a @hxw committed Jan 11, 2013
Showing with 59 additions and 1 deletion.
  1. +59 −1 zshrc
View
60 zshrc
@@ -42,7 +42,65 @@ fi
export LESS="-iR"
# make a directory and change to it
-function mkcd { mkdir -p "$1"; cd "$1"; }
+function mkcd {
+ local dir
+ dir="$1"; shift
+
+ if [ -z "${dir}" ]
+ then
+ pwd
+ elif [ -d "${dir}" ]
+ then
+ cd "${dir}"
+ elif [ -f "${dir}" ]
+ then
+ echo A file of that name already exists
+ return 1
+ else
+ mkdir -p "${dir}"
+ cd "${dir}"
+ fi
+ return 0
+}
+# remove items from PATH
+function pathrm {
+ local item pa p IFS old_ifs
+ old_ifs="${IFS}"
+ IFS=':'
+ pa=(${PATH})
+ IFS="${old_ifs}"
+
+ for item in $@
+ do
+ pa=("${pa[@]/${item}/}")
+ done
+
+ p=
+ for item in "${pa[@]}"
+ do
+ [ -n "${item}" ] && p="${p}:${item}"
+ done
+ pa="${pa[@]}"
+ PATH="${p:1}"
+}
+
+# add items to front of PATH
+# move existing items to front of PATH
+function pathfront {
+ local item p
+ pathrm "$@"
+
+ p=
+ for item in $@
+ do
+ [ -n "${item}" ] && p="${p}:${item}"
+ done
+ PATH="${p:1}:${PATH}"
+}
+
+# show path
+alias path='echo ${PATH}'
+
# Single history for all open shells
HISTFILE=~/.zhistory

0 comments on commit 7a6b87d

Please sign in to comment.