j Project root
- This enables you to return to the root directory of your project faster.
- It's meant for people who find it annoying to type
cd ../
a lot of times:D
- If you are in
./src/api/routes
you can simply usepr
and you will automatically cd to the root of the project if its path was saved waspr add
command.
.
├── dist
├── node_modules
├── package.json
├── src
│ ├── api
│ │ └── routes
│ │ └── getProduct.ts
│ └── utils
│ └── array.ts
└── tsconfig.json
6 directories, 4 files
- Run
mkdir ~/.proot
- Run
touch entryPoint.sh
- Put this in the file
entryPoint.sh
function pr {
output=$(~/.proot/proot $@)
retCode=$?
if [[ ( $1 == "go" || $1 == "" || $1 == "back" || $1 == "b" || $1 == "to" || $1 == "t" ) && $retCode -eq 0 ]]; then
# cd when go or back command. hide output
cd $output
else
echo $output
fi
if [ $retCode -ne 0 ]; then
return $retCode
fi
}
- Install the
proot
executable from here and put it in the directory~/.proot
- Add
source ~/.proot/entryPoint.sh
to your.bashrc
or.zshrc
. (This step is important) - Source your shell again or open a new terminal session.
- Use
pr --help
- Use
pr add [path]
to save the current path as a project root. - Use
pr
orpr go
from any child directory of your project and you will jump to the root of the project as long as you saved its path like in step 1. - Use
pr list
to list all saved project root paths. - Use
pr purge
to delete any paths that were saved before but don't exist in the file system any more. - Use
pr clear
to delete all saved paths. (use with CAUTION) - Use
pr back
go back to the last path from which you used thepr go
command- let's say you are in
/home/user/project/src/utils
and you saved/home/user/project/
as a project root - Now you want to go back to the project root (to do something quickly) so you execute
pr go
or justpr
- What if you want to go back to
/home/user/project/src/utils
again to continue you work ? thepr back
command helps with such case - type
pr back
and it will cd to/home/user/project/src/utils
automatically
- let's say you are in