Re: ssh config "Include" and bash completion

2018-05-14 Thread Javier Barroso
Hello Greg,

On Mon, May 14, 2018 at 3:35 PM, Greg Wooledge  wrote:
> On Mon, May 14, 2018 at 03:29:22PM +0200, Javier Barroso wrote:
>> Maybe you can improve the script talking / sendind pull request? with
>> żupstream? żhttps://github.com/scop/bash-completion?
>>
>> Thank you !
>
> Not likely to happen.

ok, only was a suggest
>
>> == OFF TOPIC ==
>> An annoying bug on debian (at least for me):
>> $ ls $(bash: unexpected EOF while looking for matching `)'
>> bash: syntax error: unexpected end of file
>
> Does this happen with bash-completion disabled?  Seems OK for me on
> stretch:
>
> wooledg:~$ ls $(
> Display all 1902 possibilities? (y or n)
>
> If the bug only happens with bash-completion enabled, then the bug is
> probably somewhere in bash-completion.
>
Yes, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=742466

I think I saw that the bug was fixed at upstream, but now I am not
able to find the fix

Thanks !



Re: ssh config "Include" and bash completion

2018-05-14 Thread Greg Wooledge
On Mon, May 14, 2018 at 03:29:22PM +0200, Javier Barroso wrote:
> Maybe you can improve the script talking / sendind pull request? with
> ¿upstream? ¿https://github.com/scop/bash-completion?
> 
> Thank you !

Not likely to happen.

> == OFF TOPIC ==
> An annoying bug on debian (at least for me):
> $ ls $(bash: unexpected EOF while looking for matching `)'
> bash: syntax error: unexpected end of file

Does this happen with bash-completion disabled?  Seems OK for me on
stretch:

wooledg:~$ ls $(
Display all 1902 possibilities? (y or n)

If the bug only happens with bash-completion enabled, then the bug is
probably somewhere in bash-completion.



Re: ssh config "Include" and bash completion

2018-05-14 Thread Javier Barroso
Hello Greg,

On Mon, May 14, 2018 at 3:19 PM, Greg Wooledge  wrote:
>> local included=$( command sed -ne
>> 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\{1,\}\([^#%]*\)\(#.*\)\{0,1\}$/\1/p'
>> "${configfile}" )
>
> So, "included" is a string variable containing the ouput of sed.
>
> If I'm reading that regex correctly, there'll be one pathname per line.
>
>> for i in ${included[@]}; do
>
> But then the function attempts to treat the string variable as an array,
> and then attempts to iterate over the "array" using an unquoted expansion.
>
> Code like this is one reason why I do not use bash-completion.  Any time
> it doesn't fail is just a lucky coincidence.
>
> In this particular instance, it "works" so long as each pathname in
> sed's output contains NO whitespace and NO globbing characters.  The
> array syntax is a total red herring, though -- you get the same result
> (success or failure) just by expanding the string variable with regular
> string expansion syntax.
>
> wooledg:~$ included=$'/foo/bar\n/Program Files/junk'
> wooledg:~$ args ${included[@]}
> 3 args:   
> wooledg:~$ args $included
> 3 args:   
>
> A correct implementation would have "included" be a real array variable,
> initialized by splitting the sed output on newlines, so that each
> pathname becomes one array element.  Then, a *correct* array expansion
> (with double quotes) would work:
>
> wooledg:~$ included=(/foo/bar "/Program Files/junk")
> wooledg:~$ args "${included[@]}"
> 2 args:  
>
> I don't know whether bash-completion is targeting bash 4.x exclusively,
> or older bash versions.  If it's targeting bash 4.x then it could use
> mapfile to initialize the array from sed's output.  Otherwise, it needs
> a loop.
>
Maybe you can improve the script talking / sendind pull request? with
¿upstream? ¿https://github.com/scop/bash-completion?

Thank you !

== OFF TOPIC ==
An annoying bug on debian (at least for me):
$ ls $(bash: unexpected EOF while looking for matching `)'
bash: syntax error: unexpected end of file



Re: ssh config "Include" and bash completion

2018-05-14 Thread Greg Wooledge
> local included=$( command sed -ne
> 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\{1,\}\([^#%]*\)\(#.*\)\{0,1\}$/\1/p'
> "${configfile}" )

So, "included" is a string variable containing the ouput of sed.

If I'm reading that regex correctly, there'll be one pathname per line.

> for i in ${included[@]}; do

But then the function attempts to treat the string variable as an array,
and then attempts to iterate over the "array" using an unquoted expansion.

Code like this is one reason why I do not use bash-completion.  Any time
it doesn't fail is just a lucky coincidence.

In this particular instance, it "works" so long as each pathname in
sed's output contains NO whitespace and NO globbing characters.  The
array syntax is a total red herring, though -- you get the same result
(success or failure) just by expanding the string variable with regular
string expansion syntax.

wooledg:~$ included=$'/foo/bar\n/Program Files/junk'
wooledg:~$ args ${included[@]}
3 args:   
wooledg:~$ args $included
3 args:   

A correct implementation would have "included" be a real array variable,
initialized by splitting the sed output on newlines, so that each
pathname becomes one array element.  Then, a *correct* array expansion
(with double quotes) would work:

wooledg:~$ included=(/foo/bar "/Program Files/junk")
wooledg:~$ args "${included[@]}"
2 args:  

I don't know whether bash-completion is targeting bash 4.x exclusively,
or older bash versions.  If it's targeting bash 4.x then it could use
mapfile to initialize the array from sed's output.  Otherwise, it needs
a loop.



Re: ssh config "Include" and bash completion

2018-05-14 Thread Richard Hector
On 14/05/18 21:51, Javier Barroso wrote:
> Hello Hector,
> 
> It work for me:
> 
> $ grep "Include\|testing" /etc/ssh/ssh_config ; cat /etc/ssh/ssh.d/test
> Include /etc/ssh/ssh.d/test
> Host testing
> Hostname 1.1.1.1
> 
> $ ssh test => testing
> $ dpkg -l bash-completion
> Deseado=desconocido(U)/Instalar/eliminaR/Purgar/retener(H)
> | 
> Estado=No/Inst/ficheros-Conf/desempaqUetado/medio-conF/medio-inst(H)/espera-disparo(W)/pendienTe-disparo
> |/ Err?=(ninguno)/requiere-Reinst (Estado,Err: mayúsc.=malo)
> ||/ Nombre  Versión  Arquitectura
>Descripción
> +++-===---
> ii  bash-completion 1:2.8-1  all
>programmable completion for the bash shell

Ah, yep - so you've got the newer version from buster or sid,
presumably. I'm on stretch. Good to know that buster will fix it :-)

I guess I could request a backport, but it's probably not worth it.

Richard



signature.asc
Description: OpenPGP digital signature


Re: ssh config "Include" and bash completion

2018-05-14 Thread Richard Hector
On 14/05/18 18:09, Richard Hector wrote:
> Hi all,
> 
> I recently started using the Include directive in my .ssh/config file -
> so all the definitions are now in .ssh/config.d/.
> 
> Now bash completion of hostnames no longer works. Is this expected
> behaviour? Anyone know how to fix it, without reverting to a single file?
> 
> I couldn't work out how to filter down a web search to find anything
> useful :-(

Aha. There's a debian bug:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=834695
which refers to a solved upstream bug:
https://github.com/scop/bash-completion/issues/70

... so I guess I just have to wait for it to get to debian, probably in
buster.

In the meantime, I've modified
/usr/share/bash-completion/bash_completion

to suit my own needs (diff attached).

Richard
--- /usr/share/bash-completion/bash_completion.orig	2018-05-14 21:43:30.775922065 +1200
+++ /usr/share/bash-completion/bash_completion	2018-05-14 21:45:06.338031392 +1200
@@ -1448,7 +1448,7 @@
 if [[ -n $configfile ]]; then
 [[ -r $configfile ]] && config+=( "$configfile" )
 else
-for i in /etc/ssh/ssh_config ~/.ssh/config ~/.ssh2/config; do
+for i in /etc/ssh/ssh_config ~/.ssh/config ~/.ssh2/config ~/.ssh/config.d/*; do
 [[ -r $i ]] && config+=( "$i" )
 done
 fi


signature.asc
Description: OpenPGP digital signature


Re: ssh config "Include" and bash completion

2018-05-14 Thread Javier Barroso
On Mon, May 14, 2018 at 11:51 AM, Javier Barroso  wrote:
> Hello Hector,
>
> It work for me:
>
> $ grep "Include\|testing" /etc/ssh/ssh_config ; cat /etc/ssh/ssh.d/test
> Include /etc/ssh/ssh.d/test
> Host testing
> Hostname 1.1.1.1
>
> $ ssh test => testing
> $ dpkg -l bash-completion
> Deseado=desconocido(U)/Instalar/eliminaR/Purgar/retener(H)
> | 
> Estado=No/Inst/ficheros-Conf/desempaqUetado/medio-conF/medio-inst(H)/espera-disparo(W)/pendienTe-disparo
> |/ Err?=(ninguno)/requiere-Reinst (Estado,Err: mayúsc.=malo)
> ||/ Nombre  Versión  Arquitectura
>Descripción
> +++-===---
> ii  bash-completion 1:2.8-1  all
>programmable completion for the bash shell
>
> At bash_completioni script:
>
> $ grep Inclu /usr/share/bash-completion/bash_completion -A10
> # This function look for the "Include" keyword in ssh config files and include
> # them recursively adding each result to the config variable
> _included_ssh_config_files()
> {
> [[ $# -lt 1 ]] && echo "error: $FUNCNAME: missing mandatory argument 
> CONFIG"
> local configfile i f
> configfile=$1
> local included=$( command sed -ne
> 's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\{1,\}\([^#%]*\)\(#.*\)\{0,1\}$/\1/p'
> "${configfile}" )
> for i in ${included[@]}; do
> # Check the origin of $configfile to complete relative
> included paths on included
> # files according to ssh_config(5):
> --
> # The Included file is processed to look for Included
> files in itself
> _included_ssh_config_files $f
> fi
> done
> done
> } # _included_ssh_config_files()
>
>
> Regards
>
> On Mon, May 14, 2018 at 11:32 AM, Richard Hector  
> wrote:
>> On 14/05/18 20:49, john doe wrote:
>>> On 5/14/2018 8:09 AM, Richard Hector wrote:
 Hi all,

 I recently started using the Include directive in my .ssh/config file -
 so all the definitions are now in .ssh/config.d/.

 Now bash completion of hostnames no longer works. Is this expected
 behaviour? Anyone know how to fix it, without reverting to a single file?

>>>
>>> The only work around I can think of is:
>>>
>>> $ cat ~/.ssh/config
>>> host x
>>> include ~/.config.d/x
>>>
>>> $ cat ~/.ssh/config.d/x
>>> hostname x.example.com
>>>
>>
>> Meaning all my hosts need to be specified in both places? Not really
>> convenient.
>>
>> I don't actually use one file per host; I use one per 'group' -
>> generally a client, or perhaps a vm or container host.
>>
>> I assume there's a way to modify the bash completion config, but I
>> haven't looked at that. (Now I have, and it's ... going to require
>> further study.)
>>
>> Richard
>>
Sorry for the top posting (and this second mail :( )



Re: ssh config "Include" and bash completion

2018-05-14 Thread Javier Barroso
Hello Hector,

It work for me:

$ grep "Include\|testing" /etc/ssh/ssh_config ; cat /etc/ssh/ssh.d/test
Include /etc/ssh/ssh.d/test
Host testing
Hostname 1.1.1.1

$ ssh test => testing
$ dpkg -l bash-completion
Deseado=desconocido(U)/Instalar/eliminaR/Purgar/retener(H)
| 
Estado=No/Inst/ficheros-Conf/desempaqUetado/medio-conF/medio-inst(H)/espera-disparo(W)/pendienTe-disparo
|/ Err?=(ninguno)/requiere-Reinst (Estado,Err: mayúsc.=malo)
||/ Nombre  Versión  Arquitectura
   Descripción
+++-===---
ii  bash-completion 1:2.8-1  all
   programmable completion for the bash shell

At bash_completioni script:

$ grep Inclu /usr/share/bash-completion/bash_completion -A10
# This function look for the "Include" keyword in ssh config files and include
# them recursively adding each result to the config variable
_included_ssh_config_files()
{
[[ $# -lt 1 ]] && echo "error: $FUNCNAME: missing mandatory argument CONFIG"
local configfile i f
configfile=$1
local included=$( command sed -ne
's/^[[:blank:]]*[Ii][Nn][Cc][Ll][Uu][Dd][Ee][[:blank:]]\{1,\}\([^#%]*\)\(#.*\)\{0,1\}$/\1/p'
"${configfile}" )
for i in ${included[@]}; do
# Check the origin of $configfile to complete relative
included paths on included
# files according to ssh_config(5):
--
# The Included file is processed to look for Included
files in itself
_included_ssh_config_files $f
fi
done
done
} # _included_ssh_config_files()


Regards

On Mon, May 14, 2018 at 11:32 AM, Richard Hector  wrote:
> On 14/05/18 20:49, john doe wrote:
>> On 5/14/2018 8:09 AM, Richard Hector wrote:
>>> Hi all,
>>>
>>> I recently started using the Include directive in my .ssh/config file -
>>> so all the definitions are now in .ssh/config.d/.
>>>
>>> Now bash completion of hostnames no longer works. Is this expected
>>> behaviour? Anyone know how to fix it, without reverting to a single file?
>>>
>>
>> The only work around I can think of is:
>>
>> $ cat ~/.ssh/config
>> host x
>> include ~/.config.d/x
>>
>> $ cat ~/.ssh/config.d/x
>> hostname x.example.com
>>
>
> Meaning all my hosts need to be specified in both places? Not really
> convenient.
>
> I don't actually use one file per host; I use one per 'group' -
> generally a client, or perhaps a vm or container host.
>
> I assume there's a way to modify the bash completion config, but I
> haven't looked at that. (Now I have, and it's ... going to require
> further study.)
>
> Richard
>



Re: ssh config "Include" and bash completion

2018-05-14 Thread Richard Hector
On 14/05/18 20:49, john doe wrote:
> On 5/14/2018 8:09 AM, Richard Hector wrote:
>> Hi all,
>>
>> I recently started using the Include directive in my .ssh/config file -
>> so all the definitions are now in .ssh/config.d/.
>>
>> Now bash completion of hostnames no longer works. Is this expected
>> behaviour? Anyone know how to fix it, without reverting to a single file?
>>
> 
> The only work around I can think of is:
> 
> $ cat ~/.ssh/config
> host x
> include ~/.config.d/x
> 
> $ cat ~/.ssh/config.d/x
> hostname x.example.com
> 

Meaning all my hosts need to be specified in both places? Not really
convenient.

I don't actually use one file per host; I use one per 'group' -
generally a client, or perhaps a vm or container host.

I assume there's a way to modify the bash completion config, but I
haven't looked at that. (Now I have, and it's ... going to require
further study.)

Richard



signature.asc
Description: OpenPGP digital signature


Re: ssh config "Include" and bash completion

2018-05-14 Thread john doe

On 5/14/2018 8:09 AM, Richard Hector wrote:

Hi all,

I recently started using the Include directive in my .ssh/config file -
so all the definitions are now in .ssh/config.d/.

Now bash completion of hostnames no longer works. Is this expected
behaviour? Anyone know how to fix it, without reverting to a single file?



The only work around I can think of is:

$ cat ~/.ssh/config
host x
include ~/.config.d/x

$ cat ~/.ssh/config.d/x
hostname x.example.com

--
John Doe