1

I can't count the number of times I've typed: source en<tab> only to be left with a bunch of garbled text on the screen because it sourced the program env instead of the local env.sh.

I tried making a simple function to detect this particular use case but it didn't work.

This is what I tried:

source () { if [ "$1" == "env" ] then source ./env.sh else source $@ fi } 

I realize that source is a shell command which is probably why it didn't work but I don't really care about how its implemented, I just want to stop sourcing binaries on my $PATH before the local directory.

Cheers!

2 Answers 2

1

The reason it doesn't work is that you're calling your function recursively. Use builtin source to call the builtin source rather than your function source:

source () { if [ "$1" == "env" ] then builtin source ./env.sh else builtin source $@ fi } 
Sign up to request clarification or add additional context in comments.

Comments

0

Rather than override a general command (source) to handle a special case, make a new command to handle the special case.

locenv () { source ./env.sh } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.