Module: Scide
- Defined in:
- lib/scide.rb,
lib/scide/auto.rb,
lib/scide/list.rb,
lib/scide/open.rb,
lib/scide/setup.rb,
lib/scide/program.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'1.0.0'
- SCREEN_BIN =
'screen'
- SCREEN_OPTIONS =
'-U'
Class Method Summary collapse
- .auto?(options = {}) ⇒ Boolean
- .auto_config ⇒ Object
- .auto_config_file {|file| ... } ⇒ Object
- .list(options = {}) ⇒ Object
- .open(*args) ⇒ Object
- .setup(*args) ⇒ Object
Class Method Details
.auto?(options = {}) ⇒ Boolean
24 25 26 |
# File 'lib/scide/auto.rb', line 24 def self.auto? = {} [:auto] or (ENV['SCIDE_AUTO'] and ENV['SCIDE_AUTO'].match(/\A(1|y|yes|t|true)\Z/i)) end |
.auto_config ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/scide/auto.rb', line 4 def self.auto_config # TODO: option to specify custom default configuration file String.new.tap do |c| c << %|source $HOME/.screenrc\n\n| if File.exists? home_config_file c << %|screen -t editor 0\n| c << %|stuff "\\${PROJECT_EDITOR-\\$EDITOR}\\012"\n| c << %|screen -t shell 1\n| c << %|select editor| end end |
.auto_config_file {|file| ... } ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/scide/auto.rb', line 15 def self.auto_config_file file = Tempfile.new 'scide' file.write auto_config file.rewind file.close yield file file.unlink end |
.list(options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/scide/list.rb', line 4 def self.list = {} dir = projects_dir projects = [] config_file = '.screenrc' projects << '.' if Dir.pwd != File.('~') and File.file?(config_file) if File.directory? dir Dir.entries(dir).each do |project| next if project.match /\A\.+\Z/ project_dir = File.join dir, project next unless File.directory? project_dir config_file = File.join project_dir, '.screenrc' next unless File.file? config_file projects << project end elsif projects.empty? error %/No such directory "#{dir}"/ end projects end |
.open(*args) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/scide/open.rb', line 6 def self.open *args error "screen must be in the path" unless Which.which 'screen' = args.last.kind_of?(Hash) ? args.pop : {} dir = current_project_dir args, file = File.join dir, '.screenrc' exists = File.exists? file if auto?() and !exists auto_config_file do |auto_file| return run dir, .merge(screenrc: auto_file.path) end end error %/No such configuration "#{file}"/ unless exists error %/"#{file}" is not a file/ unless File.file? file run dir, end |
.setup(*args) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/scide/setup.rb', line 4 def self.setup *args = args.last.kind_of?(Hash) ? args.pop : {} dir = current_project_dir args, file = File.join dir, '.screenrc' error "#{file} already exists" if File.exists? file File.open(file, 'w'){ |f| f.write auto_config } file end |