zsh-users
 help / color / mirror / code / Atom feed
* random once but not twice
@ 2017-11-11 18:57 Emanuel Berg
  2017-11-11 21:52 ` Mikael Magnusson
  0 siblings, 1 reply; 12+ messages in thread
From: Emanuel Berg @ 2017-11-11 18:57 UTC (permalink / raw)
  To: zsh-users

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

-- 
underground experts united
http://user.it.uu.se/~embe8573


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-11-13  5:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-11 18:57 random once but not twice Emanuel Berg
2017-11-11 21:52 ` Mikael Magnusson
2017-11-11 22:26   ` Emanuel Berg
2017-11-11 22:32     ` Emanuel Berg
2017-11-11 22:46       ` Emanuel Berg
2017-11-12 19:08         ` Peter Stephenson
2017-11-12 20:02           ` Emanuel Berg
2017-11-12 20:15             ` Bart Schaefer
2017-11-12 20:18               ` Emanuel Berg
2017-11-13  0:15           ` Emanuel Berg
2017-11-13  4:56             ` Bart Schaefer
2017-11-13  5:07               ` Emanuel Berg

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).