From d85f114b7b221a19572e80d979c2f7e8b1644463 Mon Sep 17 00:00:00 2001
From: Daniel Carl <danielcarl@gmx.de>
Date: Wed, 12 Mar 2014 21:19:34 +0100
Subject: [PATCH] Don't expand download-path if set.

It is unusual to expand the variables when they are set. This will irritate
the user in case ':set download-path=$HOME' is set but ':set download-path?'
spits out not what the user set before.
So vimb follows the example given by vim and save the path like is was given
and expands it it it's used.
---
 doc/vimb.1    |  9 +++++----
 src/setting.c | 22 +---------------------
 2 files changed, 6 insertions(+), 25 deletions(-)

diff --git a/doc/vimb.1 b/doc/vimb.1
index 363373f..9cb624d 100644
--- a/doc/vimb.1
+++ b/doc/vimb.1
@@ -519,8 +519,8 @@ Example: :sh! echo "`date` %" >> myhistory.txt
 .TP
 .BI ":s[ave] [" PATH "]"
 Download current opened page into configured download directory. If \fIPATH\fP
-is given, download under this file name or path. \fIPATH\fP is expanded via
-shell and can therefor contain '~/', '${ENV}' and '~user' pattern.
+is given, download under this file name or path. \fIPATH\fP is expanded and
+can therefor contain '~/', '${ENV}' and '~user' pattern.
 .TP
 .B :q[uit]
 Close the browser.
@@ -700,8 +700,9 @@ cookies)}.
 Cookie timeout in seconds.
 .TP
 .B download-path (string)
-Path to the default download directory. Note that the set path is expanded via
-shell, so you can use '~/path' or '$HOME/foo'.
+Path to the default download directory. If the directory is not set download
+will be written into current directory. Following pattern will be expanded if
+the download is started '~/', '~user', '$VAR' and '${VAR}'.
 .TP
 .B editor-command (string)
 Command with placeholder '%s' called if form filed is opened with editor to
diff --git a/src/setting.c b/src/setting.c
index a162fc1..8f318b6 100644
--- a/src/setting.c
+++ b/src/setting.c
@@ -663,30 +663,10 @@ static SettingStatus home_page(const Setting *s, const SettingType type)
 
 static SettingStatus download_path(const Setting *s, const SettingType type)
 {
-    char *path;
     if (type == SETTING_GET) {
         print_value(s, vb.config.download_dir);
     } else {
-        if (vb.config.download_dir) {
-            g_free(vb.config.download_dir);
-            vb.config.download_dir = NULL;
-        }
-
-        path = util_expand(s->arg.s);
-        if (*path) {
-            /* if path is not absolute set it in the home directory */
-            if (*path != '/') {
-                vb.config.download_dir = g_build_filename(util_get_home_dir(), path, NULL);
-                g_free(path);
-            } else {
-                vb.config.download_dir = path;
-            }
-            /* create the path if it does not exist */
-            util_create_dir_if_not_exists(vb.config.download_dir);
-        } else {
-            /* set the empty path */
-            vb.config.download_dir = path;
-        }
+        OVERWRITE_STRING(vb.config.download_dir, s->arg.s);
     }
 
     return SETTING_OK;
-- 
2.20.1