From 8f6d534cac0269d9c6c46485bbf40ef19e1f9115 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Mon, 18 Feb 2019 11:54:33 +0100 Subject: [PATCH] vsed: make more compatible with sed commandline semantics. --- common/environment/setup/vsed.sh | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/common/environment/setup/vsed.sh b/common/environment/setup/vsed.sh index 400b1f2c9d2..e5b66990bd4 100644 --- a/common/environment/setup/vsed.sh +++ b/common/environment/setup/vsed.sh @@ -6,23 +6,41 @@ # call. vsed() { - local files=() regexes=() OPTIND + local files=() regexes=() OPTIND OPTSTRING="ie:" has_inline= - while getopts ":i:e:" opt; do + eval set -- $(getopt -s bash "$OPTSTRING" "$@"); + + while getopts "$OPTSTRING" opt; do case $opt in - i) files+=("$OPTARG") ;; + i) has_inline=1 ;; e) regexes+=("$OPTARG") ;; *) ;; esac done - if [ ${#files[@]} -eq 0 ]; then - msg_red "$pkgver: vsed: no files specified with -i.\n" + if ! [ "$has_inline" ]; then + msg_red "$pkgver: vsed: you must specify -i.\n" return 1 fi + shift $(($OPTIND - 1)) + + if [ ${#regexes[@]} -eq 0 ] && [ $# -ge 2 ]; then + regexes+=("$1") + shift + fi + if [ ${#regexes[@]} -eq 0 ]; then - msg_red "$pkgver: vsed: no regexes specified with -e.\n" + msg_red "$pkgver: vsed: no regexes specified.\n" + return 1 + fi + + for i; do + files+=("$i") + done + + if [ ${#files[@]} -eq 0 ]; then + msg_red "$pkgver: vsed: no files specified.\n" return 1 fi