Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #243618 > unrolled thread
| Started by | Long Wind <longwind2@yahoo.com> |
|---|---|
| First post | 2022-01-03 06:30 +0100 |
| Last post | 2022-01-04 20:40 +0100 |
| Articles | 11 — 4 participants |
Back to article view | Back to linux.debian.user
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
why bash completion sometimes doesn't work? Long Wind <longwind2@yahoo.com> - 2022-01-03 06:30 +0100
Re: why bash completion sometimes doesn't work? Greg Wooledge <greg@wooledge.org> - 2022-01-03 13:30 +0100
Re: why bash completion sometimes doesn't work? Richmond <richmond@criptext.com> - 2022-01-03 15:50 +0100
Re: why bash completion sometimes doesn't work? Long Wind <longwind2@yahoo.com> - 2022-01-03 21:20 +0100
Re: why bash completion sometimes doesn't work? Greg Wooledge <greg@wooledge.org> - 2022-01-03 21:30 +0100
Re: why bash completion sometimes doesn't work? David Wright <deblis@lionunicorn.co.uk> - 2022-01-03 22:50 +0100
Re: why bash completion sometimes doesn't work? Long Wind <longwind2@yahoo.com> - 2022-01-04 01:00 +0100
Re: why bash completion sometimes doesn't work? Greg Wooledge <greg@wooledge.org> - 2022-01-04 03:30 +0100
Re: why bash completion sometimes doesn't work? Long Wind <longwind2@yahoo.com> - 2022-01-04 03:50 +0100
Re: why bash completion sometimes doesn't work? Greg Wooledge <greg@wooledge.org> - 2022-01-04 04:00 +0100
Re: why bash completion sometimes doesn't work? David Wright <deblis@lionunicorn.co.uk> - 2022-01-04 20:40 +0100
| From | Long Wind <longwind2@yahoo.com> |
|---|---|
| Date | 2022-01-03 06:30 +0100 |
| Subject | why bash completion sometimes doesn't work? |
| Message-ID | <DBo4V-4oV-1@gated-at.bofh.it> |
when i type "ifdown wl" and press Tab, it shall complete it with full device name wlx12345 i believe it's taken from /etc/network/interfaces but sometimes it doesn't work in buster
[toc] | [next] | [standalone]
| From | Greg Wooledge <greg@wooledge.org> |
|---|---|
| Date | 2022-01-03 13:30 +0100 |
| Message-ID | <DBuDn-8jx-5@gated-at.bofh.it> |
| In reply to | #243618 |
On Mon, Jan 03, 2022 at 05:25:31AM +0000, Long Wind wrote: > when i type "ifdown wl" and press Tab, it shall complete it with full device name wlx12345 > i believe it's taken from /etc/network/interfaces > but sometimes it doesn't work in buster You're describing "programmable completion", which is an optional feature of bash. It's done on a per-command basis. E.g. if you type "cd wlx<TAB>" it will not complete the wlx word using interface names, because there is no such completion defined for the "cd" command. Apparently there is (on your system) for "ifdown" though. By default, Debian installs the bash-completion package, which contains programmable completions for a whole bunch of commands. This is enabled by dotting in a file from ~/.bashrc (the code to do this is at the end of /etc/skel/.bashrc, which becomes the default user ~/.bashrc file if you add users with "adduser"). Unless told otherwise, we're going to assume you're using bash (not zsh) as your shell, and that you've got the standard Debian ~/.bashrc file, so that bash's programmable completion has been enabled. If some programmable completion isn't working the way you expect, then you need to gather some more information. Give us the versions of the bash and bash-completion packages that you've got installed, and then tell us the EXACT command you typed, and what results you got by pressing Tab.
[toc] | [prev] | [next] | [standalone]
| From | Richmond <richmond@criptext.com> |
|---|---|
| Date | 2022-01-03 15:50 +0100 |
| Message-ID | <DBwOU-16h-25@gated-at.bofh.it> |
| In reply to | #243628 |
Greg Wooledge <greg@wooledge.org> writes: > By default, Debian installs the bash-completion package, which contains > programmable completions for a whole bunch of commands. This is > enabled by dotting in a file from ~/.bashrc (the code to do this is > at the end of /etc/skel/.bashrc, which becomes the default user ~/.bashrc > file if you add users with "adduser"). > Reading this has solved something which has puzzled me for some time. My .bashrc is a leftover from when I was running Opensuse, and so bash completion has never quite worked properly on the su command. Now I have copied /etc/skel/.bashrc and it is working!
[toc] | [prev] | [next] | [standalone]
| From | Long Wind <longwind2@yahoo.com> |
|---|---|
| Date | 2022-01-03 21:20 +0100 |
| Message-ID | <DBBYd-4lx-1@gated-at.bofh.it> |
| In reply to | #243628 |
Thank Greg! i use bash 5.0-4 and bash-completion 1:2.8-6 all bash setting for root is default except 3 alias alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' i type "ifdown wl" and press Tab, nothing happens there's only one wireless device in /etc/network/interfaces it shall complete command to "ifdown wlx12345" i've read /etc/skel/.bashrc, programmable completion seems enabled by default and it works for other commands, e.g. i type "dhclient enp" and Tab, it becomes "dhclient enp0s1"
[toc] | [prev] | [next] | [standalone]
| From | Greg Wooledge <greg@wooledge.org> |
|---|---|
| Date | 2022-01-03 21:30 +0100 |
| Message-ID | <DBC7U-4oG-7@gated-at.bofh.it> |
| In reply to | #243638 |
On Mon, Jan 03, 2022 at 08:12:50PM +0000, Long Wind wrote:
> Thank Greg! i use bash 5.0-4 and bash-completion 1:2.8-6
> i type "ifdown wl" and press Tab, nothing happens
> there's only one wireless device in /etc/network/interfaces
> it shall complete command to "ifdown wlx12345"
>
> i've read /etc/skel/.bashrc, programmable completion seems enabled by default
> and it works for other commands, e.g. i type "dhclient enp" and Tab, it becomes "dhclient enp0s1"
Well. In this package, the completions for ifdown and dhclient
are very different. E.g. in dhclient's completion, there's code that
looks like this:
if [[ "$cur" == -* ]]; then
COMPREPLY=( $( compgen -W '-p -d -q -1 -r -lf -pf -cf -sf -s -g -n -nw
-w' -- "$cur" ) )
else
_available_interfaces
The ifdown completion, on the other hand, has:
if [[ $cword -eq 1 ]]; then
_configured_interfaces
COMPREPLY=( $(compgen -W '${COMPREPLY[@]}' -- "$cur") )
I wonder what the difference between _available_interfaces and
_configured_interfaces is. Looks important.
[toc] | [prev] | [next] | [standalone]
| From | David Wright <deblis@lionunicorn.co.uk> |
|---|---|
| Date | 2022-01-03 22:50 +0100 |
| Message-ID | <DBDnk-53X-11@gated-at.bofh.it> |
| In reply to | #243638 |
On Mon 03 Jan 2022 at 20:12:50 (+0000), Long Wind wrote: > Thank Greg! i use bash 5.0-4 and bash-completion 1:2.8-6 > all bash setting for root is default except 3 alias > > alias rm='rm -i' > alias cp='cp -i' > alias mv='mv -i' > > i type "ifdown wl" and press Tab, nothing happens > there's only one wireless device in /etc/network/interfaces > it shall complete command to "ifdown wlx12345" > > i've read /etc/skel/.bashrc, programmable completion seems enabled by default > and it works for other commands, e.g. i type "dhclient enp" and Tab, it becomes "dhclient enp0s1" Type: ifdown <TAB><TAB> and you should get a list that will contain at least "lo". Cancel that line and type: ip a to see what interfaces you actually have. Cheers, David.
[toc] | [prev] | [next] | [standalone]
| From | Long Wind <longwind2@yahoo.com> |
|---|---|
| Date | 2022-01-04 01:00 +0100 |
| Message-ID | <DBFp8-6fB-7@gated-at.bofh.it> |
| In reply to | #243642 |
Thank Greg and David! i type "ifdown <TAB><TAB>", it add lo automatically, wireless device isn't shown, though wireless connection works well i think "ip a" can list wireless device
[toc] | [prev] | [next] | [standalone]
| From | Greg Wooledge <greg@wooledge.org> |
|---|---|
| Date | 2022-01-04 03:30 +0100 |
| Message-ID | <DBHKh-7Lc-3@gated-at.bofh.it> |
| In reply to | #243660 |
On Mon, Jan 03, 2022 at 11:56:57PM +0000, Long Wind wrote:
> Thank Greg and David!
>
> i type "ifdown <TAB><TAB>", it add lo automatically,
> wireless device isn't shown, though wireless connection works well
>
> i think "ip a" can list wireless device
Well, it sounds like _configured_interfaces on your system only finds
"lo", whereas _available_interfaces finds a larger set.
_configured_interfaces is apparently defined in
/usr/share/bash-completion/bash_completion and includes this code:
if [[ -f /etc/debian_version ]]; then
# Debian system
COMPREPLY=($(compgen -W "$(command sed -ne 's|^iface \([^ ]\{1,\}\).*$|\
1|p' \
/etc/network/interfaces /etc/network/interfaces.d/* 2>/dev/null)" \
-- "$cur"))
If I'm reading that sed command correctly, it only works if there is
precisely ONE space between "iface" and the interface name.
Perhaps your iface lines in /etc/network/interfaces are using tabs, or
more than one space, between the word "iface" and the interface name.
If so, that's why this particular bash-completion function doesn't
return it.
It's also possible that your desired interfaces aren't defined in
/etc/network/interfaces at all. You might be using Network-Manager
instead, on that system. That's perfectly valid, but this bash-completion
function won't see those interfaces.
The _available_interfaces function (used by dhclient's completion function)
is very different. It calls "ifconfig -a" or "ip link show" and then
parses names out with awk. Or at least it tries to. Obviously that will
give different results, if your interfaces are defined by Network-Manager,
or systemd units, or if you used liberal whitespace, etc.
Have I mentioned yet that bash-completion has some notoriety for being
fragile and a bit broken at times? I don't use it personally. If it
works for you, that's great. But it's far from perfect.
[toc] | [prev] | [next] | [standalone]
| From | Long Wind <longwind2@yahoo.com> |
|---|---|
| Date | 2022-01-04 03:50 +0100 |
| Message-ID | <DBI3D-7RQ-3@gated-at.bofh.it> |
| In reply to | #243665 |
Thank Greg Wooledge! it seems solved, there's more whitespace between iface and device name, i correct it to just one space, and bash completion works for ifup/ifdown
[toc] | [prev] | [next] | [standalone]
| From | Greg Wooledge <greg@wooledge.org> |
|---|---|
| Date | 2022-01-04 04:00 +0100 |
| Message-ID | <DBIdj-7V1-5@gated-at.bofh.it> |
| In reply to | #243667 |
On Tue, Jan 04, 2022 at 02:39:24AM +0000, Long Wind wrote: > > Thank Greg Wooledge! > > it seems solved, > there's more whitespace between iface and device name, > i correct it to just one space, and bash completion works for ifup/ifdown Might be worth a bug report.
[toc] | [prev] | [next] | [standalone]
| From | David Wright <deblis@lionunicorn.co.uk> |
|---|---|
| Date | 2022-01-04 20:40 +0100 |
| Message-ID | <DBXP3-QH-13@gated-at.bofh.it> |
| In reply to | #243665 |
On Mon 03 Jan 2022 at 21:22:44 (-0500), Greg Wooledge wrote:
> On Mon, Jan 03, 2022 at 11:56:57PM +0000, Long Wind wrote:
> > Thank Greg and David!
> >
> > i type "ifdown <TAB><TAB>", it add lo automatically,
> > wireless device isn't shown, though wireless connection works well
> >
> > i think "ip a" can list wireless device
>
> Well, it sounds like _configured_interfaces on your system only finds
> "lo", whereas _available_interfaces finds a larger set.
>
> _configured_interfaces is apparently defined in
> /usr/share/bash-completion/bash_completion and includes this code:
>
> if [[ -f /etc/debian_version ]]; then
> # Debian system
> COMPREPLY=($(compgen -W "$(command sed -ne 's|^iface \([^ ]\{1,\}\).*$|\
> 1|p' \
> /etc/network/interfaces /etc/network/interfaces.d/* 2>/dev/null)" \
> -- "$cur"))
>
> If I'm reading that sed command correctly, it only works if there is
> precisely ONE space between "iface" and the interface name.
>
> Perhaps your iface lines in /etc/network/interfaces are using tabs, or
> more than one space, between the word "iface" and the interface name.
> If so, that's why this particular bash-completion function doesn't
> return it.
>
> It's also possible that your desired interfaces aren't defined in
> /etc/network/interfaces at all. You might be using Network-Manager
> instead, on that system. That's perfectly valid, but this bash-completion
> function won't see those interfaces.
There's another assumption in that pattern: that /e/n/i contains
source /etc/network/interfaces.d/*
That line could be absent, pointing somewhere else, or it could
be the subtly different source-directory keyword that filters
the filenames in the directories to a particular charset.
> The _available_interfaces function (used by dhclient's completion function)
> is very different. It calls "ifconfig -a" or "ip link show" and then
> parses names out with awk. Or at least it tries to. Obviously that will
> give different results, if your interfaces are defined by Network-Manager,
> or systemd units, or if you used liberal whitespace, etc.
>
> Have I mentioned yet that bash-completion has some notoriety for being
> fragile and a bit broken at times? I don't use it personally. If it
> works for you, that's great. But it's far from perfect.
Cheers,
David.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.debian.user
csiph-web