#!/usr/bin/env ruby ## Se guarda en /usr/local/bin/cosa, se le da permisos con chmod a+x /usr/local/bin/cosa y se ## ejecuta con cosa paquete, asi de simple ^^ require 'open3' TARGET = ARGV.first APT_SEARCH = "apt-cache search #{TARGET}" class AptCache def self.parse(pkgdesc) if pkgdesc =~ /([\w\-\_]+)\s-\s(.+)$/ AptCache.show $1 end end def self.show(pkg) Open3.popen3("apt-cache show #{pkg}") { |stdin, stdout, stderr| hash = {} stdout.each { |line| if line =~ /(\w+):\s(.+)$/ hash[$1.downcase.to_sym] = $2 end } installed = AptCache.installed?(pkg) print " \033[92m*\033[00m #{hash[:section]}/\033[01m#{hash[:package]}\033[00m " if installed puts "[\033[42mINSTALLED\033[00m]" else puts "" end puts " \033[32mVersion:\033[00m \033[96m#{hash[:version]}\033[00m" if hash.has_key? :homepage puts " \033[32mHomepage:\033[00m #{hash[:homepage]}" end puts " \033[32mDescription:\033[00m #{hash[:description]}" puts "" } end def self.installed?(pkg) Open3.popen3("dpkg -l #{pkg}") { |stdin, stdout, stderr| stdout.each { |line| if line =~ /^ii\s+#{pkg}\s+/ return true end } } false end end begin Open3.popen3(APT_SEARCH) { |stdin, stdout, stderr| stdout.each { |line| AptCache.parse(line) } } rescue Interrupt end #Fin