A quick CLI tip: launch all files modified in git in your editor đź’˝

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:

  1. git status -s: Show all the modified files. The -s flag shortens the output to a single line per file. e.g. M path/to/your/file.js.
  2. 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”)
  3. 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 what xargs does for us.

Happy coding!