I do this too often:
$ pwd /a/long/long/way/from/anywhere $ cd # oops - meant to tab-complete something /home/$USER
Can cd
defaulting to $HOME be disabled?
I do this too often:
$ pwd /a/long/long/way/from/anywhere $ cd # oops - meant to tab-complete something /home/$USER
Can cd
defaulting to $HOME be disabled?
Two options I can think of:
you can write an alias
to default cd
without arguments to whatever you want. This is in the line of using utilities like cdargs
or apparix
. Personally, I have been using this cd
replacement for quite a long time.
patch bash
to behave differently (bash-4.2/builtins/cd.def
). Not sure if changing this default breaks other things, though.
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 }
In bash, if you accidentally change to the wrong directory, you can go back to the previous directory with:
cd $OLDPWD
This alias seems to do it:
alias cd='HOME= cd'
I don't think it has any dangerous side effects...