aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-06-03 23:21:56 +1200
committerTom Ryder <tom@sanctum.geek.nz>2015-06-03 23:21:56 +1200
commit5b8e387dc4928a2075c3a5a085fe803945a37e47 (patch)
tree1e10052f0c7f8f965bb9202b0661322e37088a26 /bash
parentHandle empty password dirs (diff)
downloaddotfiles-5b8e387dc4928a2075c3a5a085fe803945a37e47.tar.gz
dotfiles-5b8e387dc4928a2075c3a5a085fe803945a37e47.zip
Add vared function for editing vars
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc.d/vared.bash19
1 files changed, 19 insertions, 0 deletions
diff --git a/bash/bashrc.d/vared.bash b/bash/bashrc.d/vared.bash
new file mode 100644
index 00000000..a2066b4c
--- /dev/null
+++ b/bash/bashrc.d/vared.bash
@@ -0,0 +1,19 @@
+# Requires Bash >= 4.0 for read -i and ${!name}
+if ((10#${BASH_VERSINFO[0]%%[![:digit:]]*} < 4)) ; then
+ return
+fi
+
+# Edit named variables' values
+vared() {
+ if ! (($#)) ; then
+ printf 'bash: %s: No variable names given\n' \
+ "$FUNCNAME" >&2
+ return 2
+ fi
+ local name
+ for name in "$@" ; do
+ IFS= read -e -i "${!name}" -p "$name"= -r "$name"
+ done
+}
+complete -A variable vared
+