trentm / go-tool

Automatically exported from code.google.com/p/go-tool
Other
10 stars 8 forks source link

Feature Request: go option for automating bash completion list of users shortcuts #17

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
#!/usr/bin/env ruby -w

# PURPOSE:
#  The go (version 1.2.1) command without bash command-line completion for your 
shortcuts is like a hammer without nails.
#  Unfortunately the go (version 1.2.1) command uses an XML string for the 
'human interface' configuration file.

# IMPORTANT FOLLOW-UP STEP:
#  Add the following line to ~/.bashrc after executing this file 
(go_bash_completion_list.rb) :
#  complete -W "`cat 
/Users/pcs/Projects/Ruby/go_completion/go_bash_completion_list.txt`" go

# SEE ALSO:
#  Run 'man autojump'  and  run 'cdargs --help'. 

dd = "/Users/pcs/Projects/Ruby/go_completion/" # development directory
inputfn = '/Users/pcs/.go/shortcuts.xml'       # input filename 
outputfn = "go_bash_completion_list.txt"       # output filename

# Move old bash completion list for go command into MacOSX Trash folder for 
later dumpster-diving if necessary. 
system("/opt/local/bin/rmtrash #{dd}#{outputfn}") if 
File.exists?("#{dd}#{outputfn}") 

infh = File.new("#{inputfn}", File::RDONLY) # File handle object for reading 
only.
outfh = File.new("#{dd}#{outputfn}", "a+")  # File handle object for appending 
and reading.

infh.each do |line|
  name_list = line.scan(/name="(\w+)"/)
  name_list.each do |ary|
    matchdata = /\[\"(\w+)\"\]/.match("#{ary}")
    outfh.print "#{matchdata[1]} "
  end
end

outfh.rewind
outfh.each {|line| puts line} # Display completion list for eyeballs. 

infh.close
outfh.close

Original issue reported on code.google.com by StearnsP...@gmail.com on 20 Mar 2012 at 6:27

GoogleCodeExporter commented 9 years ago
Makeshift automation ...

alias g=go
alias gl='go --list ; ruby 
/Users/pcs/Projects/Ruby/go_completion/go_bash_completion_list.rb ; cd ~ ; . 
.bashrc ; cd - ;'

Original comment by StearnsP...@gmail.com on 20 Mar 2012 at 7:30