Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to (terminal) cd in folder from ruby script
    primarykey
    data
    text
    <p>I'd like to know if it's possible to change the current terminal directory from where I'm executing my ruby script.</p> <p>For example, if I'm executing the script from <code>$HOME</code> in the terminal, I would like to cd in <code>$HOME/mydir</code> at the end of the script. </p> <p>I've tried a couple of things, but I'm always finding in the same directorry where the script was started.</p> <p>Things I've tried:</p> <pre><code>Dir.chdir( mydir ) %[cd mydir] </code></pre> <p>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.</p> <p>I've found something similar in SO, but it's <a href="https://stackoverflow.com/questions/2799256/cd-terminal-at-a-given-directory-after-running-a-python-script">Python-related</a> and response seems negative.</p> <hr> <p>You may ask why?</p> <p>I'm currently involved in a command line application (using <code>gli</code>) which, as starting point, needs a project folder. So my first command looks like:</p> <pre><code>$ myfoo new project </code></pre> <p>Which creates a new folder with name <code>project</code> in the current directory. Now to be able to work with the other commands I need to:</p> <pre><code>$ cd project project$ myfoo domore </code></pre> <p>So I was <em>simply</em> thinking that it would be nice to found my self in <code>project</code> after having executed <code>myfoo new project</code>.</p> <hr> <p>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 <code>eval</code>?</p> <hr> <p>Thanks for the answers. But I'm afraid that no one is acceptable. Probably the question wasn't :).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload