2

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?

wodow
  • 590
  • 1
  • 6
  • 18
  • 6
    You can always switch back to the previous directory [using the `cd -` command](http://serverfault.com/questions/384930/how-to-change-back-to-previous-path-quickly). – jscott May 04 '13 at 11:13

3 Answers3

2

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     }
dawud
  • 15,096
  • 3
  • 42
  • 61
  • Plenty of options - thanks! I've taken the suggestion to use `alias` and added a specific example as another answer. – wodow May 04 '13 at 23:54
1

In bash, if you accidentally change to the wrong directory, you can go back to the previous directory with:

cd $OLDPWD
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
0

This alias seems to do it:

alias cd='HOME= cd'

I don't think it has any dangerous side effects...

wodow
  • 590
  • 1
  • 6
  • 18