summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2018-10-29 12:24:10 -0600
committerAaron Ball <nullspoon@oper.io>2018-10-29 12:24:10 -0600
commit4d11d5e2802a6074ac6ad11232ec29f28ae60297 (patch)
tree8dcc72b4a736caee2bce7f4ed7b19267fd192c5d
parent0329386fe6f8fada5d65795292416573fa64f748 (diff)
downloadgpgedit-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.adoc2
-rw-r--r--src/main.c9
2 files changed, 9 insertions, 2 deletions
diff --git a/TODO.adoc b/TODO.adoc
index aaf3b38..fa8dec8 100644
--- a/TODO.adoc
+++ b/TODO.adoc
@@ -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
diff --git a/src/main.c b/src/main.c
index ca0df5c..2ddae06 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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);
}

Generated by cgit