Giter VIP home page Giter VIP logo

compleat's Introduction

Compleat

Generate tab completion for any shell command by specifying its usage in a familiar manpage-like format. For example, a usage specification for top(1):

top [-b | -c | -H | -i | -s | -S | -d <delay> | -n <num> | -p <pid> ...] ... ;
top (-h|-v)

Supported shells are bash, fish, and zsh.

Installation

Get the source code: git clone git://github.com/mbrubeck/compleat.git

Next, install Stack.

To install Compleat in your system, run:

make install

This will install the compleat binary into ~/.local/bin and the compleat_setup script into $BASH_COMPLETION_USER_DIR (defaults to $XDG_DATA_HOME/bash-completion/completions or ~/.local/share/bash-completion/completions):

bash

To enable compleat in bash, add the following line to your .bashrc. (Adjust the path if you configured with a custom prefix.)

source ${BASH_COMPLETION_USER_DIR}/compleat_setup

and install your .usage files in a directory named /etc/compleat.d or ~/.compleat:

mkdir ~/compleat
cp examples/* ~/compleat

Restart your shell to begin using completions:

exec bash

zsh

zsh support requires zsh >= 4.2.1, and currently uses zsh's bash-compatibility mode rather than taking advantage of zsh's extended completion features.

To enable compleat in zsh, make the following change to your .zshrc. (Adjust the path if you configured with a custom prefix.)

If you used the zsh wizard (zsh-newuser-install) to set up your zshrc, it should contain lines like the following (if they don't exist, simply add the lines in the change below):

autoload -Uz compinit
compinit

Change these to:

autoload -Uz compinit bashcompinit
compinit
bashcompinit

source ~/.bash_completion.d/compleat_setup

and install your .usage files in a directory named /etc/compleat.d or ~/.compleat:

sudo mkdir /etc/compleat.d
sudo cp examples/* /etc/compleat.d

Restart your shell to begin using completions:

exec zsh

fish

To install the fish completion file, run:

make install-fish

To enable compleat in fish, add the following line to your ~/.config/fish/config.fish.

source ~/.config/fish/compleat_setup.fish

and install your .usage files in a directory named /etc/compleat.d or ~/.compleat:

mkdir ~/compleat
cp examples/* ~/compleat

Restart your shell to begin using completions:

exec fish

Testing

Type top and then press Tab a few times to see the example files in action.

Syntax

A usage file contains commands and definitions, separated by semicolons.

A command consists of a command name followed by a pattern. The command name can be any atom. If there is more than one command in the file, compleat will attempt to match each of them against the input line.

An atom consists of letters, numbers, and any of the characters -_/@=+.,:, or any string enclosed in double quotes with C/Java-style backslash escapes.

The following are valid patterns:

  • Any atom matches itself: foo matches the string foo. "x\\y" matches the string x\y.
  • a b matches a followed by b.
  • a b | c matches either a b or c.
  • [a] matches zero or one occurrences of a.
  • a ... matches one or more occurrences of a.
  • [a] ... matches zero or more occurrences of a.

Use parentheses to group patterns:

  • a (b | c) matches a followed by either b or c.
  • (a | b) ... matches a or b followed by any number of additional a or b.

Patterns may also include variables:

  • name = value; defines a new variable. The name can be any atom, and the value can be any pattern. Then <name> in a pattern refers to the value as a sub-pattern.

  • name = !command; defines a variable that uses a shell command to generate suggested completions. The shell command should print one suggested completion per line. The $COMP_LINE and $COMP_CWORD environment will contain the input line and the current word being completed.

  • If no value is defined for name, then the pattern <name> will match any word.

Copyright

Copyright (c) 2009 Matt Brubeck

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

compleat's People

Contributors

chocolateboy avatar ehamberg avatar jaimemf avatar jean avatar mbrubeck avatar mdippery avatar michelk avatar smacke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

compleat's Issues

Problem creating a completion file for "vv"

Hi,

I have created a simple completion file for vv, a medical image viewer:

image = !ls -1 | grep -E '\.(mhd|dcm|png|jpg|vox)$' ;
vector = !ls -1 | grep -E '(\.vf|.*vf.*\.mhd)$' ;

vv <image> [ <image> | --vf <vector> | --overlay <image> ] ...

The first word () is completed alright, however if I type the following:

vv 4d_lungs_iso2.mhd --vf

in a directory containing the following files:

4d_from_60_to_50_iso2.mhd  4d_lungs_iso2.mhd  stats        vf_demon_4d_60_to_50.mhd  vf_ffd_4d_60_to_all.mhd
4d_from_60_to_50_iso2.raw  4d_lungs_iso2.raw  ventilation  vf_demon_4d_60_to_50.raw  vf_ffd_4d_60_to_all.raw

I get the following completions:

4d_from_60_to_50_iso2.mhd   --overlay                   vf_demon_4d_60_to_50.mhd
4d_lungs_iso2.mhd           --vf                        vf_ffd_4d_60_to_all.mhd

when I would expect:

vf_demon_4d_60_to_50.mhd  vf_ffd_4d_60_to_all.mhd

Am I missing something? Or is this a bug?

import error on build

I know nothing about haskell, and I can't get it to build. Found this on SO. So I'm guessing that wherever Prelude is being imported, it needs to be prefixed with base? But I can't even find where the import is.

$ ./Setup.lhs build
Building compleat-1.0...
Preprocessing executable 'compleat' for compleat-1.0...

compleat.hs:1:1:
    Ambiguous module name `Prelude':
      it was found in multiple packages: base haskell98-2.0.0.1

Can't build

When I get tot the build step: $ ./Setup.lhs build

I get this error:

Top level:
    Ambiguous interface for `Prelude':
      it was found in multiple packages: base haskell98-2.0.0.1

I tried removing haskell98 from the cabal file as suggested here http://hackage.haskell.org/trac/ghc/ticket/4958 but then I get this error:


Completer.hs:10:8:
    Could not find module `IO'
    It is a member of the hidden package `haskell98-2.0.0.1'.
    Perhaps you need to add `haskell98' to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.

Which I think is way beyond my possibilities to solve, since I have never use Haskell before.

Trouble with sudo completion.

BASH completion for "sudo foo" works as expected when the "foo" completion is provided by the bash_completion package or written manually with the BASH completion API.

However, it refuses to work for completions generated by Compleat.
sudo open[tab] results in the error bellow:

sudo open -bash: compgen: warning: -C option may not work as you expect
compleat: : openFile: does not exist (No such file or directory)
/Users/sorin/.compleat/open.usage

This is my open.usage for the Mac OS X open command:
open [-a (|) | -b | -e | -t | -R | --reveal | -f];
open [-a ] [-g | --background | -n | --new | -W | --wait-apps] [--args] ;
open [-h | --header ];
application = !mdfind 'kMDItemKind == Application' | awk 'BEGIN {FS=OFS="/"} {print $NF}' | sed 's/ /\ /g';
identifier = !mdfind 'kMDItemKind == Application' | sed -e 's/ /\ /g' -e "s:':\':g" | xargs -n 1 mdls | grep 'kMDItemCFBundleIdentifier' | cut -d '=' -f 2 | sed 's/^ "(.*)"$/\1/g'

Issue with combining positional arguments generated by shell commands.

Howdy,

Thanks a ton for the awesome work on Compleat.

I ran into an issue while attempting to create a usage file for the program vcsh. I've included the minimum needed to see the issue.

repo = !vcsh list ;
git-command = !git help -a | egrep '^  [a-zA-Z0-9]' | grep -ve '--' | xargs -n 1 echo ;

vcsh rename <repo> <new-name>;
vcsh <repo> <git-command>;
vcsh <repo>;

The line vcsh <options> <repo> <git-command>; seems to "pollute" the completion for all occurrences of <repo>. As a result, typing vcsh rename <TAB> will list both the output of the <repo> substitution and the <git-command> substitution.

Interestingly (to me, at least), typing vcsh <TAB> gives what I'd expect: the output of the <repo> substitution plus the atom rename.

I'm not sure what's causing this. Any help would be appreciated. Let me know if there's anything I can do to collect debugging information.

Thanks!

Colons in an atom?

Hello (again),

I'm trying to write a usage file for the Heroku command line tool, and it uses a colon as a namespace separator in its command line. I'm trying to write a usage file along these lines:

heroku access <opts>;
heroku access:add <email> <opts>;

I'm not sure if a colon in an atom is disallowed, but escaping the colon with \ doesn't work. Is this possible? My Haskell is a bit rusty so I'm not able to follow Usage.hs easily. Any help would be appreciated.

Thanks!

README is confusing

One of the first lines reads:

The only supported shells at the moment are bash and zsh.

Later on it specifies instructions on how to use compleat in fish, I presume you support all three and not just bash and zsh?

spacing problem

Hi

I wanted to create a completion for the following pattern:

app -P profileX,profileY,profileZ

by doing this

app (..... | -P <profile>[,<profile>] ...)

but through compleat i get

app -P profileX , profileY , profileZ

Am i doing something wrong or is it somehow possible to get rid of the spacing?

Data-Files: on OS X are not placed

After installing haskell like brew cask install haskell-platform, and following the install steps for compleat, the bin file is moved into place, but the /usr/local/share/compleat-1.0/compleat_setup file does not exist.

To fix this, I moved it manually like cp compleat_setup /usr/local/share/compleat-1.0/.

XDG Config

Enabling $HOME/.config/compleat or $HOME/.cache/compleat rather than ~/.compleat.

Completion for `ls`

How ls.usage should look like?

$ man ls
SYNOPSIS
    ls [-ABCFGHLPRTWZabcdefghiklmnopqrstuwx1] [file ...]

$ echo "ls [-ABCFGHLPRTWZabcdefghiklmnopqrstuwx1] [file ...]" > ~/.compleat/ls.usage
$ exec bash
$ ls -↹
$ ls -ABCFGHLPRTWZabcdefghiklmnopqrstuwx1

( is a tab key)

This is not what I'm expecting. Ok, another try:

$ echo "ls [-(A|B|C|F|G|H|L|P|R|T|W|Z|a|b|c|d|e|f|g|h|i|k|l|m|n|o|p|q|r|s|t|u|w|x|1)] [<file> ...]" > ~/.compleat/ls.usage
$ exec bash
$ ls ↹
$ ls - 

Instead of file listing - added.

$ ls - ↹
1   B   F   H   P   T   Z   b   d   f   h   k   m   o   q   s   u   x   
A   C   G   L   R   W   a   c   e   g   i   l   n   p   r   t   w

Space after - should not exist.

BTW, the idea of compleat is really elegant. I like it.

README update: libghc-parsec3-dev

Ubuntu 16 ships with libhgc-parsec3-dev (instead of parsec2 as noted in the README).

(This successfully fulfills the requirement parsec >=2 && <4 and compleat built clean for me with ghc7).

Output Completion Script

Hi,

can I use compleat to output a bash/zsh/fish/... completion script based on the tools usage signature (or --help) output instead of letting it auto-complete it interactively?

I know it's less fancy as the full compleat functionality but such a auto-generator would be super-handy for shipping completions and auto-generating them, e.g. before a software release. (It also just introduces a software dependency for the dev side but not for the user side.)

command not found

hello. I installed in zsh, however I get this error when opening terminal

compleat: command not found
compleat: command not found
compleat: command not found
compleat: command not found
compleat: command not found

My setup
in bashrc:

source ~/.bash_completion.d/compleat_setup

in zshrc :

plugins=(compleat)
source $ZSH/oh-my-zsh.sh

modified autoload:

#from 
        autoload -U compinit && compinit -u
        
#to
        autoload -Uz compinit bashcompinit && compinit bashcompinit -u
        source ~/.bash_completion.d/compleat_setup

what am i missing?

Verbose mode

Feature request. List options from man page, without opening, well, man page.

$ ls -↹
-A      List all entries except for . and ...  Always set for the super-user.
-B      Force printing of non-printable characters (as defined by ctype(3) and current locale settings) in file names as \xxx, where xxx is the numeric
         value of the character in octal.
-C      Force multi-column output; this is the default when output is to a terminal.
...

Hackage?

This package doesn't seem to be available on Hackage even though there is a Cabal file? Am I missing something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.