[Bash-completion-devel] Fixed competion of '~' and '~xx' in _filedir_xspec()
Andrey Pokrovskiy
wonder.mice at gmail.com
Wed Sep 5 21:17:47 UTC 2012
Sorry for the bad patch. Better version attached.
Issue described in more details here:
please do not expand leading tildes
https://bugs.launchpad.net/bash-completion/+bug/324505
Test cases (before - before patch, after - after patch):
1. What: vim ~/<TAB>
Before: vim /home/mice/
After: vim ~/
2. What: vim ~/<TAB><TAB>
Before: vim /home/mice/
+ list of folders and files
After: vim ~/
+ list of folders and files
3. What: vim ~/Doc
Before: vim /home/mice/Documents/
After: vim ~/Documents/
---- ---- ---- ----
>From ad35b81343a1f00000c8ebc40ff1efe613597123 Mon Sep 17 00:00:00 2001
From: "wonder.mice" <wonder.mice at gmail.com>
Date: Thu, 6 Sep 2012 00:47:22 +0400
Subject: [PATCH] Fixed tilde expanding in _filedir_xspec
With this patch completions that use _filedir_xspec will not expand
tilde when "expand-tilde" option is set to off.
This patch fixes:
1. What: vim ~/<TAB>
Before: vim /home/mice/
After: vim ~/
2. What: vim ~/<TAB><TAB>
Before: vim /home/mice/
+ list of folders and files
After: vim ~/
+ list of folders and files
3. What: vim ~/Doc
Before: vim /home/mice/Documents/
After: vim ~/Documents/
---
bash_completion | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bash_completion b/bash_completion
index f3488ba..335f7a3 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1800,7 +1800,7 @@ _filedir_xspec()
local cur prev words cword
_init_completion || return
- _expand || return 0
+ _tilde "$cur" || return 0
local IFS=$'\n' xspec=${_xspecs[${1##*/}]} tmp
local -a toks
--
1.7.9.5
On Wed, Sep 5, 2012 at 6:00 PM, Igor Murzov <e-mail at date.by> wrote:
> On Sun, 26 Aug 2012 16:20:37 +0400
> "wonder.mice" <wonder.mice at gmail.com> wrote:
>
> > As I understand, this patch solves "Please do not expand leading tildes"
> > problem when _filedir_xspec is used (for vim, for example).
> >
> > ---
> >
> > diff --git a/bash_completion b/bash_completion
> > index b58e37e..912a8e6 100644
> > --- a/bash_completion
> > +++ b/bash_completion
> > @@ -1596,7 +1596,7 @@ _filedir_xspec()
> > COMPREPLY=()
> > _get_comp_words_by_ref cur
> >
> > - _expand || return 0
> > + _tilde "$cur" || return 0
> >
> > # get first exclusion compspec that matches this command
> > xspec=$( awk "/^complete[ \t]+.*[ \t]${1##*/}([ \t]|\$)/ { print
> > \$0; exit }" \
>
> The patch does not apply. You should start your work of the 'master'
> branch on git://anonscm.debian.org/bash-completion/bash-completion.git
> Also, the title is not clear. Please describe what issue you are
> trying to fix with this patch or submit some tests that this patch fixes.
>
>
> -- Igor
>
> > On 08/25/2012 07:53 PM, wonder.mice wrote:
> > > Hello,
> > >
> > > I would like to fix issue with expanding '~' by several completion
> > > scripts:
> > > #489720 [m|U☹|=↝] [bash-completion] bash-completion: Please do not
> > > expand leading tildes
> > > #521406 [m|U☹|=↝] [bash-completion] bash-completion: leading tilde
> > > always expanded
> > > please do not expand leading tildes
> > > https://bugs.launchpad.net/bash-completion/+bug/324505
> > >
> > > As I understand, the problem is in _expand() function that is not
> > > always correctly used.
> > > For example, in _filedir_xspec() it expands '~' regardless to bind
> > > -v|grep expand-tilde option.
> > >
> > > This patch will not solve problems described above.
> > > I'm very new in bash and completion and I want to understand that I
> > > got right direction.
> > >
> > > That patch fixes simple problem:
> > > $ vim ~mi<TAB>
> > > will not expand to
> > > $ vim ~mice/
> > >
> > > ----
> > >
> > > Use _tilde() to complete '~' and '~xx' like it done in _filedir().
> > >
> > > diff --git a/bash_completion b/bash_completion
> > > index f3488ba..beec07c 100644
> > > --- a/bash_completion
> > > +++ b/bash_completion
> > > @@ -1800,6 +1800,7 @@ _filedir_xspec()
> > > local cur prev words cword
> > > _init_completion || return
> > >
> > > + _tilde "$cur" || return 0
> > > _expand || return 0
> > >
> > > local IFS=$'\n' xspec=${_xspecs[${1##*/}]} tmp
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20120906/6078997f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-tilde-expand.patch
Type: application/octet-stream
Size: 1099 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/bash-completion-devel/attachments/20120906/6078997f/attachment.obj>
More information about the Bash-completion-devel
mailing list