我经常这样做:
$ pwd /a/long/long/way/from/anywhere $ cd # oops - meant to tab-complete something /home/$USER
可以cd默认为$ HOME被禁用?
我可以想到的两个选项:
你可以写一个alias到默认的cd而不需要任何你想要的参数。 这是使用像cdargs或apparix实用程序的行。 就个人而言,我一直在使用这个 cdreplace相当长的时间。
修补bash-4.2/builtins/cd.def行为不同( bash-4.2/builtins/cd.def )。 不知道是否改变这个默认打破其他的东西,但。
228 if (list == 0) 229 { 230 /* `cd' without arguments is equivalent to `cd $HOME' */ 231 dirname = get_string_value ("HOME"); 232 233 if (dirname == 0) 234 { 235 builtin_error (_("HOME not set")); 236 return (EXECUTION_FAILURE); 237 } 238 lflag = 0; 239 }
在bash中,如果你不小心改到了错误的目录,你可以回到以前的目录:
cd $OLDPWD
这个别名似乎是这样做的:
别名cd ='HOME = cd'
我不认为它有任何危险的副作用…