diff options
author | Aaron Ball <nullspoon@oper.io> | 2018-10-29 12:24:10 -0600 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2018-10-29 12:24:10 -0600 |
commit | 4d11d5e2802a6074ac6ad11232ec29f28ae60297 (patch) | |
tree | 8dcc72b4a736caee2bce7f4ed7b19267fd192c5d | |
parent | 0329386fe6f8fada5d65795292416573fa64f748 (diff) | |
download | gpgedit-4d11d5e2802a6074ac6ad11232ec29f28ae60297.tar.gz gpgedit-4d11d5e2802a6074ac6ad11232ec29f28ae60297.tar.xz |
Implemented read EDITOR env variable
Now we detect which editor the user wants to use based on their
environment variable EDITOR. If none is set, use vim by default. Tested
with vim, vi, nano, cat (not an editor), and leafpad.
-rw-r--r-- | TODO.adoc | 2 | ||||
-rw-r--r-- | src/main.c | 9 |
2 files changed, 9 insertions, 2 deletions
@@ -7,7 +7,7 @@ Implement * [x] File decryption to temp path * [x] File re-encryption * [ ] Comment all functions -* [ ] Read environment variable $EDITOR, default to vim (only parse arg 0 to +* [X] Read environment variable $EDITOR, default to vim (only parse arg 0 to some avoid security concerns) * [ ] Argument parser (eg: -r,--recipient) * [x] Recipient addition beyond the list already in the file @@ -26,7 +26,14 @@ void system_edit(char* file) { char cmd[256]; // Buffer for editor command - sprintf(cmd, "%s %s\n", "vim", file); + char* editor; // Editor to use when editing the file + + // Read the environment variable for "EDITOR". If null, default to vim. + editor = getenv("EDITOR"); + if(editor == NULL) + editor = "vim"; + + sprintf(cmd, "%s %s\n", editor, file); system(cmd); } |