autocshell

Crates.ioautocshell
lib.rsautocshell
version0.5.3
sourcesrc
created_at2020-06-26 17:28:21.190151
updated_at2020-11-09 17:12:22.760218
descriptionautocshell is a command line tool that helps you generate auto completion scripts for your tools and for your shell(s).
homepage
repositoryhttps://github.com/GeorgeLS/autocshell
max_upload_size
id258453
size35,040
George Liontos (GeorgeLS)

documentation

README

autocshell

autocshell is a command line tool that enables you to generate shell files/scripts that you can use in order to provide auto completion capabilities for your command line programs.

This program is able to generate scripts for various shells (currently only bash and zsh) and not for c-shell only (not to be confused due to the name being auto-cshell).

The only thing that autocshell requires is a simple to create configuration file that will take as input. In order to check the configuration file format please run autocshell with the --config-help flag.

By default autocshell prints the script in the standard output so you can redirect the output to whatever file you like but by providing the --output option the program can do that for you :)

Configuration File:

The configuration file that you must provide as input (using -c or --config option) has the following format:

shell:        <shell_type> (bash|zsh)
program_name: <program_name>
use_equals_sign: (true|false) [default: true] (available only for zsh) 
option*:
    short?: <short_name> _
                          |-> At least one should exist
    long?:  <long_name>  ‾
    accepts_value?:       (true|false) [default: true]  (available only for zsh)
    accepts_files?:       (true|false) [default: false]
    accepts_multiple?:    (true|false) [default: false] (available only for zsh)
    description?:
    fixed_values?:        [<fixed_value>, ...]

Field/Values explanation:

Field: shell
Value: It's the shell you want to generate the script for.
Mandatory: yes

Field: program_name
Value: The name of you program to generate the autocompletions for
Mandatory: yes

Field: use_equals_sign
Value: Denotes whether we want to add an equals sign (=) after option completion. This is valid only for zsh.
Default: true
Mandatory: no

Field: option
Value: None. The option field gets no value. It starts a new option definition
Mandatory: no

Field: short
Value: The short option description (- must be included)
Mandatory: no*

Field: long
Value: The long option description (-- must be included)
Mandatory: no*

Field: accepts_value
Value: Denotes whether this option takes an option or not (it's a flag). This is valid only for zsh.
Default: true
Mandatory: no

Field: accepts_files
Value: Denotes whether that option takes files/directories as value(s). Must be true or false
Default: false
Mandatory: no

Field: accepts_multiple
Value: This value denotes whether the option can appear multiple times in the cli . This is valid only for zsh.
Default: false
Mandatory: no

Field: description
Value: This value contains the description that will appear when auto completing this option. This is valid only for zsh.
Mandatory: no

Field: fixed_values
Value: This value is a bracketed comma separated list of fixed values that will be auto completed for that option. This is valid only for zsh.
Mandatory: no

* short and long fields are not mandatory, however if you define an option at least one of them must be present.

Adding the completions to the shell

The recommended way to load and register the autocomplete functions for your programs is to create a folder where you will keep all of the generated files in there.
Then in you initialization shell script you can add the following: \

AUTOCOMPLETE_DIR=/path/to/dir
for f in$(find ${AUTOCOMPLETE_DIR} -name "*.<shell_name>");
do source $f;
done

Of course the loop might need to be tailored to the shell's acceptable syntax.

Bash

For bash you don't need anything special to do, just source the files as shown above.

Zsh

For zsh you must have run compinit, otherwise compdef will fail.
If you are using oh-my-zsh that is done in .zshrc file, in the line oh-my-zsh.sh is sourced.

Commit count: 16

cargo fmt