This repository has been archived by the owner on May 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from grosser/autocomplete
add boxen autocomplete
- Loading branch information
Showing
5 changed files
with
90 additions
and
0 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env ruby | ||
|
||
module Boxen | ||
module Autocomplete | ||
# 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 complete(typed) | ||
if part = after(typed, SERVICE_OPTIONS) | ||
available_services.select { |s| s.start_with?(part) } | ||
elsif after(typed, DIR_OPTIONS) | ||
[] | ||
else | ||
OPTIONS.select { |o| o.start_with?(typed[/([a-z-]*)$/,1].to_s) } | ||
end | ||
end | ||
|
||
private | ||
|
||
def after(typed, kind) | ||
typed[/(#{kind.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 | ||
end | ||
|
||
if $0 == __FILE__ | ||
puts Boxen::Autocomplete.complete(ENV["COMP_LINE"]) | ||
end |
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 characters
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 characters
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'spec_helper' | ||
require 'boxen/autocomplete' | ||
|
||
describe Boxen::Autocomplete do | ||
describe ".complete" do | ||
def call(string) | ||
Boxen::Autocomplete.complete(string) | ||
end | ||
|
||
let(:available_services) { ["mysql", "myother", "nginx"] } | ||
|
||
before do | ||
Boxen::Autocomplete.stub(:available_services).and_return(available_services) | ||
end | ||
|
||
it "completes from nothing" do | ||
call("boxen ").should include "-h" | ||
end | ||
|
||
it "completes from partial option" do | ||
call("boxen --res").should == ["--restart-service", "--restart-services"] | ||
end | ||
|
||
it "completes from end of service" do | ||
call("boxen --restart-service").should == ["--restart-service", "--restart-services"] | ||
end | ||
|
||
it "completes from after service" do | ||
call("boxen --restart-service ").should == available_services | ||
end | ||
|
||
it "completes from partial service name" do | ||
call("boxen --restart-service my").should == (available_services - ["nginx"]) | ||
end | ||
|
||
it "completes from after service name" do | ||
call("boxen --restart-service nginx ").should include "-h" | ||
end | ||
|
||
it "completes files after file options" do | ||
call("boxen --logfile ").should == [] | ||
call("boxen --homedir ").should == [] | ||
end | ||
end | ||
end |
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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Autocomplete for boxen | ||
|
||
<% script = File.expand_path("../../lib/boxen/autocomplete.rb", __FILE__) %> | ||
type complete >/dev/null && complete -C <%= script %> -o default boxen |