I have this function:
sgrep ()
{
local OPTIND;
if getopts i o; then
grep --color=auto -P -in \"$1\" \"$2\";
shift $((OPTIND-1));
I have changed the positional params to one bigger:
sgrep ()
{
local OPTIND;
if getopts i o; then
grep --color=auto -P -in "$2" "$3";
shift $((OPTIND-1));
else
grep --color=auto -P -n "$1" "$2";
fi | sed -E -n 's/^([0-9]+).*/\1/p' | xargs -I{} vim +"{}" "$2";
stty sane
}
Which works, but I don't like it. In one branch I have to use bigger positions, because of the option, but on the other branch without option used, positions do not change. It is messy
I have tried to put shift $((OPTIND-1))
immediately after then
but for no avail.