If the path ~/dev/project1/node_modules/.bin/ionic exists, and my working directory is ~/dev/project1, I would like to be able to just type ionic and hit enter.I could include all those subdirectories to PATH but I'm curious if there's a cleaner way. I'm looking to add some magic so my path always includes that subdirectory relative to whatever my current working directory is.Bonus points if you can make it search all parent directories for that subdirectory and add all of them to the path.
How can I get $PATH to always include $(pwd)/sub_directory/.bin
bash;shell;path
You can put relative paths in the search path. It's dangerous, because it could cause you to execute unexpected binaries when you're in a directory which isn't part of your project; don't do it on a multi-user machine.PATH=;node_modules/.bin/ionic;For more safety and flexibility, you can change the search path each time the current directory changes. In your .bashrc:cd () { builtin cd $@ && chpwd; }pushd () { builtin pushd $@ && chpwd; }popd () { builtin popd $@ && chpwd; }chpwd () {  if [[ $PATH = */node_modules/.bin/ionic ]]; then    PATH=${PATH%:*}  fi  if [[ $PWD =~ ^$HOME/dev/[^/]* ]]; then    project_root=${BASH_REMATCH[0]}    PATH=$PATH:${project_root}/node_modules/.bin/inoic  fi}chpwd