I am scripting in Ruby and want to insert a command in the history for the Zshell that calls the Ruby script. I've tried this but it can't access the calling Zshell (I think)
#!/usr/bin/env ruby
`zsh -c print -s what`
Any hints?
I am scripting in Ruby and want to insert a command in the history for the Zshell that calls the Ruby script. I've tried this but it can't access the calling Zshell (I think)
#!/usr/bin/env ruby
`zsh -c print -s what`
Any hints?
One way you can go about doing this is as follows:
Make a zsh function that calls fc -R
after it finishes executing a certain command as follows:
function rb_yourprogram {
ruby /path/to/your/program.rb && fc -R
}
In Ruby, append to the ~/.zsh_history
file:
File.open("~/.zsh_history", "a") do |f|
f.puts "adds this line to history"
end
Now, you can call the program by typing rb_yourprogram
into zsh, and after it finishes executing it will reload the history file and thus will have this new line of history (in addition to anything written into other zsh instances during the time since you opened the first shell).
You could also overload the ruby
command in zsh so that it will always call fc -R
after finishing execution:
function ruby {
builtin ruby "$@" && fc -R
}