diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-04 11:58:03 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2015-06-04 11:58:03 +1200 |
commit | a0ca55ad53acffd2fa87ff84dfba7bccec92dfc6 (patch) | |
tree | b428b79985af12132536f1459a9445c6eafdbf54 /bash/bashrc.d/vared.bash | |
parent | COLORFGBG too (diff) | |
download | dotfiles-a0ca55ad53acffd2fa87ff84dfba7bccec92dfc6.tar.gz dotfiles-a0ca55ad53acffd2fa87ff84dfba7bccec92dfc6.zip |
Support -p option to vared
Diffstat (limited to 'bash/bashrc.d/vared.bash')
-rw-r--r-- | bash/bashrc.d/vared.bash | 17 |
1 files changed, 16 insertions, 1 deletions
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 |