Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #40 from hakamadare/bash_completion
Browse files Browse the repository at this point in the history
enable installation of bash completion
  • Loading branch information
jhaals committed Jun 9, 2014
2 parents 701820e + 565559e commit 2610a03
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/.bundle
/.rake_t_cache
/.ruby-version
/spec/fixtures/.librarian
/spec/fixtures/.tmp
/spec/fixtures/Puppetfile.lock
/spec/fixtures/modules/boxen/
/spec/fixtures/modules/*
/spec/fixtures/vendor
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ Install [Vagrant](http://www.vagrantup.com/) on your Mac.
## Usage

```puppet
include vagrant
class { 'vagrant': }
```
By default, the module will install Vagrant 1.6.3. You can specify a different version of Vagrant to install (minimum version is 1.4.0 due to download locations). To install Vagrant 1.4.0, you would specify the version as follows:

```puppet
class { 'vagrant':
version => '1.6.3'
version => '1.4.0'
}
```

Expand All @@ -40,6 +40,39 @@ vagrant::box { 'squeeze64/vmware_fusion':
}
```

Bash Completion
--

[Bash](https://www.gnu.org/software/bash/) supports tab-completion for commands, _i.e._ you can type part of a command, then press Tab, and Bash will attempt to determine what command you have begun typing and then complete the command for you. By default, Bash can only complete commands by searching `$PATH`; to enable completion for commands that have subcommands (like `vagrant`), you need to add additional Bash configuration.

To install this configuration automatically, invoke this class as follows:

```puppet
class { 'vagrant':
completion => true,
}
```

This will install a [Homebrew](http://brew.sh/) package that provides the necessary configuration. Once you have done so, **RESTART YOUR SHELL**, and then you'll be able to do something like the following:

```console
$ vagrant <TAB><TAB>
box docker-run init plugin resume ssh up
connect global-status list-commands provision rsync ssh-config version
destroy halt login rdp rsync-auto status
docker-logs help package reload share suspend
$ vagrant bo<TAB>
$ vagrant box <TAB><TAB>
add help list remove repackage
$ vagrant box li<TAB>
$ vagrant box list <RETURN>
puppetlabs/centos-6.5-64-puppet (vmware_desktop, 0.2.0)
$
```

## Required Puppet Modules

* `boxen`
* `homebrew`
* `repository`
* `stdlib`
23 changes: 21 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,33 @@
#
# include vagrant

class vagrant($version = '1.6.3') {
class vagrant(
$version = '1.6.3',
$completion = false
) {
validate_bool($completion)

$ensure_pkg = $completion ? {
true => 'present',
default => 'absent',
}

package { "Vagrant_${version}":
ensure => installed,
source => "https://dl.bintray.com/mitchellh/vagrant/vagrant_${version}.dmg",
provider => 'pkgdmg'
}

file { "/Users/${::boxen_user}/.vagrant.d":
ensure => directory
ensure => directory,
require => Package["Vagrant_${version}"],
}

homebrew::tap { 'homebrew/completions': }

package { 'vagrant-completion':
ensure => $ensure_pkg,
provider => 'homebrew',
require => Homebrew::Tab['homebrew/completions'],
}
}
10 changes: 10 additions & 0 deletions spec/classes/vagrant_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'spec_helper'

describe 'vagrant' do
let (:facts) { default_test_facts }

describe 'when not specifiying a version' do
it { should contain_package('Vagrant_1.6.3').with({
:ensure => 'installed',
Expand All @@ -15,4 +17,12 @@
it { should contain_package('Vagrant_1.5.0').with_source('https://dl.bintray.com/mitchellh/vagrant/vagrant_1.5.0.dmg')}
end

describe 'when installing bash completion' do
let (:params) {{:completion => true}}

it { should contain_package('Vagrant_1.6.3')}
it { should contain_package('Vagrant_1.6.3').with_source('https://dl.bintray.com/mitchellh/vagrant/vagrant_1.6.3.dmg')}
it { should contain_package('vagrant-completion').with_provider('homebrew')}
end

end
5 changes: 4 additions & 1 deletion spec/fixtures/Puppetfile
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
mod 'boxen', '3.6.0', :github_tarball => 'boxen/puppet-boxen'
mod 'boxen', '3.3.3', :github_tarball => 'boxen/puppet-boxen'
mod 'homebrew', '1.9.3', :github_tarball => 'boxen/puppet-homebrew'
mod 'repository', '2.3.0', :github_tarball => 'boxen/puppet-repository'
mod 'stdlib', '4.1.0', :github_tarball => 'puppetlabs/puppetlabs-stdlib'
6 changes: 4 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

def default_test_facts
{
:boxen_user => "testuser",
:boxen_home => "/test/boxen"
:boxen_user => "testuser",
:boxen_home => "/test/boxen",
:boxen_repodir => "/test/boxen/our-boxen",
:boxen_srcdir => "/test/boxen/src",
}
end

0 comments on commit 2610a03

Please sign in to comment.