I am about to write a shell script to edit some files.
I'm doing it like this:
/usr/bin/vim $file
Now i want to ask the exit status of vim. If the user closes with saved changes do something (:wq or :x), or if closed without changes (:q, :q!) do something else
if [ vi-exit-status=wq ] ; then
# do this
else # vi didn't save anything
# do that
fi
How can I do that? When I call vi to create a new file and exit it without saving (:q!) and then I check the status via
echo $?
the answer is 0. If I save something or create a file via vi/vim, it's also 0.
Kind regards