diff src/evalfunc.c @ 13229:93efa1de7abb v8.0.1489

patch 8.0.1489: there is no easy way to get the global directory commit https://github.com/vim/vim/commit/5459129af2a832a027a1e7ca2d6177c26647d64f Author: Bram Moolenaar <Bram@vim.org> Date: Fri Feb 9 20:53:59 2018 +0100 patch 8.0.1489: there is no easy way to get the global directory Problem: There is no easy way to get the global directory, esp. if some windows have a local directory. Solution: Make getcwd(-1) return the global directory. (Andy Massimino, closes #2606)
author Christian Brabandt <cb@256bit.org>
date Fri, 09 Feb 2018 21:00:06 +0100
parents a80490493c6b
children fee03d646e42
line wrap: on
line diff
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -4613,16 +4613,21 @@ f_getcwd(typval_T *argvars, typval_T *re
 {
     win_T	*wp = NULL;
     char_u	*cwd;
+    int		global = FALSE;
 
     rettv->v_type = VAR_STRING;
     rettv->vval.v_string = NULL;
 
-    wp = find_tabwin(&argvars[0], &argvars[1]);
-    if (wp != NULL)
-    {
-	if (wp->w_localdir != NULL)
-	    rettv->vval.v_string = vim_strsave(wp->w_localdir);
-	else if (globaldir != NULL)
+    if (argvars[0].v_type == VAR_NUMBER && argvars[0].vval.v_number == -1)
+	global = TRUE;
+    else
+	wp = find_tabwin(&argvars[0], &argvars[1]);
+
+    if (wp != NULL && wp->w_localdir != NULL)
+	rettv->vval.v_string = vim_strsave(wp->w_localdir);
+    else if (wp != NULL || global)
+    {
+	if (globaldir != NULL)
 	    rettv->vval.v_string = vim_strsave(globaldir);
 	else
 	{