diff options
-rw-r--r-- | README.markdown | 1 | ||||
-rw-r--r-- | bash/bashrc.d/readv.bash | 26 |
2 files changed, 27 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown index 9a617c59..d6c61463 100644 --- a/README.markdown +++ b/README.markdown @@ -189,6 +189,7 @@ There are a few other little tricks in `bash/bashrc.d`, including: * `path` — Manage the contents of `PATH` conveniently * `paz` — Print given arguments separated by NULL chars * `pd` — Change to the argument’s parent directory +* `readv` — Print names and values from `read` calls to `stderr` * `readz` — Alias for `read -d '' -r` * `scr` — Create a temporary directory and change into it * `sd` — Switch to a sibling directory diff --git a/bash/bashrc.d/readv.bash b/bash/bashrc.d/readv.bash new file mode 100644 index 00000000..5013dd89 --- /dev/null +++ b/bash/bashrc.d/readv.bash @@ -0,0 +1,26 @@ +readv() { + local arg + local -a opts names + for arg ; do + case $arg in + --) + shift + break + ;; + -*) + shift + opts[${#opts[@]}]=$arg + ;; + *) + break + ;; + esac + done + names=("$@") + builtin read "${opts[@]}" "${names[@]}" || return + for name in "${names[@]}" ; do + printf >&2 '%s: %s = %s\n' \ + "$FUNCNAME" "$name" "${!name}" + done +} + |