summaryrefslogtreecommitdiffstats
path: root/zsh/functions/add-to-list
diff options
context:
space:
mode:
authorGravatar Tom Willemse2014-07-01 22:52:29 +0200
committerGravatar Tom Willemse2014-07-01 22:52:29 +0200
commitd494d318ceedcfc18c81440eb29bd681084ff65c (patch)
tree3b889379ed2115d9def65e21c82463e4f6b7f746 /zsh/functions/add-to-list
parentff1b2cb7624d6d65f3488c03918e3c18cccfd21d (diff)
downloaddotfiles-d494d318ceedcfc18c81440eb29bd681084ff65c.tar.gz
dotfiles-d494d318ceedcfc18c81440eb29bd681084ff65c.zip
Rename .zsh
Diffstat (limited to 'zsh/functions/add-to-list')
-rw-r--r--zsh/functions/add-to-list10
1 files changed, 10 insertions, 0 deletions
diff --git a/zsh/functions/add-to-list b/zsh/functions/add-to-list
new file mode 100644
index 0000000..18720e0
--- /dev/null
+++ b/zsh/functions/add-to-list
@@ -0,0 +1,10 @@
+# -*- mode: sh; -*-
+if [[ ! "${(P)${1}}" =~ (^|:)"$2"(:|$) ]]; then
+ if [ -n "$3" ]; then
+ # Append
+ typeset -g $1="${(P)${1}}:$2"
+ else
+ # Prepend
+ typeset -g $1="$2:${(P)${1}}"
+ fi
+fi