bash_completion
script file.On some Linux systems bash_completion
allow the program to control command line behaviour.
$ nitls [TAB][TAB]
file1.nit file2.nit file3.nit
$ nitls --[TAB][TAB]
--bash-toolname --keep --path --tree
--depends --log --package --verbose
--disable-phase --log-dir --quiet --version
--gen-bash-completion --no-color --recursive --warn
--help --only-metamodel --source
--ignore-visibility --only-parse --stop-on-first-error
Generated file can be placed in system bash_completion directory /etc/bash_completion.d/
or source it in ~/.bash_completion
.
nitc :: BashCompletion :: _toolcontext
nitc :: BashCompletion :: defaultinit
nitc :: BashCompletion :: toolcontext
nitc :: BashCompletion :: toolcontext=
nitc $ BashCompletion :: SELF
Type of this instance, automatically specialized in every classnitc $ BashCompletion :: rendering
Service used to render the content of the template.template :: Template :: _is_frozen
Is the template allowing more modification (add
)
template :: Template :: _is_writing
Flag to avoid infinite recursivity if a template contains itselftemplate :: Template :: _render_done
Flag to avoid multiple renderingnitc :: BashCompletion :: _toolcontext
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Writable :: defaultinit
nitc :: BashCompletion :: defaultinit
template :: Template :: defaultinit
core :: Object :: defaultinit
template :: Template :: is_frozen=
Is the template allowing more modification (add
)
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
template :: Template :: is_writing
Flag to avoid infinite recursivity if a template contains itselftemplate :: Template :: is_writing=
Flag to avoid infinite recursivity if a template contains itselfcore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).template :: Template :: render_done=
Flag to avoid multiple renderingnitc :: BashCompletion :: toolcontext
nitc :: BashCompletion :: toolcontext=
core :: Writable :: write_to_bytes
Likewrite_to
but return a new Bytes (may be quite large)
core :: Writable :: write_to_file
Likewrite_to
but take care of creating the file
core :: Writable :: write_to_string
Likewrite_to
but return a new String (may be quite large).
# This class generates a compatible `bash_completion` script file.
#
# On some Linux systems `bash_completion` allow the program to control command line behaviour.
#
# ~~~sh
# $ nitls [TAB][TAB]
# file1.nit file2.nit file3.nit
#
# $ nitls --[TAB][TAB]
# --bash-toolname --keep --path --tree
# --depends --log --package --verbose
# --disable-phase --log-dir --quiet --version
# --gen-bash-completion --no-color --recursive --warn
# --help --only-metamodel --source
# --ignore-visibility --only-parse --stop-on-first-error
# ~~~
#
# Generated file can be placed in system bash_completion directory `/etc/bash_completion.d/`
# or source it in `~/.bash_completion`.
class BashCompletion
super Template
var toolcontext: ToolContext
private fun extract_options_names: Array[String] do
var names = new Array[String]
for option in toolcontext.option_context.options do
for name in option.names do
if name.has_prefix("--") then names.add name
end
end
return names
end
redef fun rendering do
var name = toolcontext.toolname
var option_names = extract_options_names
addn "# generated bash completion file for {name} {toolcontext.version}"
addn "_{name}()"
addn "\{"
addn " local cur prev opts"
addn " COMPREPLY=()"
addn " cur=\"$\{COMP_WORDS[COMP_CWORD]\}\""
addn " prev=\"$\{COMP_WORDS[COMP_CWORD-1]\}\""
if not option_names.is_empty then
addn " opts=\"{option_names.join(" ")}\""
addn " if [[ $\{cur\} == -* ]] ; then"
addn " COMPREPLY=( $(compgen -W \"$\{opts\}\" -- $\{cur\}) )"
addn " return 0"
addn " fi"
end
addn "\} &&"
addn "complete -o default -F _{name} {name}"
end
end
src/toolcontext.nit:636,1--690,3