Currently, if :write is given a directory name as its argument, it fails with 
the "Failed to save document." error. This can sometimes be quite annoying: for 
instance, when viewing documents that have been downloaded to /tmp from the 
web, I often find myself wanting to hang on to file without changing its file 
name. In order to do so, I either have to leave Zathura and cp the file or else 
retype the whole filename after :write, neither of which are too convenient.

The following patch would make :write work sort of how mv does: if its argument 
is a currently existing directory, it will be inferred that the user wants to 
save the document in that directory using its current basename.

---
 zathura.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/zathura.c b/zathura.c
index c5e7c9a..b499801 100644
--- a/zathura.c
+++ b/zathura.c
@@ -753,6 +753,15 @@ document_save(zathura_t* zathura, const char* path, bool 
overwrite)
   g_return_val_if_fail(path, false);
 
   gchar* file_path = girara_fix_path(path);
+  /* use current basename if path points to a directory  */
+  if (g_file_test(file_path, G_FILE_TEST_IS_DIR) == TRUE) {
+    char* basename = 
g_path_get_basename(zathura_document_get_path(zathura->document));
+    char* tmp = file_path;
+    file_path = g_strconcat(file_path, "/", basename, NULL);
+    g_free(tmp);
+    g_free(basename);
+  }
+
   if ((overwrite == false) && g_file_test(file_path, G_FILE_TEST_EXISTS)) {
     girara_error("File already exists: %s. Use :write! to overwrite it.", 
file_path);
     g_free(file_path);
-- 
Rob Cornish

_______________________________________________
zathura mailing list
zathura@lists.pwmt.org
http://lists.pwmt.org/mailman/listinfo/zathura

Reply via email to