Last active
March 11, 2016 20:27
-
-
Save NigoroJr/6ab2043064d5e3637ee2 to your computer and use it in GitHub Desktop.
Randomly shuffle and sample arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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