Last active
December 16, 2015 09:58
Revisions
-
awidegreen revised this gist
Apr 18, 2013 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ # # A call returns a space-seperated string # of the possible completions, e.g.: # ParameterCompletion.getCompletionString("cmd1 diff") # returns: "-1 -2 -s -r" # # The definition of possible completions is done in a hash, see below. @@ -58,11 +58,11 @@ def self.getCompletion(comp_hash, tokens, position) end end def self.getCompletionString(command) tokens = command.split(" ") getCompletion(@@complete_hash, tokens, 0) end end ### example call puts ParameterCompletion.getCompletionString(ARGV.join(" ")) -
awidegreen created this gist
Apr 18, 2013 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,68 @@ #!/usr/bin/env ruby # # This is a wrapper to query the appropiate command/parameter # completions for (t)csh. # # Armin Widegreen (c) 2013 # # A call returns a space-seperated string # of the possible completions, e.g.: # ParameterCompletion.getCompletionList("cmd1 diff") # returns: "-1 -2 -s -r" # # The definition of possible completions is done in a hash, see below. # The implementation relies on the termination of the last hash-element entry # with nil. # # More examples: # in: cm > "cmd1 cmd2" # in: cmd1 di > "diff history" # in: cmd2 d > "" ; no return needed class ParameterCompletion @@complete_hash = { "cmd1" => { "diff" => { "-1" => nil, "-2" => nil, "-s" => nil, "-r" => nil }, "history" => { "-l" => nil, "-a" => nil } }, "cmd2" => { "s" => nil, "d" => nil } } def self.getCompletion(comp_hash, tokens, position) token = tokens[position] if comp_hash[token].is_a?(Hash) # has sub-hash with sub-param return getCompletion(comp_hash[token], tokens, position+1) elsif position == tokens.length - 1 && comp_hash.has_key?(token) # last element and has key, no completion! return "" else # last element (no hash), but no match return comp_hash.keys.join(" ") end end def self.getCompletionList(command) tokens = command.split(" ") getCompletion(@@complete_hash, tokens, 0) end end ### example call puts ParameterCompletion.getCompletionList(ARGV.join(" "))