Method: Morpheus::Cli::DotFile#remove_aliases
- Defined in:
- lib/morpheus/cli/dot_file.rb
#remove_aliases(alias_names) ⇒ Object
this saves the source file, removing alias definitions at the bottom todo: smarter logic to allow the user to put stuff AFTER this section too under the section titled ‘# exported aliases’
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/morpheus/cli/dot_file.rb', line 149 def remove_aliases(alias_names) if !@filename print "#{Term::ANSIColor.dark}Skipping source file save because filename has not been set#{Term::ANSIColor.reset}\n" if Morpheus::Logging.debug? return false end if !Dir.exist?(File.dirname(@filename)) FileUtils.mkdir_p(File.dirname(@filename)) end if !File.exist?(@filename) print "#{Term::ANSIColor.dark}Initializing source file #{@filename}#{Term::ANSIColor.reset}\n" if Morpheus::Logging.debug? FileUtils.touch(@filename) else print "#{dark} #=> Saving source file #{@filename}#{reset}\n" if Morpheus::Logging.debug? end config_text = File.read(@filename) config_lines = config_text.split(/\n/) new_config_lines = config_lines.reject {|line| alias_names.find {|alias_name| /^alias\s+#{Regexp.escape(alias_name)}\s?\=/ } } new_config_text = new_config_lines.join("\n") File.open(@filename, 'w') {|f| f.write(new_config_text) } return true end |