[pacman-dev] [PATCH] bash_completion: remove absolute utility paths again
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash. Signed-off-by: Cedric Staniewski <cedric@gmx.ca> --- contrib/bash_completion | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-) diff --git a/contrib/bash_completion b/contrib/bash_completion index 62e5bc9..40ef8c0 100644 --- a/contrib/bash_completion +++ b/contrib/bash_completion @@ -14,7 +14,7 @@ rem_selected () # (Adapted from bash_completion by Ian Macdonald <ian@caliban.org>) # This removes any options from the list of completions that have # already been specified on the command line. - COMPREPLY=($(/bin/echo "${COMP_WORDS[@]}" | \ + COMPREPLY=($(\echo "${COMP_WORDS[@]}" | \ (while read -d ' ' i; do [ "${i}" == "" ] && continue # flatten array with spaces on either side, @@ -24,20 +24,20 @@ rem_selected () # remove word from list of completions COMPREPLY=(${COMPREPLY/ ${i%% *} / }) done - /bin/echo ${COMPREPLY[@]}))) + \echo ${COMPREPLY[@]}))) return 0 } _available_repos () { - COMPREPLY=( $( compgen -W "$(/bin/grep '\[' /etc/pacman.conf | /bin/grep -v -e 'options' -e '^#' | tr -d '[]' )" -- $cur ) ) + COMPREPLY=( $( compgen -W "$(\grep '\[' /etc/pacman.conf | \grep -v -e 'options' -e '^#' | \tr -d '[]' )" -- $cur ) ) } _installed_pkgs () { local installed_pkgs - installed_pkgs=$( /bin/ls /var/lib/pacman/local/ ) - COMPREPLY=( $( compgen -W "$( for i in $installed_pkgs; do /bin/echo ${i%-*-*}; done )" -- $cur ) ) + installed_pkgs=$( \ls /var/lib/pacman/local/ ) + COMPREPLY=( $( compgen -W "$( for i in $installed_pkgs; do \echo ${i%-*-*}; done )" -- $cur ) ) } _available_pkgs () @@ -47,16 +47,16 @@ _available_pkgs () # This little change-up removes the find *and* only uses enabled repos local available_pkgs local enabled_repos - enabled_repos=$( /bin/grep '\[' /etc/pacman.conf | /bin/grep -v -e 'options' -e '^#' | tr -d '[]' ) - available_pkgs=$( for r in $enabled_repos; do /bin/echo /var/lib/pacman/sync/$r/*; done ) + enabled_repos=$( \grep '\[' /etc/pacman.conf | \grep -v -e 'options' -e '^#' | \tr -d '[]' ) + available_pkgs=$( for r in $enabled_repos; do \echo /var/lib/pacman/sync/$r/*; done ) COMPREPLY=( $( compgen -W "$( for i in $available_pkgs; do j=${i##*/}; echo ${j%-*-*}; done )" -- $cur ) ) } _installed_groups () { local installed_groups - installed_groups=$( /bin/find /var/lib/pacman/local -name desc -exec /bin/sed -ne '/%GROUPS%/,/^$/{//d; p}' {} \; | /bin/sort -u ) - COMPREPLY=( $( compgen -W "$( for i in $installed_groups; do /bin/echo ${i%-*-*}; done )" -- $cur ) ) + installed_groups=$( \find /var/lib/pacman/local -name desc -exec \sed -ne '/%GROUPS%/,/^$/{//d; p}' {} \; | \sort -u ) + COMPREPLY=( $( compgen -W "$( for i in $installed_groups; do \echo ${i%-*-*}; done )" -- $cur ) ) } _available_groups () @@ -66,9 +66,9 @@ _available_groups () # This little change-up removes the find *and* only uses enabled repos local available_groups local enabled_repos - enabled_repos=$( /bin/grep '\[' /etc/pacman.conf | /bin/grep -v -e 'options' -e '^#' | tr -d '[]' ) - available_groups=$( for r in $enabled_repos; do /bin/sed '/%GROUPS%/,/^$/{//d; p}' /var/lib/pacman/sync/$r/*/desc | /bin/sort -u; done ) - COMPREPLY=( $( compgen -W "$( for i in $available_groups; do /bin/echo ${i%-*-*}; done )" -- $cur ) ) + enabled_repos=$( \grep '\[' /etc/pacman.conf | \grep -v -e 'options' -e '^#' | tr -d '[]' ) + available_groups=$( for r in $enabled_repos; do \sed '/%GROUPS%/,/^$/{//d; p}' /var/lib/pacman/sync/$r/*/desc | \sort -u; done ) + COMPREPLY=( $( compgen -W "$( for i in $available_groups; do \echo ${i%-*-*}; done )" -- $cur ) ) } ## makepkg completion @@ -126,7 +126,7 @@ _instring () str="${1}" shift 1 for c in "${@}"; do - if [ $(/bin/expr index "${str}" "${c}") -gt 0 ]; then + if [ $(\expr index "${str}" "${c}") -gt 0 ]; then return 0 fi done @@ -193,7 +193,7 @@ _pacman () esac arglen=$(( ${#toparse}-1 )) - for c in $(/bin/seq 0 "${arglen}"); do + for c in $(\seq 0 "${arglen}"); do arg=${toparse:$c:1} [ "${arg}" != "-" ] && mod="${mod}${arg}" done -- 1.7.0
On Thu, Feb 25, 2010 at 4:23 PM, Cedric Staniewski <cedric@gmx.ca> wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
Holy crap, that works? Where did you find this trick?
On 25.02.2010 23:43, Aaron Griffin wrote:
On Thu, Feb 25, 2010 at 4:23 PM, Cedric Staniewski <cedric@gmx.ca> wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
Holy crap, that works? Where did you find this trick?
Seems so. I found it in a blog post[1] but not in bash's man page. [1] http://blog.zelut.org/2009/03/14/temporarily-disable-aliases-in-bash/
On 26 February 2010 06:56, Cedric Staniewski <cedric@gmx.ca> wrote:
On 25.02.2010 23:43, Aaron Griffin wrote:
On Thu, Feb 25, 2010 at 4:23 PM, Cedric Staniewski <cedric@gmx.ca> wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
Holy crap, that works? Where did you find this trick?
Seems so. I found it in a blog post[1] but not in bash's man page.
[1] http://blog.zelut.org/2009/03/14/temporarily-disable-aliases-in-bash/
And presto, it really does: [schiv@v3000 ~]$ alias printf='printf "hi\n"' [schiv@v3000 ~]$ printf hi [schiv@v3000 ~]$ \printf printf: usage: printf [-v var] format [arguments] -- GPG/PGP ID: B42DDCAD
On Thu, Feb 25, 2010 at 4:56 PM, Cedric Staniewski <cedric@gmx.ca> wrote:
On 25.02.2010 23:43, Aaron Griffin wrote:
On Thu, Feb 25, 2010 at 4:23 PM, Cedric Staniewski <cedric@gmx.ca> wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
Holy crap, that works? Where did you find this trick?
Seems so. I found it in a blog post[1] but not in bash's man page.
[1] http://blog.zelut.org/2009/03/14/temporarily-disable-aliases-in-bash/
This appears undocumented. I can't find any mention in the man page
On 26 February 2010 07:03, Aaron Griffin <aaronmgriffin@gmail.com> wrote:
On Thu, Feb 25, 2010 at 4:56 PM, Cedric Staniewski <cedric@gmx.ca> wrote:
On 25.02.2010 23:43, Aaron Griffin wrote:
On Thu, Feb 25, 2010 at 4:23 PM, Cedric Staniewski <cedric@gmx.ca> wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
Holy crap, that works? Where did you find this trick?
Seems so. I found it in a blog post[1] but not in bash's man page.
[1] http://blog.zelut.org/2009/03/14/temporarily-disable-aliases-in-bash/
This appears undocumented. I can't find any mention in the man page
Probably because \ is "already" documented as being an escape character, allowing the string to be taken literally by the shell, hence skipping possible aliases in this case. The closest form of documentation comes from TLDP [1]: [quote] The alias command will list your current aliases. You can use unalias to remove the alias (to disable it just for one command add a “\” (back-slash) before the command)... [/quote] [1] http://tldp.org/LDP/GNU-Linux-Tools-Summary/html/c1195.htm -- GPG/PGP ID: B42DDCAD
add a “\” (back-slash) before the command)...
it is even working if \ is in the middle of the command name try: $ l\s $ alias printf='print hi\n"' and then try $ prin\tf from #bash@irc.freenode.net <ferret> you can also use 'command' or "command" <ferret> or l\s <ferret> or ''ls
On Thu, Feb 25, 2010 at 6:03 PM, Aaron Griffin <aaronmgriffin@gmail.com> wrote:
On Thu, Feb 25, 2010 at 4:56 PM, Cedric Staniewski <cedric@gmx.ca> wrote:
On 25.02.2010 23:43, Aaron Griffin wrote:
On Thu, Feb 25, 2010 at 4:23 PM, Cedric Staniewski <cedric@gmx.ca> wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
Holy crap, that works? Where did you find this trick?
Seems so. I found it in a blog post[1] but not in bash's man page.
[1] http://blog.zelut.org/2009/03/14/temporarily-disable-aliases-in-bash/
This appears undocumented. I can't find any mention in the man page
I think this is one of the very old tricks that was first done in the original csh, and picked up as "an obvious idea" by bash when it was started. Nowadays, we've all forgotten about it, and it's become mysterious.
On Thu, Feb 25, 2010 at 08:13:15PM -0500, Ray Kohler wrote:
I think this is one of the very old tricks that was first done in the original csh, and picked up as "an obvious idea" by bash when it was started. Nowadays, we've all forgotten about it, and it's become mysterious.
I can't reproduce this behavior on GNU bash, version 2.05b.0(1)-release (i386-portbld-freebsd4.7), but can on GNU bash, version 4.0.24(0)-release (amd64-portbld-freebsd7.2) and other 4.x bashes on various Linux boxes. I don't have bash 3 available, but someone already mentioned it working for that. -- Jeff My other computer is an abacus.
On 26/02/10 08:23, Cedric Staniewski wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
That seems fine to me. Just one check. How long has that syntax been available (i.e. is it a bash4ism)? Allan
On 25.02.2010 23:44, Allan McRae wrote:
On 26/02/10 08:23, Cedric Staniewski wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
That seems fine to me. Just one check. How long has that syntax been available (i.e. is it a bash4ism)?
Allan
Just tested it on GNU bash, version 3.2.39(1)-release and it works. So I guess it's safe to use.
On 26/02/10 08:57, Cedric Staniewski wrote:
On 25.02.2010 23:44, Allan McRae wrote:
On 26/02/10 08:23, Cedric Staniewski wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
That seems fine to me. Just one check. How long has that syntax been available (i.e. is it a bash4ism)?
Allan
Just tested it on GNU bash, version 3.2.39(1)-release and it works. So I guess it's safe to use.
Well, I am happy using this then. The lack of documentation for this feature may be a slight concern, but given it has been supported by bash for a long time, I think we can rely on it. Allan
On Thu, Feb 25, 2010 at 5:56 PM, Allan McRae <allan@archlinux.org> wrote:
On 26/02/10 08:57, Cedric Staniewski wrote:
On 25.02.2010 23:44, Allan McRae wrote:
On 26/02/10 08:23, Cedric Staniewski wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
That seems fine to me. Just one check. How long has that syntax been available (i.e. is it a bash4ism)?
Allan
Just tested it on GNU bash, version 3.2.39(1)-release and it works. So I guess it's safe to use.
Well, I am happy using this then. The lack of documentation for this feature may be a slight concern, but given it has been supported by bash for a long time, I think we can rely on it.
Wow this is pretty sweet. We do have some outstanding completion bugs/features though that we might want to incorporate in addition to this: http://bugs.archlinux.org/task/16630 Can someone look into it more and put a total package together (or a series of patches) that get us exactly where we want to be? I do apologize for getting broken software out there, even if it is only in git. -Dan
On Fri, Feb 26, 2010 at 09:56:05AM +1000, Allan McRae wrote:
On 26/02/10 08:57, Cedric Staniewski wrote:
On 25.02.2010 23:44, Allan McRae wrote:
On 26/02/10 08:23, Cedric Staniewski wrote:
The location of the used utilities may and does differ between various distributions and therefore absolute paths do not work well. Since the main purpose of its introduction was to avoid side-effects caused by aliases, it is sufficient to disable possible aliases temporarily by preceding the commands with a backslash.
That seems fine to me. Just one check. How long has that syntax been available (i.e. is it a bash4ism)?
Allan
Just tested it on GNU bash, version 3.2.39(1)-release and it works. So I guess it's safe to use.
Well, I am happy using this then. The lack of documentation for this feature may be a slight concern, but given it has been supported by bash for a long time, I think we can rely on it.
I've seen this documented before. I don't remember where, but before bash 4. I just checked the Advanced Bash Scripting guide, and the Bash Reference Manual, and didn't find it there. I see in the bash manpage this:
ALIASES Aliases allow a string to be substituted for a word when it is used as the first word of a simple command. The shell maintains a list of aliases that may be set and unset with the alias and unalias builtin commands (see SHELL BUILTIN COMMANDS below). The first word of each simple command, if unquoted, is checked to see if it has an alias. If so, that word is replaced by the text of the alias.
which arguably says that alias expansion won't occur on \echo or "echo". However, I did encounter a more explicit explanation of this somewhere or other... Sorry I hadn't been following the discussion that led up to this. -- Jim Pryor profjim@jimpryor.net
participants (9)
-
Aaron Griffin
-
Allan McRae
-
Cedric Staniewski
-
Dan McGee
-
Jeff
-
Jim Pryor
-
Ray Kohler
-
Ray Rashif
-
solsTiCe d'Hiver