lib/mkalias.rb in mkalias-0.1.1 vs lib/mkalias.rb in mkalias-0.1.2

- old
+ new

@@ -4,10 +4,13 @@ module Mkalias BASHRC_PATH = "#{File.expand_path('~')}/.bashrc" def self.new_alias(alias_name, command, file_path=BASHRC_PATH) + alias_names = Mkalias.list_alias(file_path) + return false if alias_names.include?(alias_name) + command = command.gsub('#', '$') function_name = "mkalias_#{alias_name}" bash_function = "function #{function_name}(){ #{command}; }" bash_alias = "alias #{alias_name}='#{function_name}'" @@ -15,10 +18,12 @@ open(file_path, 'a') do |file| file.puts("\n") file.puts(bash_alias) file.puts(bash_function) end + + true end def self.list_alias(file_path=BASHRC_PATH) alias_names = Set.new @@ -32,11 +37,11 @@ alias_names.to_a end def self.show_alias(alias_name, file_path=BASHRC_PATH) - alias_names = Mkalias.list_alias + alias_names = Mkalias.list_alias(file_path) return nil unless alias_names.include?(alias_name) alias_regex = /\bmkalias_#{alias_name}[(]/ function_regex = /[{](.*)[;]/ @@ -49,10 +54,10 @@ nil end def self.remove_alias(alias_name, file_path=BASHRC_PATH) - alias_names = Mkalias.list_alias + alias_names = Mkalias.list_alias(file_path) return false unless alias_names.include?(alias_name) alias_regex = /\bmkalias_#{alias_name}[(']/ lines = File.readlines(file_path).reject{ |line| line =~ alias_regex }