diff --git a/libexec/de-sc b/libexec/de-sc index 233ba52..74225c3 100755 --- a/libexec/de-sc +++ b/libexec/de-sc @@ -11,7 +11,11 @@ if ARGV.first == '--complete' else server = ARGV.first + rails_folder = SshHosts.remote_rails_folder(server) + + puts "Connecting..." + SshHosts.remote_command(server, %{ - echo Running console... && cd #{ server }/current; (if test -f script/console ; then ./script/console; else bundle exec rails c; fi) + echo Running console... && cd #{ rails_folder }/current; (if test -f script/console ; then ./script/console; else bundle exec rails c; fi) }) end diff --git a/libexec/de-stl b/libexec/de-stl index c7c1a08..7c309c2 100755 --- a/libexec/de-stl +++ b/libexec/de-stl @@ -10,7 +10,11 @@ if ARGV.first == '--complete' else server = ARGV.first + rails_folder = SshHosts.remote_rails_folder(server) + + puts "Connecting..." + SshHosts.remote_command(server, %{ - tail -n 500 -f #{ server }/shared/log/production.log + tail -n 500 -f #{ rails_folder }/shared/log/production.log }) end diff --git a/libexec/lib/ssh_hosts.rb b/libexec/lib/ssh_hosts.rb index 381fe42..07cd73b 100644 --- a/libexec/lib/ssh_hosts.rb +++ b/libexec/lib/ssh_hosts.rb @@ -1,3 +1,5 @@ +require "yaml" + module SshHosts class << self def host_list_autocomplete @@ -8,8 +10,22 @@ def host_list_autocomplete def remote_command(server, command) system %{ - ssh #{server} -t "bash -i -c '#{ command }'" + ssh #{server} -t "bash -i -c '. ~/.profile; #{ command }'" } end + + def remote_rails_folder(server) + config_file = Dir[File.expand_path("~/.ssh/hosts/**/#{server}.yml")].first + + if File.file?(config_file) + config = YAML.load_file(config_file)[server] + + if config['de'] and config['de']['rails_folder'] + return config['de']['rails_folder'] + end + end + + server + end end end \ No newline at end of file