git status -s | awk '{print $2}' | xargs your-editor
Replace your-editor with the command to launch, well, your editor. If you use a terminal editor, like Neovim, you’re all set. If you use a graphical editor, there may be some more setup.
The command breakdown:
git status -s: Show all the modified files. The-sflag shortens the output to a single line per file. e.g.M path/to/your/file.js.awk '{print $2}': we pass each line to AWK, which is a domain specific programming language designed to operate on lines of text. We give it a simple invocation. By default, AWK separates each line passed to it by spaces, and stores them in positional variables. So we can print out the second column with$2. That gives us just the file name, and removes the M flag (git’s short name for “modified”)- We pass that to
args your-editor. XARGS does many complex and weird things, but by default it’s pretty simple: it takes its input and spreads all of it to the given command. Normally, if you passed 2 files to a command, it would expand to something like this:your-editor file1; your-editor file2. We want all the files to be passed to the editor, like this:your-editor file1 file2. That’s whatxargsdoes for us.
Happy coding!