Permalink
Browse files

PATH helper

This is a way to modify your PATH environment variable

    smartcd helper run path append __PATH__/bin /bar

    smartcd helper run path prepend __PATH__/foo __PATH__/baz

These are analagous to

    autostash PATH="$PATH:__PATH__/bin:/bar"

    autostash PATH="__PATH__/foo:__PATH__/baz:$PATH"

And although this is actually more verbose than the original commands,
it serves as a useful proof of concept for the smartcd helper facility,
and in addition you could use aliases to shorten this significantly:

    alias pa="smartcd helper run path append"
    alias pp="smartcd helper run path prepend"

    pa __PATH__/bin /bar
    pp __PATH__/foo __PATH__/baz
  • Loading branch information...
1 parent 1325977 commit 5ffd9f9c94be385b4ffa9e0561bc0553a70f5ffd @cxreg committed Apr 8, 2012
Showing with 39 additions and 1 deletion.
  1. +3 −1 download-and-install
  2. +4 −0 helper/path/meta
  3. +32 −0 helper/path/script
View
4 download-and-install
@@ -57,7 +57,9 @@ for file in \
lib/core/smartcd_upgrade_database \
lib/core/varstash \
lib/core/arrays \
- lib/core/completion
+ lib/core/completion \
+ helper/path/script \
+ helper/path/meta
do
download_file "$file"
done
View
4 helper/path/meta
@@ -0,0 +1,4 @@
+Description: Modify your PATH
+Author: Dave Olszewski <cxreg@pobox.com>
+URI: https://raw.github.com/cxreg/smartcd/master/helper/path
+Version: 1.0
View
32 helper/path/script
@@ -0,0 +1,32 @@
+###############################################################################
+# Modify your PATH
+#
+# Example usage:
+#
+# # Find these after the main PATH locations
+# smartcd helper run path append __PATH__/bin /bar
+#
+# # Find these first
+# smartcd helper run path prepend __PATH__/foo
+#
+###############################################################################
+
+local i
+local action="$1"; shift
+case $action in
+ prepend) local new
+ for i in "$@"; do
+ if [[ -n $new ]]; then
+ new="$new:$i"
+ else
+ new="$i"
+ fi
+ done
+ autostash PATH="$new:$PATH"
+ ;;
+ append) for i in "$@"; do
+ autostash PATH="$PATH:$i"
+ done
+ ;;
+ *) echo "Usage: smartcd helper run path ( append | prepend ) <path>";;
+esac

0 comments on commit 5ffd9f9

Please sign in to comment.