class Warp::Dir::Command::Install
Attributes
existing[RW]
installed[RW]
shell_init_files[RW]
wrapper[RW]
Public Class Methods
already_installed?(file_path)
click to toggle source
# File lib/warp/dir/command/install.rb, line 20 def already_installed?(file_path) path = ::Warp::Dir.absolute(file_path) if File.exist?(path) File.open path do |file| file.find { |line| line =~ ::Warp::Dir::SHELL_WRAPPER_REGX } end end end
new(*args)
click to toggle source
Calls superclass method
Warp::Dir::Command::new
# File lib/warp/dir/command/install.rb, line 30 def initialize(*args) self.installed = [] self.existing = [] self.wrapper = ::Warp::Dir::SHELL_WRAPPER_SRCE self.shell_init_files = ::Warp::Dir::DOTFILES super(*args) end
wrapper_installed?()
click to toggle source
# File lib/warp/dir/command/install.rb, line 16 def wrapper_installed? ::Warp::Dir::DOTFILES.any?{ |file| already_installed?(file) } end
Public Instance Methods
run(*args)
click to toggle source
# File lib/warp/dir/command/install.rb, line 38 def run(*args) self.shell_init_files = config[:dotfile].split(',') if config[:dotfile] self.shell_init_files.any? { |dotfile| append_wrapper_to(dotfile) } # Overwrites if already there install_bash_wd local_existing = self.existing local_installed = self.installed local_shell_files = self.shell_init_files if installed.empty? if existing.empty? on :error do if local_shell_files.size > 1 then message "Shell init files #{local_shell_files.join(', ').yellow.bold} were not found on the filesystem.".red else message "Shell init file #{local_shell_files.join(', ').yellow.bold} was not found on the filesystem.".red end end else on :error do message 'Looks like you already have shell support installed.'.red message "#{local_existing.join(', ').yellow.bold} already warp-dir definition. Use --force to override." end end else on :success do message 'Shell support is installed in the following files:'.green.bold message "#{local_installed.join(', ')}".bold.yellow end end end
Private Instance Methods
append_wrapper_to(shell_init_file)
click to toggle source
# File lib/warp/dir/command/install.rb, line 82 def append_wrapper_to(shell_init_file) file = ::Warp::Dir.absolute(shell_init_file) pre_installed = self.class.already_installed?(file) self.existing << file if pre_installed if File.exist?(file) && (!pre_installed || config[:force]) source = File.read(file) source.gsub!(/# WarpDir.*BEGIN\n.*\n# WarpDir.*END/, '') File.open(file, 'w') do |f| f.write source f.write wrapper end self.installed << shell_init_file end end
install_bash_wd()
click to toggle source
# File lib/warp/dir/command/install.rb, line 74 def install_bash_wd source = File.read(::Warp::Dir::SHELL_WRAPPER_FILE) source.gsub!(/%WARP-DIR%/, "WarpDir (v#{::Warp::Dir::VERSION})") File.open(::Warp::Dir::SHELL_WRAPPER_DEST, 'w') do |file| file.puts source end end