[Bug 1394920] Re: complete -o filename can't be used with filenames relative to another directory to handle space vs. trailing /

2014-12-10 Thread hakon
Hi Peter, you were completely right! Now I have got some help at
stackoverflow, and it seems that helped solve this issue. There are four
things that seems must be in place to solve it:

1. compopt -o nospace
2. compopt -o filenames
3. Running compgen -f with an absolute path
4. Then postprocessing the results of compgen
  a) removing absoulte path prefix
  b) adding slashes after filenames

So here is minimal example (not handling quoting and spaces in file
names):

_compTest() {
local cur tmp val
cur=${COMP_WORDS[$COMP_CWORD]}
tmp=~/tmp/
tmp_escaped=${tmp//\//\\\/}
cur=$tmp$cur
COMPREPLY=( $(compgen -f $cur) )
for ((i=0 ; i${#COMPREPLY[@]}; i++ )) ; do
val=${COMPREPLY[$i]}
[[ -d $val ]]  val=$val/
COMPREPLY[$i]=${val/$tmp_escaped/}
done
}
complete -o filenames -o nospace -F _compTest aaa

Thanks again for excellent help!

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1394920

Title:
  complete -o filename can't be used with filenames relative to another
  directory to handle  space vs. trailing /

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/1394920/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs


[Bug 1394920] Re: complete -o filename can't be used with filenames relative to another directory to handle space vs. trailing /

2014-12-02 Thread hakon
Thanks Peter! See follow-up question at stackoverflow:

http://stackoverflow.com/questions/27244300/how-to-complete-filenames-
relative-to-another-directory

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1394920

Title:
  complete -o filename can't be used with filenames relative to another
  directory to handle  space vs. trailing /

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/1394920/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs


[Bug 1394920] Re: complete -o filename can't be used with filenames relative to another directory to handle space vs. trailing /

2014-12-01 Thread hakon
Thanks for the thorough answer! If I add shopt -s extglob your code is
working.

The question is how to add slashes after directory names and not file names. If 
I remove -o filenames and add 
compopt -o nospace I still can use compgen -f $cur  but it does not add 
slashes. And the completions are not broken at / (if I insert it manually) 
such that I get a completion list with a/b/c instead of just c  when I try 
to complete a/b..

Do I have to add a slash to $COMP_WORDBREAKS variable?

There is a post a stackoverflow :
http://stackoverflow.com/questions/10528695/how-to-reset-comp-wordbreaks-without-effecting-other-completion-script

It refers to a function _get_comp_words_by_ref .. where is this function 
documented? I searched the bash manual, 
http://www.gnu.org/software/bash/manual/bashref.html
but it is not mentioned there..

Thanks!

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1394920

Title:
  complete -o filename can't be used with filenames relative to another
  directory to handle  space vs. trailing /

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/1394920/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs


[Bug 1394920] Re: complete -o filename can't be used with filenames relative to another directory to handle space vs. trailing /

2014-12-01 Thread Peter Cordes
Was working on completions for something else, and thought of this when
I saw completions/make checking if COMPREPLY has only a single entry.
If it does, that means completion will replace the user's word, rather
than show possible completions.  In that case, run compopt -o nospace.

 And maybe also make sure your possible completions for directories end
with /, to trick the shell into appending that.  (Sort that out in the
subshell that's cded there, so it can tell.)

_get_comp_words_by_ref is in /usr/share/bash-completion/bash_completion.
You might as well use any of those building blocks.  But mostly they're
overkill solutions for the problem of noticing when there's a  or 
redirect, and completing on filenames for it, and then adjusting the
rest of the line like it hadn't happened, I think.

 AFAICT, that's all you miss out on with
local cur=${COMP_WORDS[$COMP_CWORD]}
vs.
 _get_comp_words_by_ref cur prev

If you want more help with this, you should prob. post on stackoverflow
about how to complete filenames relative to something other than the
current directory.  This Ubuntu bug probably isn't the most visible
place for anyone to notice and tip you off to a good idea.  Since I'm
pretty much at the limit of my knowledge of obscure tips and tricks for
making something like this not take a lot of code and debugging time.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1394920

Title:
  complete -o filename can't be used with filenames relative to another
  directory to handle  space vs. trailing /

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/1394920/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs