Skip to content

Instantly share code, notes, and snippets.

@BanzaiMan
Created October 20, 2009 00:19
Show Gist options
  • Select an option

  • Save BanzaiMan/213868 to your computer and use it in GitHub Desktop.

Select an option

Save BanzaiMan/213868 to your computer and use it in GitHub Desktop.
module Termtter::Client
config.plugins.edit_plugin.set_default(:local_dir, File.join(config.system.conf_dir, 'plugins'))
config.plugins.edit_plugin.set_default(:editor, ENV["EDITOR"] || ENV["VISUAL"] || '')
if config.plugins.edit_plugin.editor.empty?
warn "Unable to determine appropriate editor command"
return
end
register_command(
:name => :edit_plugin,
:aliases => [:ep],
:help => ["edit_plugin", "opens editor to edit the specified local plugin"],
:completion_proc => lambda {|cmd, arg|
Dir.entries(config.plugins.edit_plugin.local_dir).select{ |f| f =~ /^[^\.]\S*\.rb$/}.map{|f| "#{cmd} #{f}"}
},
:exec => lambda { |plugin|
raise ArgumentError, "plugin name not specified" if plugin.empty?
plugin += ".rb" unless plugin =~ /\.rb$/
begin
cmd = [
"exec",
config.plugins.edit_plugin.editor,
File.join(config.plugins.edit_plugin.local_dir,plugin)
]
call_commands(cmd.join(" "))
rescue Exception => e
handle_error(e)
end
}
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment