mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-10 17:53:45 +01:00
Document saves with current basename if given a directory
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. Signed-off-by: Sebastian Ramacher <sebastian@ramacher.at>
This commit is contained in:
parent
9765b43113
commit
723f1535e1
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user