From a0ca55ad53acffd2fa87ff84dfba7bccec92dfc6 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Thu, 4 Jun 2015 11:58:03 +1200 Subject: Support -p option to vared --- bash/bashrc.d/vared.bash | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'bash/bashrc.d/vared.bash') diff --git a/bash/bashrc.d/vared.bash b/bash/bashrc.d/vared.bash index a2066b4c..40eeee21 100644 --- a/bash/bashrc.d/vared.bash +++ b/bash/bashrc.d/vared.bash @@ -5,6 +5,21 @@ fi # Edit named variables' values vared() { + local opt prompt + local OPTERR OPTIND OPTARG + while getopts 'p:' ; do + case $opt in + p) + prompt=$OPTARG + ;; + \?) + printf 'bash: %s: -%s: invalid option\n' + "$FUNCNAME" "$opt" >&2 + return 2 + ;; + esac + done + shift "$((OPTIND-1))" if ! (($#)) ; then printf 'bash: %s: No variable names given\n' \ "$FUNCNAME" >&2 @@ -12,7 +27,7 @@ vared() { fi local name for name in "$@" ; do - IFS= read -e -i "${!name}" -p "$name"= -r "$name" + IFS= read -e -i "${!name}" -p "${prompt:-$name=}" -r -- "$name" done } complete -A variable vared -- cgit v1.2.3