long time lurker first time poster.
i've looked everywhere , i'm sure it's found couldn't word search.
i working on coding exercises textbook , i've got work in directories following hierarchy:
r00t / \ tools code \ chapts in tools directory couple scripts make life easier. want, , reason i'm posting, able call scripts in r00t/tools wherever am, long i'm inside r00t. know add them global path seems lazy , don't want path balloon more (is sensible?).
so, can add scripts or programs "local path" inside dir somehow?
take on here towards ondir (link) program letting execute scripts upon entering or leaving directories.
with dynamically change path variable. must admit never have used program nor informed development status.
alternatively replace cd command script checking pwd versus r00t directory , updating $path based on outcome. of course cd slowed down not noticeably.
an example:
#!/bin/bash #alternative cd cd $* #check r00t directory if [ "$( pwd | grep -o 'r00t')" == "r00t" ] ; #check path variable: if [ "$(echo $path | grep -o 'r00t')" != "r00t" ] ; export path=$path:/dir/r00t/bin fi else #remove r00t path when not in r00t if [ "$(echo $path | grep -o 'r00t')" == "r00t" ] ; export path=$( echo $path | sed 's~:/dir/r00t/bin~~' ) fi fi note you'll have intoduce alias follows:
alias cd='. ./path/to/script/alternative_cd.sh' as exported path needs sourced in order work current shell (if using bash alternative_cd.sh, you'd new path subshell script run in)
i tested , seemed working. have fun.
Comments
Post a Comment