summaryrefslogtreecommitdiffstats
path: root/.zsh/functions/add-to-list
diff options
context:
space:
mode:
authorGravatar Tom Willemse2013-08-13 20:53:57 +0200
committerGravatar Tom Willemse2013-08-13 20:53:57 +0200
commit2a133f4a39b120cf89755a6222760e1d6c4a45ce (patch)
treeaa5d3e6933072005da11fea6e21b9f4352a2f629 /.zsh/functions/add-to-list
downloadzsh-2a133f4a39b120cf89755a6222760e1d6c4a45ce.tar.gz
zsh-2a133f4a39b120cf89755a6222760e1d6c4a45ce.zip
Initial commit of my ZSH configuration in vcsh
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