Skip to content

Instantly share code, notes, and snippets.

@meise
Created November 9, 2012 17:46
Show Gist options
  • Save meise/4047098 to your computer and use it in GitHub Desktop.
Save meise/4047098 to your computer and use it in GitHub Desktop.
zsh completion builder for shorewall and shorewall6 main commands
#!/usr/bin/env ruby
# encoding: utf-8
require 'pathname'
['shorewall', 'shorewall6'].each do |shorewall_version|
if %x{whereis #{shorewall_version}}.split[1].nil?
puts "#{shorewall_version} not installed."
else
commands = {}
%x{sudo #{shorewall_version}}.split(/\n/).each do |command|
if command =~ /^\ \ \ /
command = command.gsub(' ', '').split
commands[command[0]] = ''
end
end
file_content =<<FILE
#compdef #{shorewall_version}
_arguments \\
':command:(#{commands.map{|l,a| l.to_s}.join(' ')})'
FILE
File.open(output_file = Pathname.pwd + "_#{shorewall_version}", 'w') do |file|
file << file_content
end
puts "#{output_file} created."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment