Re: [PATCH 1/3] completion: fix alias listings with newlines
- From
Stephen Boyd <bebarino@gmail.com>
- Date
- Oct 7, 2009, 18:55 UTC
- Message-ID
- <4ACCE417.5080907@gmail.com>
- In-Reply-To
- <4ACC6055.1070204@viscovery.net>
Johannes Sixt wrote:
Show 13 quoted lines
> Is it necessary to change the body of the loop? Your version spawns two
> processes on each iteration, while the original spawned no processes.
>
> You can avoid the pipeline (i.e. yet another process) using a "here-string":
>
> local i aliases=$(git --git-dir="$(__gitdir)" config -z \
> --get-regexp "alias\..*" 2>/dev/null)
> while IFS= read -rd '' i; do
> i="${i#alias.}"
> echo "${i/ */}" # could be: echo "${i%% *}"
> done <<< "$aliases"
>
> but I don't know how well bash handles variable values with embedded NULs.I can't get the above snippet to work, but maybe I'm doing something wrong.
I had a problem with the newline between the key and the value. bash gives me the whole line in the loop, but when I try to trim it $i is treated as two values. I couldn't figure out any other way to do it, besides piping $i to cut or tr.
Maybe a better solution would be to add --keys-only or something to git-config?