As already mentioned in other answers, you can change pwd inside a ruby ​​script, but this only affects the child process (your ruby ​​script). Unable to modify pwd parent process from child process.
A workaround may be for the script to output shell commands for execution and call them in reverse cycles (i.e., the shell executes the script and takes its output as commands for execution)
myscript.rb:
# … fancy code to build somepath … puts "cd #{somepath}"
to call him:
`ruby myscript.rb`
make it a simple command using an alias:
alias myscript='`ruby /path/to/myscript.rb`'
Unfortunately, this way you cannot get the text of the script output to the user, since any script text is displayed by the shell (although there are other workarounds for this).
source share