diff options
author | Gabriel F. T. Gomes <gabriel@inconstante.net.br> | 2021-08-28 11:35:14 -0300 |
---|---|---|
committer | Gabriel F. T. Gomes <gabriel@inconstante.net.br> | 2021-08-28 11:40:16 -0300 |
commit | 554300c83260043150edd7380af8d9d011363db6 (patch) | |
tree | 4c01aef61e713d6050258cf69927eee228b323a2 | |
parent | a2610065c7a0b01749ae2bffd79d008680dab371 (diff) | |
download | bash-completion-554300c83260043150edd7380af8d9d011363db6.tar.gz |
Backport fix for wrong completions after TZ, TERM, LANG, and others
As reported in https://bugs.debian.org/988975#5, completions after some
special words, such as TZ, TERM, and LANG, suggest completions that only
make sense when these words are used as variables that someone wants to
assign to. When these words are used as search patterns, for instance in
'grep -F TERM', the completions do not make sense.
Since this bug has already been fixed upstream, this patch backports it.
-rw-r--r-- | debian/changelog | 3 | ||||
-rw-r--r-- | debian/patches/12-properly-handle-TERM-and-other-envvars.patch | 139 | ||||
-rw-r--r-- | debian/patches/series | 1 |
3 files changed, 143 insertions, 0 deletions
diff --git a/debian/changelog b/debian/changelog index b02eaed5..eed1bed7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,9 @@ bash-completion (1:2.11-3) UNRELEASED; urgency=medium * Remove constraints unnecessary since stretch: + Remove 179 maintscript entries from 1 files. + [ Gabriel F. T. Gomes ] + * Backport fix for TZ, TERM, LANG, and others (Closes: #988975). + -- Gabriel F. T. Gomes <gabriel@debian.org> Sat, 28 Aug 2021 11:30:11 -0300 bash-completion (1:2.11-3~exp1) experimental; urgency=medium diff --git a/debian/patches/12-properly-handle-TERM-and-other-envvars.patch b/debian/patches/12-properly-handle-TERM-and-other-envvars.patch new file mode 100644 index 00000000..5194b81b --- /dev/null +++ b/debian/patches/12-properly-handle-TERM-and-other-envvars.patch @@ -0,0 +1,139 @@ +From 79a504a44cefa119f1ef8c0db28e7fa674aeaf32 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ville=20Skytt=C3=A4?= <ville.skytta@iki.fi> +Date: Mon, 7 Dec 2020 01:12:10 +0200 +Subject: [PATCH] _variables: split out _variable_assignments, use in export + +Closes https://github.com/scop/bash-completion/issues/457 +--- + bash_completion | 77 +++++++++++++++++++++++++++++---------------- + completions/export | 5 +-- + test/t/test_grep.py | 10 ++++++ + 3 files changed, 61 insertions(+), 31 deletions(-) + +diff --git a/bash_completion b/bash_completion +index 2114ea05086..1a097417d72 100644 +--- a/bash_completion ++++ b/bash_completion +@@ -679,37 +679,60 @@ _variables() + COMPREPLY+=("$cur}") + __ltrim_colon_completions "$cur" + return 0 +- else +- case ${prev-} in +- TZ) +- cur=/usr/share/zoneinfo/$cur +- _filedir +- for i in "${!COMPREPLY[@]}"; do +- if [[ ${COMPREPLY[i]} == *.tab ]]; then +- unset 'COMPREPLY[i]' +- continue +- elif [[ -d ${COMPREPLY[i]} ]]; then +- COMPREPLY[i]+=/ +- compopt -o nospace +- fi +- COMPREPLY[i]=${COMPREPLY[i]#/usr/share/zoneinfo/} +- done +- return 0 +- ;; +- TERM) +- _terms +- return 0 +- ;; +- LANG | LC_*) +- COMPREPLY=($(compgen -W '$(locale -a 2>/dev/null)' \ +- -- "$cur")) +- return 0 +- ;; +- esac + fi + return 1 + } + ++# Complete assignment of various known environment variables. ++# The word to be completed is expected to contain the entire ++# assignment, including the variable name and the "=". See related ++# parameters to _init_completion. ++# ++# @param $1 variable assignment to be completed ++# @return True (0) if variable value completion was attempted, ++# False (> 0) if not. ++_variable_assignments() ++{ ++ local cur=${1-} ++ ++ if [[ $cur =~ ^([A-Za-z_][A-Za-z0-9_]*)=(.*)$ ]]; then ++ prev=${BASH_REMATCH[1]} ++ cur=${BASH_REMATCH[2]} ++ else ++ return 1 ++ fi ++ ++ case $prev in ++ TZ) ++ cur=/usr/share/zoneinfo/$cur ++ _filedir ++ for i in "${!COMPREPLY[@]}"; do ++ if [[ ${COMPREPLY[i]} == *.tab ]]; then ++ unset 'COMPREPLY[i]' ++ continue ++ elif [[ -d ${COMPREPLY[i]} ]]; then ++ COMPREPLY[i]+=/ ++ compopt -o nospace ++ fi ++ COMPREPLY[i]=${COMPREPLY[i]#/usr/share/zoneinfo/} ++ done ++ ;; ++ TERM) ++ _terms ++ ;; ++ LANG | LC_*) ++ COMPREPLY=($(compgen -W '$(locale -a 2>/dev/null)' \ ++ -- "$cur")) ++ ;; ++ *) ++ _variables && return 0 ++ _filedir ++ ;; ++ esac ++ ++ return 0 ++} ++ + # Initialize completion and deal with various general things: do file + # and variable completion where appropriate, and adjust prev, words, + # and cword as if no redirections exist so that completions do not +diff --git a/completions/export b/completions/export +index 8d823614aaf..9cf94277678 100644 +--- a/completions/export ++++ b/completions/export +@@ -25,10 +25,7 @@ _export() + done + + if [[ $cur == *=* ]]; then +- local ocur=$cur oprev=$prev +- prev=${cur%%=*} cur=${cur#*=} +- _variables && return +- cur=$ocur prev=$oprev ++ _variable_assignments $cur && return + fi + + case $cur in +diff --git a/test/t/test_grep.py b/test/t/test_grep.py +index a249122eb12..10956b1f5e9 100644 +--- a/test/t/test_grep.py ++++ b/test/t/test_grep.py +@@ -14,3 +14,13 @@ def test_2(self, completion): + Not really a grep option, but tests _longopt. + """ + assert completion == "foo foo.d/".split() ++ ++ @pytest.mark.complete("grep TZ ", cwd="shared/default") ++ def test_no_variable_assignment_confusion(self, completion): ++ """ ++ Test TZ doesn't trigger known variable value assignment completion. ++ ++ Not really a grep specific, but good to test somewhere. ++ Refs https://github.com/scop/bash-completion/issues/457 ++ """ ++ assert "foo" in completion + diff --git a/debian/patches/series b/debian/patches/series index ab68d6c7..755b2cbc 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -3,3 +3,4 @@ 06-xpdf_support_compressed_pdf.patch 07-dpkg_support_raw-extract_vextract.patch 11-add-completions-for-openrc-rc-service.patch +12-properly-handle-TERM-and-other-envvars.patch |