Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Array assignment? Funny prompt magic?
- X-seq: zsh-users 13576
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: Webb Sprague <webb.sprague@xxxxxxxxx>
- Subject: Re: Array assignment? Funny prompt magic?
- Date: Wed, 10 Dec 2008 16:57:19 +0000
- Cc: zsh-users@xxxxxxxxxx
- In-reply-to: <b11ea23c0812100812u374b5c21lfb899d422994f455@xxxxxxxxxxxxxx>
- Mail-followup-to: Webb Sprague <webb.sprague@xxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <b11ea23c0812100812u374b5c21lfb899d422994f455@xxxxxxxxxxxxxx>
On Wed, Dec 10, 2008 at 08:12:32AM -0800, Webb Sprague wrote:
> HI all,
>
> (II know I should be digging through the docs, but this is so easy and
> I get such great answers!)
>
> (1) Is x=($y) the correct way to assign an array to x? I worry that
> first $y gets converted to text, then mangled with ().
If $y is an array, then
x=($y)
will copy the non empty elements of $y into a new $x array, you
want:
x=("${y[@]}")
to also copy the empty elements. the above creates an exact copy
of the array.
If $y is a scalar,
x=($y)
creates an array of 0 or 1 elements depending on whether $y is
empty or not. You want:
x=("$y")
if you want $x to contain only one element which is the content
of $y (regardless of whether it's empty or not).
If $y is an associative array:
x=($y)
will make an array of the non-empty values (not the keys) of the
associative array.
If $y is a scalar and you want it split (word splitting using
$IFS as in other shells), you should do:
x=($=y)
if you also want filename generation to be performed on each of
the resulting words from the splitting (that is for instance if
you want "*" to be replaced by the list of files in the current
directory), you should do:
x=($=~y)
which would then be the equivalent of bash's
z=($y)
> (2) Is there a way to set the names of the background processes for
> the prompt? I use %j to count the number of them, but a list that
> goes like "%vim, %vim, %man" (or some such) would be great. My
> analogy is to completing backrounded jobs with "fg <TAB>"
[...]
See the $jobtexts special associative array:
$ sleep 1000 &
[1] 11165
$ printf '%s => %s\n' "${(@kv)jobstates}"
1 => running:+:11165=running
$ printf '%s => %s\n' "${(@kv)jobtexts}"
1 => sleep 1000
$ echo ${(t)jobtexts}
association-readonly-hide-hideval-special
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author