Skip to content

Commit

Permalink
Cleanup genproto.sh
Browse files Browse the repository at this point in the history
Use delimiter and tr instead of "here" documents for ed script.

Fixes missing newline in script when removing old go_package option.
  • Loading branch information
cmikk committed Feb 9, 2021
1 parent bd1bb11 commit b713147
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions genproto.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
#!/bin/sh

go_package() {
local file pkg cleanup
local file pkg line script
file=$1; shift
pkg=$1; shift

grep "^option go_package = \"$pkg\";$" $file > /dev/null && return
line="option go_package = \"$pkg\";"
grep "^$line\$" $file > /dev/null && return

script="/^package nmsg/|a|$line|.|w|q|"
if grep "^option go_package" $file > /dev/null; then
cleanup=$(echo "/^option go_package/d:1" | tr : '\n')
script="/^option go_package/d|1|${script}"
fi
ed $file <<EOF || exit
$cleanup/^package nmsg/
a
option go_package = "$pkg";
.
w
q
EOF
echo "$script" | tr '|' '\n' | ed $file || exit
}

dir=$(dirname $0)
Expand Down

0 comments on commit b713147

Please sign in to comment.