Created
November 9, 2012 17:46
-
-
Save meise/4047098 to your computer and use it in GitHub Desktop.
zsh completion builder for shorewall and shorewall6 main commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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