aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-03-28 15:09:23 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-03-28 15:09:23 +1300
commit699ab2911ca05d23200e6355dc51f9d2b3852146 (patch)
tree5f95099d435d815f5c90dff1cb92ee3f5ec0c3f4
parentAdd mail signature (diff)
downloaddotfiles-699ab2911ca05d23200e6355dc51f9d2b3852146.tar.gz
dotfiles-699ab2911ca05d23200e6355dc51f9d2b3852146.zip
Add readv function
-rw-r--r--README.markdown1
-rw-r--r--bash/bashrc.d/readv.bash26
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
+}
+