openSUSE / zypper

World's most powerful command line package manager
http://en.opensuse.org/Portal:Zypper
Other
403 stars 110 forks source link

Prefer unaliased `grep` to avoid unexpected/wrong completions. #503

Closed tfpf closed 11 months ago

tfpf commented 11 months ago

If

alias grep='grep -n'

is set before zypper's programmable completion script is sourced, the latter malfunctions. For instance, typing zypper remove and then pressing TABTAByq results in the following.

$ zypper remove 
Display all 2075 possibilities? (y or n)
1000\:libpaper                                    1935\:xfwm4-lang
1001\:libpaper-tools                              1936\:xhost
1002\:libpaper2                                   1937\:xiccd
1003\:libparted-fs-resize0                        1938\:xinit
1004\:libparted2                                  1939\:xkbcomp
1005\:libpathplan4                                193\:farstream-data
1006\:libpci3                                     1940\:xkeyboard-config
1007\:libpciaccess0                               1941\:xkeyboard-config-lang
1008\:libpcre1                                    1942\:xli
1009\:libpcre2-16-0                               1943\:xmessage
100\:bzip2                                        1944\:xml-commons-apis
1010\:libpcre2-32-0                               1945\:xmodmap
1011\:libpcre2-8-0                                1946\:xorg-x11-Xvnc
1012\:libpcre2-posix3                             1947\:xorg-x11-Xvnc-module
1013\:libpcsclite1                                1948\:xorg-x11-driver-video
1014\:libpeas-1_0-0                               1949\:xorg-x11-essentials
1015\:libpeas-gtk-1_0-0                           194\:fdupes
1016\:libpeas-lang                                1950\:xorg-x11-fonts
1017\:libpeas-loader-python3                      1951\:xorg-x11-fonts-converted
1018\:libpgm-5_3-0                                1952\:xorg-x11-fonts-core
1019\:libpipeline1                                1953\:xorg-x11-fonts-legacy
101\:ca-certificates                              1954\:xorg-x11-libX11-ccache
1020\:libpipewire-0_3-0                           1955\:xorg-x11-server
1021\:libpixman-1-0                               1956\:xorg-x11-server-Xvfb
1022\:libpkgconf3                                 1957\:xorg-x11-server-extra
$ zypper remove 

A simple fix is to use \grep instead of grep. Though this does raise the question: should cut and sed get the same treatment?

Notes

mlandres commented 11 months ago

Thanks for raising this. You are right, it may in fact affect any command used inside. Maybe even an \unalias -a at the beginning is appropriate. We'll review the script.

tfpf commented 11 months ago

The \unalias -a suggestion got me thinking: it won't touch any functions, so it may not fully address the problem? Upon some experimentation, I found that if a function grep is defined, \grep actually calls that function instead of running /bin/grep. However, command grep runs /bin/grep.