ePhrygian
ePhrygian

Reputation: 51

How to create a bash alias to launch gvim on the .bash_aliases file and resource it when the editor completes?

I'd like to have a single alias which launches gvim ~/.bash_aliases and then re-sources the file after gvim exits (. ~/.bash_aliases)

For example,...

alias newaliases="gvim ~/.bash_aliases && . ~/.bash_aliases"

or perhaps...

alias newaliases="gvim ~/.bash_aliases ; . ~/.bash_aliases"

However in both examples, gvim runs, of course, asynchronously. This in turn causes the second command to be run as soon as gvim is launched rather than when gvim finishes.

I could discover the gvim's pid and run wait pid prior to re-sourcing. But that seems a bit tedious (e.g., I would need to guarantee I've got the pid of the correct gvim instance). Perhaps it is the only solution?

Upvotes: 0

Views: 383

Answers (1)

Barmar
Barmar

Reputation: 781245

Use the -f option to gvim, which makes it run in the foreground, so the next command won't run until you finish editing.

-f
Foreground. For the GUI version, Vim will not fork and detach from the shell it was started in. ... This option should be used when Vim is executed by a program that will wait for the edit session to finish (e.g. mail).

Upvotes: 4

Related Questions