Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: random once but not twice
- X-seq: zsh-users 22964
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: random once but not twice
- Date: Sat, 11 Nov 2017 22:52:48 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=JK8Woikwp9evojsWVitQnp6m3vbhO8Wp/yjt/muNGfU=; b=kISkZvQCjo+Fjw7obAFPlT6ZbVFs5ok0rDI5Q3S6u1VAmaJD9aeaIq3frCjMqUJQ8x aEIJjlxcktQZJTl8qUV0dxNygnGztTFNnJO7l83hWdiiDAIYcFF3TdXN4ix0mxFGtWT4 6kfM8I7f5lx/4PKElBuaVmkSBjATBrVZSl3KOfqDG6kydAHNBpQ8e1UO/2QLicS9/v2a TNyhxl4PbWzMIbJWZWyHS6hffQWpb02lENVbKQqEbFzJAAWRxVbJzSbTF24fcjSGJ7Hb YFjLISRimgiohHVTz+ddE8RUOHoqM/1YkpjiE1ZMW4NypEoWlCz/6mQXlOxMo4E5RUFa /4XA==
- In-reply-to: <86k1yw63u0.fsf@zoho.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <86k1yw63u0.fsf@zoho.com>
On Sat, Nov 11, 2017 at 7:57 PM, Emanuel Berg <moasen@xxxxxxxx> wrote:
> Just wrote this. Strange thing is, random-video
> gives me randomized files, but not
> play-random-video, which is just an interface -
> or that the intention, at least :)
>
> Can anyone figure out what is going on?
>
> All other suggestions how to improve the code,
> both style and function, is appreciated, as
> always...
>
> random-video () {
> local vid_dir=${1:-.}
> local ext=${2:-mkv}
>
> local vid
> local -a vids
> local num_vids
> local vid_num
>
> vids=("${(@f)$(ls ${vid_dir}/*.${ext})}")
> num_vids=${#vids}
>
> vid_num=$(( RANDOM % $num_vids + 1 ))
> vid=$vids[$vid_num]
>
> echo $vid
> }
> alias rv=random-video
>
> play-random-video () {
> local vid_dir=${1:-/mnt-disk/mm/survivor/au/04}
> local vid
> vid=$(random-video $vid_dir)
> echo "playing $vid"
> # pl $vid # local function to omx player
> }
> alias prv=play-random-video
The subshell in the second function ensures that the RANDOM state in
the parent shell stays the same.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author