diff --git a/src/browser.c b/src/browser.c index 31972be..635c6de 100644 --- a/src/browser.c +++ b/src/browser.c @@ -41,8 +41,6 @@ static int longest = 0; /* The number of columns in the longest filename in the list. */ static size_t selected = 0; /* The currently selected filename in the list; zero-based. */ -static char *path_save = NULL; - /* A copy of the current path. */ /* Our main file browser function. path is the tilde-expanded path we * start browsing from. */ @@ -75,7 +73,7 @@ char *do_browser(char *path, DIR *dir) path = mallocstrassn(path, get_full_path(path)); /* Save the current path in order to be used later. */ - path_save = path; + path_save = mallocstrcpy(path_save, path); assert(path != NULL && path[strlen(path) - 1] == '/'); diff --git a/src/files.c b/src/files.c index 2dff2ac..30c98c0 100644 --- a/src/files.c +++ b/src/files.c @@ -1101,6 +1101,7 @@ void do_insertfile( #endif while (TRUE) { +path_save = mallocstrcpy(path_save, "./"); #ifndef NANO_TINY if (execute) { msg = @@ -2257,7 +2258,9 @@ int do_writeout(bool exiting) #endif openfile->filename); + while (TRUE) { +path_save = mallocstrcpy(path_save, "./"); const char *msg; #ifndef NANO_TINY const char *formatstr, *backupstr; @@ -2687,7 +2690,7 @@ char **cwd_tab_completion(const char *buf, bool allow_files, size_t free(wasdirname); } else { filename = dirname; - dirname = mallocstrcpy(NULL, "./"); + dirname = mallocstrcpy(NULL, path_save); } assert(dirname[strlen(dirname) - 1] == '/'); diff --git a/src/global.c b/src/global.c index 1c2f8af..2047923 100644 --- a/src/global.c +++ b/src/global.c @@ -39,6 +39,8 @@ bool func_key; /* Whether the current keystroke is an extended keypad value. */ bool focusing = FALSE; /* Whether an update of the edit window should center the cursor. */ +char *path_save = NULL; + /* Stores current path in browser for cwd_tab_completion(). */ #ifndef NANO_TINY int controlleft = CONTROL_LEFT; diff --git a/src/proto.h b/src/proto.h index 5373476..6fda9dd 100644 --- a/src/proto.h +++ b/src/proto.h @@ -33,6 +33,7 @@ extern volatile sig_atomic_t sigwinch_counter; extern bool meta_key; extern bool func_key; extern bool focusing; +extern char *path_save; #ifndef NANO_TINY extern int controlleft;