Bug 994646

Summary: attempting tab-completion with "TZ=" returns files and directories, not time zones
Product: [Fedora] Fedora Reporter: Steve Tyler <stephent98>
Component: bash-completionAssignee: Ville Skyttä <ville.skytta>
Status: CLOSED CANTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 19CC: sheltren, stephent98, ville.skytta
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-08-08 05:54:29 EDT Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Steve Tyler 2013-08-07 13:11:19 EDT
Description of problem:
Attempting tab-completion with the TZ environment variable results in a list of files and directories, not a list of time zones:

$ TZ=[tab]
bar.dir/ foo.txt  

NB: TZ is a POSIX environment variable:
8. Environment Variables
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html

Version-Release number of selected component (if applicable):
bash-completion-2.1-2.fc19.noarch
bash-4.2.45-1.fc19.x86_64

How reproducible:
Always.

Steps to Reproduce:
1. $ TZ=[tab]

Actual results:
A list of files and directories is displayed:
$ TZ=[tab]
bar.dir/ foo.txt  

Expected results:
A list of time zones is displayed.

Additional info:

With zsh, a list of time zones is displayed:

% TZ=[tab]
Africa/      CST6CDT      GMT          Israel       NZ           ROK
America/     Cuba         GMT0         Jamaica      NZ-CHAT      Singapore
Antarctica/  EET          GMT-0        Japan        Pacific/     Turkey
Arctic/      Egypt        GMT+0        Kwajalein    Poland       UCT
Asia/        Eire         Greenwich    Libya        Portugal     Universal
Atlantic/    EST          Hongkong     MET          posix/       US/
Australia/   EST5EDT      HST          Mexico/      posixrules   UTC
Brazil/      Etc/         Iceland      Mideast/     PRC          WET
Canada/      Europe/      Indian/      MST          PST8PDT      W-SU
CET          GB           Iran         MST7MDT      right/       zone.tab
Chile/       GB-Eire      iso3166.tab  Navajo       ROC          Zulu

zsh-5.0.2-4.fc19.x86_64
Comment 1 Ville Skyttä 2013-08-08 05:54:29 EDT
Completing the first argument is not something that can be done with bash's programmable completion features as far as I know. On the other hand, for export and friends (at least env, declare, typeset) it can be done, and is now done for export upstream:

http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=commitdiff;h=3f144beb721525821136f76f53a3147b4688d331
Comment 2 Steve Tyler 2013-08-08 06:26:34 EDT
Your upstream patch looks like it _fixes_ this bug.
Why did you close it CANTFIX instead of UPSTREAM?
Comment 3 Ville Skyttä 2013-08-08 07:02:54 EDT
Because as said, the requested feature cannot AFAIK be implemented. The upstream patch implements "export TZ=<TAB>" completion, not plain "TZ=<TAB>" which is what was requested.
Comment 4 Steve Tyler 2013-08-08 07:19:01 EDT
Thanks for the clarification.

The upstream version doesn't appear to work with:
$ export TZ=[tab]

That returns a list of files and directories, not a list of time zones.

To test the upstream version, do I need to do anything in addition to these?

1. Copy upstream version of bash_completion into /usr/share/bash-completion/:

$ ls /usr/share/bash-completion/
bash_completion  bash_completion.ORIG  completions/  helpers/

$ rpm -V bash-completion
SM5..UGT.    /usr/share/bash-completion/bash_completion

2. Log out.
3. Log in.
Comment 5 Ville Skyttä 2013-08-08 07:23:56 EDT
You need updated completions/export in /usr/share/bash-completion/completions from upstream too.
Comment 6 Steve Tyler 2013-08-08 08:01:44 EDT
Verified. Thanks for the patch.

$ export TZ=U[tab]
UCT        Universal  US/        UTC        

$ export TZ=UTC ;date
Thu Aug  8 11:51:50 UTC 2013

$ rpm -V bash-completion 
SM5..UGT.    /usr/share/bash-completion/bash_completion
SM5..UGT.    /usr/share/bash-completion/completions/export

BTW, I didn't know tab-completion requires so much infrastructure:
$ rpm -ql bash-completion | wc -l
563
Comment 7 Ville Skyttä 2013-08-08 08:10:25 EDT
(In reply to Steve Tyler from comment #6)
> $ rpm -ql bash-completion | wc -l
> 563

We could (and used to) lump everything into just a couple of files, but since version 2.0 splitting most things into per command completion files allows us to dynamically load needed functions from them on demand which allows huge shell startup time savings.
Comment 8 Steve Tyler 2013-08-08 08:34:30 EDT
That sounds like a valuable optimization:
$ rpm -ql bash-completion | grep /usr/share/bash-completion/ | xargs cat 2>/dev/null | wc -l
81051
Comment 9 Steve Tyler 2013-08-09 13:17:06 EDT
The pipeline in Comment 8 follows links and omits completions from other packages.

FWIW, here is a better line count:

$ find /usr/share/bash-completion/ -type f | xargs cat | wc -l
29839

That's still a lot of lines ...