Skip to content

Commit

Permalink
Merge pull request #17 from glittershark/1/bash_completion
Browse files Browse the repository at this point in the history
Add bash completion
  • Loading branch information
glittershark committed Aug 13, 2014
2 parents 405b453 + f3ae00f commit a5f6165
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
30 changes: 20 additions & 10 deletions README.md
Expand Up @@ -6,29 +6,39 @@

# Projectionist

Quickly edit project files using the [.projections.json](https://github.com/tpope/vim-projectionist) format
Quickly edit project files using the
[.projections.json](https://github.com/tpope/vim-projectionist) format

## Installation

$ gem install projectionist

There's also a bash completion script, that you can install globally by running:

```bash
$ curl -OL
https://github.com/glittershark/projectionist/raw/master/completion.bash
```

or locally by downloading [this
file](https://github.com/glittershark/projectionist/raw/master/completion.bash)
and sourcing it in your `~/.bashrc`

Zsh completion is on the way!

## Usage

For ease of typing, the executable file for projectionist is `prj`.

Given a `.projections.json` file in the root of your project with the following structure:
Given a `.projections.json` file in the root of your project with the following
structure:

```
{
"lib/**/*.rb": {
"type": "lib"
}
}
```
``` { "lib/**/*.rb": { "type": "lib" } } ```

The command to edit `lib/whatever/test.rb` would be:

$ prj edit lib whatever/test

Note that there are two glob components here - `**` and `*`. When editing files, these components are separated by a `/`
Note that there are two glob components here - `**` and `*`. When editing files,
these components are separated by a `/`

30 changes: 30 additions & 0 deletions completion.bash
@@ -0,0 +1,30 @@
#!/bin/bash

_prj()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cmds="edit help list types"

case $prev in
prj | help)
COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) )
return 0
;;
edit | types)
types=$(prj types)
COMPREPLY=( $(compgen -W "${types}" -- ${cur}) )
;;
*)
# Test if we're editing a type
if [ "${COMP_WORDS[COMP_CWORD-2]}" = 'edit' ]; then
files=$(prj list ${prev})
COMPREPLY=( $(compgen -W "${files}" -- ${cur}) )
fi
;;
esac
}
complete -F _prj prj

0 comments on commit a5f6165

Please sign in to comment.