Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
New: zsh completion. Closes #25. (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingxiaoyang authored and ellmetha committed Mar 14, 2017
1 parent e992c7c commit 986d73b
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 2 deletions.
Empty file removed contrib/completion/zsh/.gitkeep
Empty file.
126 changes: 126 additions & 0 deletions contrib/completion/zsh/_lxdock
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#compdef lxdock
# Zsh completion suppot for LXDock
#
# Provides completion for commands, options and container names.
#
# Installation instructions:
# - place this script at /usr/share/zsh/vendor-completions
# - restart your shell
#

local -a _1st_arguments
_1st_arguments=(
'config:Validate and show the LXDock file'
'destroy:Stop and remove containers'
'halt:Stop containers'
'help:Show help information'
'init:Generate a LXDock file'
'provision:Provision containers'
'shell:Open a shell in a container'
"status:Show containers' statuses"
'up:Create, start and provision containers'
)

__subcommand_list ()
{
local expl
declare -a subcommands

subcommands=(config destroy halt init provision shell status up)

_wanted tasks expl 'help' compadd $subcommands
}

__container_list ()
{
_lxdock_containers=(
$(_call_program path-all "lxdock 2>/dev/null config --containers") )

if [[ -z "${_lxdock_containers// }" ]]; then
_message 'no more arguments: no container defined.'
fi

_wanted application expl 'container' compadd $_lxdock_containers
}


local expl
local curcontext="$curcontext" state line
local -A opt_args

_arguments -C \
':command:->command' \
'*::arguments:->arguments' \

case $state in
(command)
_describe -t commands "subcommand" _1st_arguments
return
;;

(arguments)
case $line[1] in
(config)
# lxdock config [-h] [--containers]
_arguments '--containers[Display only container names, one per line.]'
;;

(destroy)
# lxdock destroy [-h] [-f] [name [name ...]]
_arguments '(-f --force)'{-f,--force}'[Destroy without confirmation]' \
'*::container:__container_list' \
;;

(halt)
# lxdock halt [-h] [name [name ...]]
_arguments '*::container:__container_list' \
;;

(help)
# lxdock help [-h] [subcommand]
_arguments ':subcommand:__subcommand_list'
;;

(init)
# lxdock init [-h] [-f] [--image IMAGE] [--project PROJECT]
_arguments '(-f --force)'{-f,--force}'[Overwrite existing LXDock file]' \
'--image[Container image to use]:image:' \
'--project[Project name to use]:project:'
;;

(provision)
# lxdock provision [-h] [name [name ...]]
_arguments '*::container:__container_list' \
;;

(shell)
# lxdock shell [-h] [-u USERNAME] [name]
_arguments '(-u --username)'{-u,--username}'[Username to login as]:username:' \
'::container:__container_list' \

;;

(status)
# lxdock status [-h] [name [name ...]]
_arguments '*::container:__container_list' \
;;

(up)
# lxdock up [-h] [name [name ...]]
_arguments '*::container:__container_list' \
;;

*)
(( ret )) && _message 'no arguments'
;;
esac
;;
esac

# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et
11 changes: 9 additions & 2 deletions docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ You should now be able to install LXDock using:
Command line completion
-----------------------

LXDock can provide completion for commands and container names.
LXDock can provide completion for commands, options and container names.

Bash
~~~~
Expand All @@ -106,7 +106,14 @@ Make sure to restart your shell before trying to use LXDock's bash completion.
ZSH
~~~

*Not yet!* But feel free to contribute (please refer to :doc:`contributing`)!
To add zsh completion for LXDock, place the ``contrib/completion/zsh/_lxdock`` file at
``/usr/share/zsh/vendor-completions/_lxdock`` (or another folder in ``$fpath``):

.. code-block:: console
$ sudo cp contrib/completion/zsh/_lxdock /usr/share/zsh/vendor-completions/_lxdock
Make sure to restart your shell before trying to use LXDock's zsh completion.

Your first LXDock file
----------------------
Expand Down

0 comments on commit 986d73b

Please sign in to comment.