lib/aka.rb in aka-0.5.2 vs lib/aka.rb in aka-0.5.4

- old
+ new

@@ -26,46 +26,61 @@ def add string, command debug "string: #{string} command: #{command}" #add a new alias to the list @aliases[string] = command writeOut + info "#{string} added to your alias list." end def remove string - #remove the alias from the list. @aliases.delete string writeOut + info "#{string} removed from your alias list." end def list - #return the list of aliases. keyList = "" @aliases.keys.each{|key| keyList = keyList+" #{key}" } info(keyList) end + def showAll + keyList = "" + @aliases.each{|key, value| keyList = keyList + "#{key}: #{value}\n"} + info keyList + end + def show string - #return the command of a single alias. info(@aliases[string]) end def empty - #empty out the file. - backup # So we don't have deleter's remorse. - @aliases = {} - writeOut + info "Would you like to create a backup before deleting? (y/n/a)" + backConfirm = gets.chomp.downcase + if backConfirm.start_with? "y" + backup + @aliases = {} + writeOut + info "Alias list deleted." + elsif backConfirm.start_with? "a" + info "Alias list deletion aborted." + elsif backConfirm.start_with? "n" + @aliases = {} + writeOut + info "Alias list deleted." + else + info "I didn't understand your response; so your file was not deleted." + end end def backup FileUtils.copy(@fileName,"#{@fileName}.bak") + info "Backup created as #{@fileName}.bak" end def writeOut filestring = "" - @aliases.each { |key, value| filestring = filestring + "alias #{key}=\"#{value}\"\n" } - + @aliases.sort.each { |key, value| filestring = filestring + "alias #{key}=\"#{value}\"\n" } File.open(@fileName, "w") { |file| file.write filestring } - - #write out the list. This will be called after any method that changes something. end end end