From ce90e571393614254112c052ad4813768e8d84f0 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 26 Mar 2018 12:19:58 +0100 Subject: [debian] Now supports abbreviations --- debian | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'debian') diff --git a/debian b/debian index 2c33d59..96fe225 100755 --- a/debian +++ b/debian @@ -1,17 +1,19 @@ #!/usr/bin/env ruby +require 'abbrev' + $map = [ %w( buzz 1.1 ), %w( rex 1.2 ), %w( bo 1.3 ), - %w( hamm 2.0 2 ), + %w( hamm 2.0 ), %w( slink 2.1 ), %w( potato 2.2 ), - %w( woody 3.0 3 ), + %w( woody 3.0 ), %w( sarge 3.1 ), - %w( etch 4.0 4 ), - %w( lenny 5.0 5 ), - %w( squeeze 6.0 6 ), + %w( etch 4.0 ), + %w( lenny 5.0 ), + %w( squeeze 6.0 ), %w( wheezy 7 ), %w( jessie 8 ), %w( stretch 9 ), @@ -37,10 +39,14 @@ def extras(keys) end def find(elem) - s = $map.map { |entry| + we = $map.map { |entry| entry + extras(entry) - }.select { |entry| - entry.include?(elem) + } + + ab = Abbrev.abbrev(we.flatten) + + s = we.select { |entry| + entry.include?(ab[elem]) }.first return nil if s.nil? return s - [elem] @@ -56,7 +62,7 @@ key = ARGV.shift.strip.downcase res = find(key) if res.nil? then - puts "No such key" + puts "No such key or ambiguous abbreviation" exit 1 end -- cgit v1.2.1