Class: Screeninator::ConfigWriter
- Inherits:
-
Object
- Object
- Screeninator::ConfigWriter
- Includes:
- Helper
- Defined in:
- lib/screeninator/config_writer.rb
Constant Summary
Constants included from Helper
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename) ⇒ ConfigWriter
constructor
A new instance of ConfigWriter.
- #write! ⇒ Object
Methods included from Helper
Constructor Details
#initialize(filename) ⇒ ConfigWriter
Returns a new instance of ConfigWriter.
11 12 13 14 15 |
# File 'lib/screeninator/config_writer.rb', line 11 def initialize(filename) @filename = filename @file_path = "#{root_dir}#{@filename}.yml" process_config! end |
Class Method Details
.write_aliases(aliases) ⇒ Object
7 8 9 |
# File 'lib/screeninator/config_writer.rb', line 7 def self.write_aliases(aliases) File.open("#{ENV["HOME"]}/.screeninator/scripts/screeninator", 'w') {|f| f.write(aliases.join("\n")) } end |
Instance Method Details
#write! ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/screeninator/config_writer.rb', line 17 def write! if File.exists?(USER_SCREEN_CONFIG) template = USER_SCREEN_CONFIG else template = "#{File.dirname(__FILE__)}/assets/screen_config.screen" end erb = ERB.new(IO.read(template)).result(binding) config_path = "#{root_dir}#{@filename}.screen" tmp = File.open(config_path, 'w') {|f| f.write(erb) } @project_name.gsub!(" ", "_") check = "screen -ls | grep #{@project_name}" attch = "screen -dr #{@project_name}" start = "screen -c #{config_path} -S #{@project_name}" %Q{alias start_#{@filename}='if [[ -n `#{check}` ]] ; then `#{attch}` ; else `#{start}`; fi'} end |