I created an alias so that I can run my ruby script from any directory.
alias run_me="ruby ~/mycli/script.rb"
However now the File.dirname doesn't work correctly. When my script runs from the alias, and executes File.dirname(File.realpath(__FILE__))
, I always get the wrong directory. I get the directory of the ruby script file but not where my terminal actually is.
The following code outputs ~/mycli
but I was expecting ~/some_random_directory
. How can I change this behavior?
cd ~/some_random_directory
run_me
CodePudding user response:
I suggest:
File.basename(Dir.getwd)