Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call bash function in IRB

Tags:

bash

ruby

If I run a custom bash function under shell console:

~/w/dotfiles/ruby [g:master-] ¶ repository_root
/Users/tian/Documents/workspace/dotfiles

And if I run the custom bash function under IRB:

irb(main):001:0> `repository_root`
(irb):1: command not found: repository_root
=> ""

How could I get the same result in IRB?

# declare
repository_root () {
    if git_is_repository ; then
        git_show_repository_root
    fi
}
like image 659
Tian Chen Avatar asked Jan 24 '26 21:01

Tian Chen


1 Answers

Assuming your function is in one of your bash profile files, you want to start up an interactive (-i) login (-l) shell to execute (-c) your function:

output = %x{bash -lic 'repository_root'}
like image 118
glenn jackman Avatar answered Jan 27 '26 12:01

glenn jackman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!