I'm trying to write some script (a function) which I can use to add some additions to a BASH script I'm modifying. This BASH script automates the building of a series of packages. The part of the script I'm wanting to modify is to add an "or die" clause after the three points for which I want some additional info. Consider this
die() {
[[ -z $1 ]] && msg="Unintended early exit" || msg=$1
echo $msg
exit 1
}
...
# This is the basic pattern
echo "package"
cd package
mkdir build && cd build
../configure <options>
make -j 8
make install
cd $TOP
I want to add onto the configure
, build
and install
lines with the die()
function to help in seeing when problems are encountered:
# This is the basic pattern
echo "package"
cd package
mkdir build && cd build
../configure <options> || die "package failed to configure"
make -j 8 || die "package failed to build"
make install || die "package failed to install"
cd $TOP
Since each "block" of the script starts with the echo
command, I'm basically wanting to do this g/^echo/call AddDie()
.
So, I'm trying to write a function named AddDie()
which basically does
- copy
package
into the0
register - "for this block" append: die || "ph failed to ..."
- "for this block" change each instance of "ph" to "package"
For this I've tried various things like this
function! AddDie()
exec 'norm f"lyt"'
exec 'norm }me``'
.,'eg/configure/exec 'norm A || die "ph failed to configure"'
.,'eg/make -j/exec 'norm A || die "ph failed to build"'
.,'eg/install/exec 'norm A || die "ph failed to install"'
.,'es/ph/\<C-R>0\<CR>
endfunction
Which results in all kinds of "nope" from vim. Most of the errors are "cannot do global recursive with a range." Lots of Googling returns hits for global recursive stuff but not really anything about why this range isn't possible. Looking through some hits from this site I think I've learned I have to use the exec ...
for everything not just what the :g
command finds within the range, but I don't understand why. Isn't vimscript supposed to work with ex commands and these commands take ranges right?
I'd appreciate any insights and help. Thanks.