Skip to content

Instantly share code, notes, and snippets.

@bobthecow
Created June 5, 2012 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bobthecow/2877277 to your computer and use it in GitHub Desktop.
Save bobthecow/2877277 to your computer and use it in GitHub Desktop.
#!bash
#
# nanoc-completion
# ================
#
# Bash completion support for nanoc
#
#
# Installation
# ------------
#
# 1. Install this file. Either:
#
# a. Place it in a `bash-completion.d` folder:
#
# * /etc/bash-completion.d
# * /usr/local/etc/bash-completion.d
# * ~/bash-completion.d
#
# b. Or, copy it somewhere (e.g. ~/.nanoc-completion.sh) and put the following line in
# your .bashrc:
#
# source ~/.nanoc-completion.sh
#
#
#
# The Fine Print
# --------------
#
# Copyright (c) 2012 [Justin Hileman](http://justinhileman.com)
#
# Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
__nanoc ()
{
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
local prev="${COMP_WORDS[COMP_CWORD-1]}"
local subcommands="$(ruby -e 'require "nanoc" ; require "nanoc/cli" ; Nanoc::CLI.setup ; puts Nanoc::CLI.root_command.subcommands.map{|c|c.name}.join(" ")')"
[[ ${COMP_CWORD} -eq 1 ]] && {
COMPREPLY=( $(compgen -W "${subcommands}" -- ${cur}) )
return
}
case "${prev}" in
help)
COMPREPLY=( $(compgen -W "${subcommands}" -- ${cur}) )
return 0
;;
*)
;;
esac
}
complete -F __nanoc nanoc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment