about summary refs log tree commit diff stats
path: root/src/command/commands.c
diff options
context:
space:
mode:
authorWill Song <incertia9474@gmail.com>2015-11-24 18:12:41 -0600
committerWill Song <incertia9474@gmail.com>2015-11-24 18:12:41 -0600
commitbd33a24bebde076ab760d7a34c9a415b0d9cd7b6 (patch)
tree59961e407dc2f373f5a0f3a0d1d5b4fd9fe7add5 /src/command/commands.c
parentc4a1e7da9b4c41395d1bec27fea3b47b387e86a6 (diff)
downloadprofani-tty-bd33a24bebde076ab760d7a34c9a415b0d9cd7b6.tar.gz
add some code to deal with a common $HOME convention
Diffstat (limited to 'src/command/commands.c')
-rw-r--r--src/command/commands.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index dc562e81..5e7e0951 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -828,8 +828,19 @@ cmd_export(ProfWin *window, const char *const command, gchar **args)
         cons_show("");
         return TRUE;
     } else if(args[0]) {
-        int fd = open(args[0], O_WRONLY | O_CREAT, 00600);
+        GString *fname = g_string_new("");
         GSList *list = NULL;
+        int fd;
+
+        /* deal with the ~ convention for $HOME */
+        if(args[0][0] == '~') {
+            fname = g_string_append(fname, getenv("HOME"));
+            fname = g_string_append(fname, args[0] + 1);
+        } else {
+            fname = g_string_append(fname, args[0]);
+        }
+
+        fd = open(fname->str, O_WRONLY | O_CREAT, 00600);
 
         if(-1 == fd) {
             cons_show("error: cannot open %s: %s", args[0], strerror(errno));
@@ -866,6 +877,7 @@ cmd_export(ProfWin *window, const char *const command, gchar **args)
 
         g_slist_free(list);
         close(fd);
+        g_string_free(fname, TRUE);
         return TRUE;
 write_error:
         cons_show("error: write failed: %s", strerror(errno));
>
6
7
8
9
10
11
12
13
14
15
16