[zsh] Make prepend_to_path and append_to_path more interesting
Add a +e/-e argument (parsed with getopt) that conditionally exports $path.
This commit is contained in:
parent
6f1d8b4ecb
commit
5d74548f21
2 changed files with 46 additions and 14 deletions
|
@ -1,13 +1,29 @@
|
||||||
#!/usr/bin/env zsh
|
|
||||||
# vim:ft=zsh:
|
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
# vim:ft=zsh:
|
||||||
|
|
||||||
function append_to_path
|
append_to_path() {
|
||||||
{
|
local should_export_path=1
|
||||||
if [[ -d "$1" ]]; then
|
|
||||||
path+="$1"
|
while getopts "e" opt; do
|
||||||
|
case $opt in
|
||||||
|
"e") should_export_path=1;;
|
||||||
|
"+e") should_export_path=0;;
|
||||||
|
*) >&2 echo "$0: unknown option '$opt'"
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
local path_to_add=$@[$OPTIND]
|
||||||
|
if [[ -d "$path_to_add" ]]; then
|
||||||
|
path+="$path_to_add"
|
||||||
|
|
||||||
|
if (( $should_export_path )); then
|
||||||
export path
|
export path
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
append_to_path "$@"
|
append_to_path "$@"
|
||||||
|
|
|
@ -1,13 +1,29 @@
|
||||||
#!/usr/bin/env zsh
|
|
||||||
# vim:ft=zsh:
|
|
||||||
# Eryn Wells <eryn@erynwells.me>
|
# Eryn Wells <eryn@erynwells.me>
|
||||||
|
# vim:ft=zsh:
|
||||||
|
|
||||||
function prepend_to_path
|
prepend_to_path() {
|
||||||
{
|
local should_export_path=1
|
||||||
if [[ -d "$1" ]]; then
|
|
||||||
path=("$1" $path)
|
while getopts "e" opt; do
|
||||||
|
case $opt in
|
||||||
|
"e") should_export_path=1;;
|
||||||
|
"+e") should_export_path=0;;
|
||||||
|
*) >&2 echo "$0: unknown option '$opt'"
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
local path_to_add=$@[$OPTIND]
|
||||||
|
if [[ -d "$path_to_add" ]]; then
|
||||||
|
path=("$path_to_add" $path)
|
||||||
|
|
||||||
|
if (( $should_export_path )); then
|
||||||
export path
|
export path
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
prepend_to_path "$@"
|
prepend_to_path "$@"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue