kieraneglin / encrypted_secrets_ex

Store your application's secrets inside your VCS
MIT License
46 stars 5 forks source link

When flags have additional values the System.cmd call fails #7

Closed JoeWoodward closed 4 years ago

JoeWoodward commented 4 years ago

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

JoeWoodward commented 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])
JoeWoodward commented 4 years ago

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"