Sha256: 3b109cffb42e04f5539fa784eb634f3a7e448b4f781d091f8b331318daa98d1f
Contents?: true
Size: 1.92 KB
Versions: 4
Compression:
Stored size: 1.92 KB
Contents
#!/usr/bin/env ruby # NOTE 2018.02.22 # This was a start at implementing Bash autocomplete, obviously copied # over from Boxen. Keep around for ref 'cause I really want autocomplete # ASAP. # require_relative '../lib/rash' module Rash; end module Rash::Autocomplete COMMANDS = ['profile', 'call', 'test', 'help'] # refresh options via: ruby -e 'puts `boxen -h 2>/dev/null`.scan(/\-+[a-z\?-]+/).inspect' # OPTIONS = ["--debug", "--pretend", "--noop", "--report", "--env", "-h", "-?", "--help", "--disable-service", "--enable-service", "--restart-service", "--disable-services", "--enable-services", "--restart-services", "--list-services", "--homedir", "--logfile", "--login", "--no-fde", "--no-pull", "--no-issue", "--stealth", "--token", "--profile", "--future-parser", "--projects", "--srcdir", "--user", "--no-color"] # SERVICE_OPTIONS = OPTIONS.select { |o| o.end_with?("-service") } # DIR_OPTIONS = ["--logfile", "--homedir"] class << self def functions Rash.load_functions Rash.function_names end def complete typed # return ['a', 'b', 'c'] if part = after(typed, COMMANDS) if after(typed, ['call']) functions.select {|name| name.downcase.start_with? part.downcase } else ['x'] end # elsif after(typed, DIR_OPTIONS) # [] else COMMANDS.select { |o| o.start_with?(typed[/([a-z-]*)$/,1].to_s) } end end private def after typed, kind escaped = kind.map {|str| Regexp.escape str} typed[/(#{escaped.join("|")})\s+([^\s]*)?$/, 2] end # keep in sync with boxen/service.rb def available_services Dir["/Library/LaunchDaemons/dev.*.plist"].map { |f| f[/dev\.(.*)\.plist/, 1] } end end end if $0 == __FILE__ puts Rash::Autocomplete.complete(ENV["COMP_LINE"]) end # complete -o default -C "${GH}/nrser/rash/bin/autocomplete.rb" rash
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
nrser-rash-0.2.3 | dev/ref/autocomplete.rb |
nrser-rash-0.2.2 | dev/ref/autocomplete.rb |
nrser-rash-0.2.1 | dev/ref/autocomplete.rb |
nrser-rash-0.2.0 | dev/ref/autocomplete.rb |