From bd33a24bebde076ab760d7a34c9a415b0d9cd7b6 Mon Sep 17 00:00:00 2001 From: Will Song Date: Tue, 24 Nov 2015 18:12:41 -0600 Subject: add some code to deal with a common $HOME convention --- src/command/commands.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/command/commands.c') 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)); -- cgit 1.4.1-2-gfad0