diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-03 23:21:56 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-03 23:21:56 +1200 |
commit | 5b8e387dc4928a2075c3a5a085fe803945a37e47 (patch) | |
tree | 1e10052f0c7f8f965bb9202b0661322e37088a26 /bash/bashrc.d | |
parent | Handle empty password dirs (diff) | |
download | dotfiles-5b8e387dc4928a2075c3a5a085fe803945a37e47.tar.gz dotfiles-5b8e387dc4928a2075c3a5a085fe803945a37e47.zip |
Add vared function for editing vars
Diffstat (limited to 'bash/bashrc.d')
-rw-r--r-- | bash/bashrc.d/vared.bash | 19 |
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 + |