Skip to content

Instantly share code, notes, and snippets.

@NigoroJr
Last active March 11, 2016 20:27
Show Gist options
  • Select an option

  • Save NigoroJr/6ab2043064d5e3637ee2 to your computer and use it in GitHub Desktop.

Select an option

Save NigoroJr/6ab2043064d5e3637ee2 to your computer and use it in GitHub Desktop.
Randomly shuffle and sample arguments
#!/usr/bin/env ruby
# Example usage in zsh:
#
# mplayer ${(f@)"$( this_script ~/Music/*.mp3 )"}
require 'slop'
opts = Slop.parse do |o|
o.integer '-s', '--sample', 'Number of samples to take', default: 0
o.bool '-h', '--help', 'Show this help'
end
if opts.help?
puts opts
exit 0
end
arr = opts.args
arr = opts[:sample] == 0 ? arr.shuffle : arr.sample(opts[:sample])
puts arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment