I'd like to know if it's possible to change the current terminal directory from where I'm executing my ruby script.
For example, if I'm executing the script from $HOME
in the terminal, I would like to cd in $HOME/mydir
at the end of the script.
I've tried a couple of things, but I'm always finding in the same directorry where the script was started.
Things I've tried:
Dir.chdir( mydir )
%[cd mydir]
They actually do change directory, but only in the thread of the script execution. When the script ends, my current location in the terminal is still the same I was before launching the script.
I've found something similar in SO, but it's Python-related and response seems negative.
You may ask why?
I'm currently involved in a command line application (using gli
) which, as starting point, needs a project folder. So my first command looks like:
$ myfoo new project
Which creates a new folder with name project
in the current directory. Now to be able to work with the other commands I need to:
$ cd project
project$ myfoo domore
So I was simply thinking that it would be nice to found my self in project
after having executed myfoo new project
.
As I was afraid, it's not that easy (not possible at all). So what about using a bash script which does the ruby calls that I want, in place of the standard file generated by RubyGems? Is that feasible? Am I foolish? Should I use eval
?
Thanks for the answers. But I'm afraid that no one is acceptable. Probably the question wasn't :).