scop / bash-completion

Programmable completion functions for bash
GNU General Public License v2.0
2.94k stars 380 forks source link

Wrong network interface name if the name is long #1089

Open hellodword opened 10 months ago

hellodword commented 10 months ago

Describe the bug

network interface name get truncated with ifconfig

To reproduce

$ ip link show up
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
3: nameislong: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000

$ ifconfig 
lo        Link encap:Local Loopback
eth0      Link encap:Ethernet
nameislongLink encap:(hwtype unknown)

https://github.com/scop/bash-completion/blob/2b7fc195aeb404b41bc3e5fa8c1e98f10f1ee26a/bash_completion#L1723-L1738

Then the _comp_compgen_available_interfaces -a will return nameislongLink instead of nameislong

Reproduce:

sudo tunctl -t nameislong
sudo ip addr add 10.23.45.0/24 dev nameislong
sudo ip link set dev  nameislong up

# TAB
curl --interface nameis

Expected behavior

Versions (please complete the following information)

Additional context

It's bug of upstream inetutils, but maybe we can simply use iproute2 as default choose

ip -c=never link show up || ip link show up || ifconfig

https://github.com/scop/bash-completion/blob/2b7fc195aeb404b41bc3e5fa8c1e98f10f1ee26a/bash_completion#L1731-L1733

yedayak commented 2 months ago

BTW, which packages provide ip and ifconfig on your system? I get different outputs on my system, the outputs span multiple lines

hellodword commented 2 months ago

BTW, which packages provide ip and ifconfig on your system? I get different outputs on my system, the outputs span multiple lines

For me it's inetutils-2.5, here is a minimal reproduce:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/d0e1602ddde669d5beb01aec49d71a51937ed7be";
  };

  outputs = { self, nixpkgs, ... }:
    let
      supportedSystems = [ "x86_64-linux" ];
      forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
        pkgs = import nixpkgs { inherit system; };
      });
    in
    {
      devShells = forEachSupportedSystem ({ pkgs }: rec {
        default = pkgs.mkShell {
          packages = with pkgs; [
            inetutils
            tunctl
          ];
        };
      });
    };
}