One of the features of Unix shells is that they allow you to create shell functions that are very similar to functions in other languages; they are essentially called team groups. For example, you can write a function called mycd that first runs cd and then runs other commands:
function mycd () { cd " $@ " if ... ; then workon environment fi }
( " $@ " expands to the arguments you passed to mycd , so mycd /path/to/dir will call cd /path/to/dir .)
As a special case, the shell function actually supersedes the built-in command with a similar name; therefore, if you name your function cd , it will run instead of the built-in cd every time you run cd . In this case, in order for the function to call the built-in cd to actually change the directory (instead of calling itself, causing infinite recursion), it can use the built-in Bash builtin to call the specified built-in command, So:
function cd () { builtin cd " $@ "
(Note. I donβt know what your logic is for recognizing a project directory, so I left it as ... for filling. If you describe your logic in a comment, I will edit it accordingly.)
ruakh source share