gnuastro-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug #60618] Fixed directory string being removed on pressing TAB


From: Pedram Ashofteh Ardakani
Subject: [bug #60618] Fixed directory string being removed on pressing TAB
Date: Fri, 25 Jun 2021 10:25:34 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0

Follow-up Comment #1, bug #60618 (project gnuastro):

Hi Mohammad. I have been looking into this bug for quite a while now and got
confused. The crazy thing is that as you said, one  can get only the file's
'basename' suggestion by default, such as using 'M-?' on your keyboard! Just
try this:

++++
# Buggy response, including the 'dirname':
$ astfits subdir/out-[TAB]
subdir/out-123.fits   subdir/out-456.fits

# Desired response, showing only the 'basename':
$ astfits subdir/out-[M-?]
out-123.fits   out-456.fits
----

As you know, 'M' stands for the 'alt' key on keyboard. I tried to get a grasp
on how this command works, unfortunately to no avail. However, I stumbled upon
a few links and commands that might be useful:

* First, thie 'M-?' command is coming from option 'possible-completions' of
the 'bind' application. Give it a try:

++++
$ bind -P | grep possible-completions
----
  
* Second, the bash-completion
<https://github.com/scop/bash-completion/blob/master/completions> repository
on github hosts many useful scripts which might be already installed on your
system under the name 'bash-completion', try:

++++
$ pacman -Q bash-completion
----

* Third, these completion scripts use arcane functions starting with
underscore '_', namely '_init_completion'. Out of curiosity, I found out one
can view the content of these functions using the 'type' command. Give it a
try:

++++
$ type _init_completion
----

As far as I understood, bash-completion overwrites the '$current' word being
completed as soon as finding a match in the COMPREPLY array. This is somewhat
similar to our problem with long options containing the equal sign '='. We
used IFS='=' to let 'complete' distinguish option name and option value before
and after the equal sign.

But here, as you have already considered, we should check if user is passing
in a directory name. But maybe we could do this with checking if the $current
string includes a '/'. If so, we should somehow split this part. This way,
'complete' will let that part alone, and will not replace the 'already'
accepted input. Hopefully, this will only replace the 'basename' of each given
file or directory.

This is what I mean, if you could echo the $current and $prev variables for
debugging:

++++
$ astfits subdir/[TAB]
current: ''
prev: 'subdir/'
----

So, $prev is a directory name, we should add $prev as a prefix to the
directory we're running 'ls' on. Like:

++++
$ ls -d "$DIR_PREFIX/"*
----

Well, this is as far as I could get today. It would be nice if you could share
some views and suggestions at your convenience :)

BTW, changing 'IFS' in the entire shell can have annoying side effects. To
this end, some scripts just declare IFS inside bash functions only locally
with a short lifespan.


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?60618>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]