Reputation: 100190
I have a specific file at the root of my project. I have a command line app (suman) that knows where this file is located. Is there a command line switch I can feed to my command line app that can take me to project root.
Something like
suman --home
or suman -h
or suman --root
what can I write as routine for this command that will actually change the current directory of the parent shell which issued this command? I am not even sure if this is possible.
Upvotes: 1
Views: 8238
Reputation: 100190
If you have an NPM project, you can do this
function npmcd {
cd $(npm root) &&
cd ..
}
put the above in ~/.bashrc
and you should be good to go
Wherever you are in your project, you can issue npmcd at the command line and it will take your terminal to the root of your project, pretty swift.
Upvotes: 1
Reputation: 785471
You can use a (bash/shell) function for this:
suman() {
cd ~/project
command suman "$@"
cd -
}
cd ~/project
- changes directory to $HOME/project
command suman "$@"
- runs actual suman
commandcd -
- changes directory back to where we wereUpvotes: 2