Changeset View
Changeset View
Standalone View
Standalone View
debian/bash_completion.d/scap
__scap_cwd= | #!/usr/bin/bash | ||||
__scap_subcommands= | # -*- mode: shell-script; sh-basic-offset: 8; indent-tabs-mode: t -*- | ||||
__scap_get_subcommands() { | # ex: ts=8 sw=8 noet filetype=sh | ||||
thcipriani: This doesn't match the format of the file | |||||
local force_update | # | ||||
force_update=${1:=0} | |||||
if [[ "$force_update" -eq 0 && -n "$__scap_subcommands" ]]; then | _scap() | ||||
return | { | ||||
local _COMP_OUTPUTSTR COMP_RET | |||||
local cur=${COMP_WORDS[COMP_CWORD]} | |||||
local prev=$3 | |||||
local compgen_args='' | |||||
local environments='' | |||||
_init_completion || return | |||||
# if already typing a file path, bypass running scap to load completions | |||||
if [[ "$cur" == */ || "$cur" == .* ]]; then | |||||
COMPREPLY=( $( compgen -o default -o bashdefault -o nospace -f -- "$cur" ) ) | |||||
return 0 | |||||
fi | fi | ||||
__scap_subcommands=$(scap --_autocomplete) | if [ "$prev" == "--environment" ] && [ -d ./scap/environments/ ]; then | ||||
} | environments=$(ls ./scap/environments/ -C) | ||||
Not Done Inline ActionsI think you probably want ls -1. ls -C seems to work fine, but seems like a weird choice thcipriani: I think you probably want `ls -1`. `ls -C` seems to work fine, but seems like a weird choice | |||||
COMPREPLY=( $( compgen -W "$environments" -- "$cur" ) ) | |||||
_scap() { | return 0 | ||||
local cur cmd=() rep force_update | |||||
cur=${COMP_WORDS[$COMP_CWORD]} | |||||
cmd=( "${COMP_WORDS[@]}" ) | |||||
if (( COMP_CWORD == 1 )); then | |||||
force_update=0 | |||||
# If we're tab completing in a different directory, | |||||
# we have to update the list of available subcommands | |||||
if [[ "$PWD" != "$__scap_cwd" ]]; then | |||||
__scap_cwd="$PWD" | |||||
force_update=1 | |||||
fi | fi | ||||
__scap_get_subcommands $force_update | _COMP_OUTPUTSTR="$( _COMPLETION=1 scap --_completion "${COMP_WORDS[*]}" 2>/dev/null )" | ||||
rep=$( compgen -W "$__scap_subcommands" -- "$cur" ) | COMP_RET=$? | ||||
COMPREPLY=( $rep ) | if (( COMP_RET == 2 )); then | ||||
return | compopt -o default | ||||
COMPREPLY=( ) | |||||
return 0 | |||||
fi | fi | ||||
# limit the command to autocomplete to the first 3 words | if (( COMP_RET != 0 )); then | ||||
if (( COMP_CWORD >= 2 )); then | compopt -o default | ||||
# don't complete any sub-subcommands, only options | |||||
if [[ -n "$cur" && "${cur:0:1}" != '-' ]]; then | |||||
COMPREPLY=() | COMPREPLY=( ) | ||||
return | return 1 | ||||
fi | |||||
cmd=( "${COMP_WORDS[@]:0:3}" ) | |||||
fi | fi | ||||
# replace the last word in the command with '--_autocomplete' | |||||
cmd[ $(( ${#cmd[@]} - 1 )) ]='--_autocomplete' | |||||
rep=$( compgen -W "$( "${cmd[@]}" )" -- "$cur" ) | # special '__dirs__' and '__files_' tokens are returned by scap to trigger | ||||
# adding files or directories to the list of completions. | |||||
if [[ "$_COMP_OUTPUTSTR" == *__dirs__* ]]; then | |||||
compgen_args="$compgen_args -A directory -o plusdirs -o nospace -o dirnames -o filenames" | |||||
fi | |||||
if [[ "$_COMP_OUTPUTSTR" == *__files__* ]]; then | |||||
compgen_args="$compgen_args -f" | |||||
fi | |||||
_COMP_OUTPUTSTR=$(echo "$_COMP_OUTPUTSTR"|grep -v '__.*__') | |||||
COMPREPLY=( $( compgen $compgen_args -W "$_COMP_OUTPUTSTR" -- "$cur" ) ) | |||||
COMPREPLY=( $rep ) | #COMPREPLY=( $( compgen -f -W "$_COMP_OUTPUTSTR" -- "$cur" ) ) | ||||
Not Done Inline ActionsThis is a neat trick. Seems to only be activated in a very narrow set of circumstances. This works: scap l10n-purge --version<tab><tab> this doesn't: scap l10n-purge --version p<tab><tab> scap l10n-purge --version 1<tab><tab> thcipriani: This is a neat trick.
Seems to only be activated in a very narrow set of circumstances. This… | |||||
#readarray -t COMPREPLY < <( echo -n "$_COMP_OUTPUTSTR"|grep -v '__.*__' ) | |||||
Not Done Inline ActionsRemove commented-out code. thcipriani: Remove commented-out code. | |||||
} | } | ||||
# By default append nospace except when completion comes from _scap | complete -D -F _scap scap | ||||
complete -S' ' -o bashdefault -o default -o nospace -F _scap scap |
Content licensed under Creative Commons Attribution-ShareAlike 3.0 (CC-BY-SA) unless otherwise noted; code licensed under GNU General Public License (GPL) or other open source licenses. By using this site, you agree to the Terms of Use, Privacy Policy, and Code of Conduct. · Wikimedia Foundation · Privacy Policy · Code of Conduct · Terms of Use · Disclaimer · CC-BY-SA · GPL
This doesn't match the format of the file