please do not expand leading tildes

Bug #324505 reported by David Paleino
40
This bug affects 10 people
Affects Status Importance Assigned to Milestone
bash-completion
Incomplete
Low
wonder.mice
bash-completion (Debian)
Fix Released
Unknown

Bug Description

From: Morita Sho <email address hidden>
To: Debian Bug Tracking System <email address hidden>
Subject: bash-completion: Please do not expand leading tildes
Date: Mon, 07 Jul 2008 20:41:37 +0900

Package: bash-completion
Version: 20080705
Severity: minor
Tags: patch

Hi,

When bash-completion is not installed, the leading tilde will not be
expanded on completion.

$ ls ~testuser/testfile
/home/testuser/testfile
$ ls ~testuser/testf[TAB]
     => ~testuser/testfile

However, when bash-completion is installed, the leading tilde will be
expanded on completion because _expand function performs the tilde
expansion. That is slightly annoying.

$ ls ~testuser/testf[TAB]
     => /home/testuser/testfile

IMHO, the tilde expansion in _expand seems needless because compgen
correctly handles leading tildes.
I suggest following patch.

--- bash_completion.orig 2008-07-07 14:07:28.000000000 +0900
+++ bash_completion 2008-07-07 17:28:59.000000000 +0900
@@ -353,7 +353,7 @@

  # expand ~username type directory specifications
  if [[ "$cur" == \~*/* ]]; then
- eval cur=$cur
+ return
  elif [[ "$cur" == \~* ]]; then
   cur=${cur#\~}
   COMPREPLY=( $( compgen -P '~' -u $cur ) )

Regards,

David Paleino (dpaleino)
Changed in bash-completion:
assignee: nobody → dpaleino
importance: Undecided → Low
status: New → Fix Committed
Changed in bash-completion:
status: Unknown → Confirmed
Revision history for this message
Victor Zamanian (victorz) wrote :

I agree with this. bash handles it correctly for me without _expand, and __expand_tilde_by_ref. These functions don't have any regard for my expand-tilde option either, they blatantly _dis_regard it.

Revision history for this message
Mike Doherty (doherty) wrote :

Was a fix for this ever released? I still find this behaviour in Lucid.

Revision history for this message
Victor Zamanian (victorz) wrote :

No, it wasn't. I still have the behavior in Maverick.

Revision history for this message
Joel (joelfrederico) wrote :

@Mike Doherty, Victor Zamanian: Just checked out bash_completion. If you use the master branch (dangerous?) it's fixed, but it's not fixed at the 1.2 tag. I was looking for the specific commit that fixed it, but I gave up.

git clone git://git.debian.org/git/bash-completion/bash-completion.git

Nobody seems to be prepping for a release yet, although the time between releases seems to be about 6-9 months, and it's been 6 months since 1.2. So it may be coming in the next several months. If you must have it, and you just want instructions, do the following:

git clone git://git.debian.org/git/bash-completion/bash-completion.git
cd bash-completion
git checkout master
sudo cp bash-completion /etc

Then add to your .bashrc, .profile, .bash_profile, whatever:

# Use bash-completion, if available
if [ -f /etc/bash_completion ]; then
  . /etc/bash_completion
fi

For fun, notice the message attached to SHA 0c4db6eb969892ca282e7d5c8a524f2c062eb42e. That just made my day.

Revision history for this message
Joel (joelfrederico) wrote :

I take it back. It works with ls, cd, etc. But not with vi, vim, or emacs, and possibly others.

Changed in bash-completion:
status: Fix Committed → Incomplete
Changed in bash-completion:
assignee: David Paleino (dpaleino) → wonder.mice (wonder-mice)
Revision history for this message
wonder.mice (wonder-mice) wrote :

Looks like attached patch will work.

Revision history for this message
wonder.mice (wonder-mice) wrote :

Ooops. Looks like fix like that will break different things:
http://lists.alioth.debian.org/pipermail/bash-completion-devel/2009-February/000973.html

Revision history for this message
wonder.mice (wonder-mice) wrote :

Ok, that patch looks better.

Note, however, that the same change must be done in following files:
bash$ grep -rn " _expand" /etc/bash_completion.d/
/etc/bash_completion.d/info:11: _expand || return 0
/etc/bash_completion.d/lrzip:49: _expand || return 0
/etc/bash_completion.d/povray:12: _expand || return 0
/etc/bash_completion.d/man:21: _expand || return 0
/etc/bash_completion.d/xz:53: _expand || return 0
/etc/bash_completion.d/lzop:54: _expand || return 0
/etc/bash_completion.d/rsync:12: _expand || return 0
/etc/bash_completion.d/sshfs:11: _expand || return 0
/etc/bash_completion.d/bzip2:37: _expand || return 0
/etc/bash_completion.d/ssh:347: _expand || return 0
/etc/bash_completion.d/lzma:32: _expand || return 0
/etc/bash_completion.d/dd:25: _expand || return 0
/etc/bash_completion.d/gcc:19: _expand || return 0
/etc/bash_completion.d/findutils:70: _expand || return 0
/etc/bash_completion.d/dpkg:29: _expand || return 0
/etc/bash_completion.d/gzip:41: _expand || return 0

--- /etc/bash_completion.original 2012-08-14 23:08:38.189654426 +0400
+++ /etc/bash_completion 2012-08-23 01:12:13.313643700 +0400
@@ -1596,7 +1596,7 @@
     COMPREPLY=()
     _get_comp_words_by_ref cur

- _expand || return 0
+ _rl_enabled expand-tilde && (_expand || return 0)

     # get first exclusion compspec that matches this command
     xspec=$( awk "/^complete[ \t]+.*[ \t]${1##*/}([ \t]|\$)/ { print \$0; exit }" \

Revision history for this message
wonder.mice (wonder-mice) wrote :

Fixed for completions that use _filedir_xspec in 'master' branch on git://anonscm.debian.org/bash-completion/bash-completion.git
http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=commit;h=fdb080ff89195f85e1b76d0752979dfefa777595

Changed in bash-completion (Debian):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.