0

I have a shell script which builds commands that the shell script will subsequently run. This is a script which is a helper for troubleshooting compilation issues, and the commands are code compilation commands pulled out of a compilation database file.

I would like to present an opportunity to adjust the command using Vim. Desired behavior is similar to what git commit does... So I just need to come up with a way to feed a string into Vim in such a way that saving and quitting will return the string to the script. I believe what git does is use the .git/COMMIT_EDITMSG file. I wonder if there are other ways to achieve this, perhaps without having to access the file system.

Steven Lu
  • 41,389
  • 58
  • 210
  • 364

1 Answers1

0

Previously my code was

CMD="$(echo "$COMMANDS" | sed -n "${COUNTER}p")" # build command
$CMD # run command

Now it's just

echo "$COMMANDS" | sed -n "${COUNTER}p" > .CMD_EDIT # build cmd, prep interactive edit
vim .CMD_EDIT # interactive edit
. .CMD_EDIT # run command by sourcing the command

This has the built in behavior similar to git commit which does nothing if you empty the buffer.

Steven Lu
  • 41,389
  • 58
  • 210
  • 364