Merge pull request #16618 from zeertzjq/vim-8.2.3780

vim-patch:8.2.{3780,3784}: ":cd" works differently on MS-Windows
This commit is contained in:
Jan Edmund Lazo
2021-12-25 21:10:44 -05:00
committed by GitHub
9 changed files with 59 additions and 13 deletions

View File

@@ -7807,14 +7807,17 @@ bool changedir_func(char_u *new_dir, CdScope scope)
prev_dir = pdir;
}
// For UNIX ":cd" means: go to home directory.
// On other systems too if 'cdhome' is set.
#if defined(UNIX)
// On Unix ":cd" means: go to home directory.
if (*new_dir == NUL) {
#else
if (*new_dir == NUL && p_cdh) {
#endif
// Use NameBuff for home directory name.
expand_env((char_u *)"$HOME", NameBuff, MAXPATHL);
new_dir = NameBuff;
}
#endif
bool dir_differs = new_dir == NULL || pdir == NULL
|| pathcmp((char *)pdir, (char *)new_dir, -1) != 0;
@@ -7834,9 +7837,9 @@ void ex_cd(exarg_T *eap)
{
char_u *new_dir;
new_dir = eap->arg;
#if !defined(UNIX) && !defined(VMS)
// for non-UNIX ":cd" means: print current directory
if (*new_dir == NUL) {
#if !defined(UNIX)
// for non-UNIX ":cd" means: print current directory unless 'cdhome' is set
if (*new_dir == NUL && !p_cdh) {
ex_pwd(NULL);
} else
#endif

View File

@@ -743,6 +743,7 @@ EXTERN int p_write; // 'write'
EXTERN int p_wa; // 'writeany'
EXTERN int p_wb; // 'writebackup'
EXTERN long p_wd; // 'writedelay'
EXTERN int p_cdh; // 'cdhome'
EXTERN int p_force_on; ///< options that cannot be turned off.
EXTERN int p_force_off; ///< options that cannot be turned on.

View File

@@ -274,6 +274,14 @@ return {
varname='p_cmp',
defaults={if_true="internal,keepascii"}
},
{
full_name='cdhome', abbreviation='cdh',
short_desc=N_(":cd without argument goes to the home directory"),
type='bool', scope={'global'},
secure=true,
varname='p_cdh',
defaults={if_true=false}
},
{
full_name='cdpath', abbreviation='cd',
short_desc=N_("list of directories searched with \":cd\""),

View File

@@ -64,6 +64,9 @@ if has('reltime')
let s:start_time = reltime()
endif
" Always use forward slashes.
set shellslash
" Common with all tests on all systems.
source setup.vim
@@ -104,9 +107,6 @@ lang mess C
" Nvim: append runtime from build dir, which contains the generated doc/tags.
let &runtimepath .= ','.expand($BUILD_DIR).'/runtime/'
" Always use forward slashes.
set shellslash
let s:t_bold = &t_md
let s:t_normal = &t_me
if has('win32')

View File

@@ -732,4 +732,25 @@ func Test_opt_reset_scroll()
call delete('Xscroll')
endfunc
" Test for the 'cdhome' option
func Test_opt_cdhome()
if has('unix') || has('vms')
throw 'Skipped: only works on non-Unix'
endif
set cdhome&
call assert_equal(0, &cdhome)
set cdhome
" This paragraph is copied from Test_cd_no_arg().
let path = getcwd()
cd
call assert_equal($HOME, getcwd())
call assert_notequal(path, getcwd())
exe 'cd ' .. fnameescape(path)
call assert_equal(path, getcwd())
set cdhome&
endfunc
" vim: shiftwidth=2 sts=2 expandtab