Closed JoeWoodward closed 4 years ago
[editor | options] = String.split(System.get_env("EDITOR"), ~r/ (-\w{2,}|-\w\s+"(?:[^"\\]*(?:\\.[^"\\]*)*)"|-\w\s+'(?:[^'\\]*(?:\\.[^'\\]*)*)'|--\w+="(?:[^"\\]*(?:\\.[^"\\]*)*)"|--\w+='(?:[^'\\]*(?:\\.[^'\\]*)*)'|--\w+=[^\s]+|-\w)/, include_captures: true, trim: true)
options = Enum.map(options, &String.trim/1)
{_retval, 0} = System.cmd(editor, options ++ [tmp_filepath])
The above code snippet will look for all possible argument types. I think all are covered
I tested it against
open -w
mvim -fcd
mvim -f -c "au VimLeave * !open -a iTerm"
mvim -f -c "au VimLeave * \"!open\" -a iTerm"
mvim --flag="thing"
mvim --flag=thing
mvim --flag="thing asdf asdf"
My EDITOR is set to
mvim -f -c "au VimLeave * !open -a iTerm"
This opens macVim, Then -f for foreground aka wait Then -c for command The command gets split from the -c flag and System.cmd fails in EncryptedSecrets.edit