0
votes

I had an alias in my bash profile like this:

alias test='cd /Usr/work/dir/test'

every time I would try to use bash completion for git in a terminal it would:

  1. freeze the terminal immediately after hitting tab.
  2. take me to that directory.

As soon as I removed that alias bash completion for git works fine. Why's that?

git version 2.26.2

GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin19) Copyright (C) 2007 Free Software Foundation, Inc.

1
Also, don't use aliases. They've been effectively obsolete since before 1996. Use a function. - William Pursell

1 Answers

2
votes

test is a built-in command, and creating an alias named test shadows it, which could lead to unforeseen issues. Pick a different name.

alias goto_test='cd /Usr/work/dir/test'

However, this is probably the least desirable solution. First, consider using a function instead:

goto_test () {
    cd /Usr/work/dir/test
}

Second, you can add /Usr/work/dir to your CDPATH variable, so that you can quickly switch to any subdirectory without having to use the entire path.

$ CDPATH=/Usr/work/dir
$ cd test
/Usr/Work/dir
$ pwd
/Usr/Work/dir/test

This saves you from having to define multiple aliases or functions if there are several directories you might commonly switch to.