Created
February 12, 2009 22:44
-
-
Save brendano/62916 to your computer and use it in GitHub Desktop.
commandline map
This file contains 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 | |
# like map(), except on shell pipelines | |
# one arg: the mapper | |
# transform input lines, via the mapper, into output lines | |
# mapper is eval'd within the input line string | |
# | |
# extract 2nd column | |
# cat file | map 'split[1]' | |
# normalize url's | |
# cat kinda-urls | map 'if self !~ %r[^http://] then "http://#{self}" else self; end' | |
# designed for dotfiles.org/~brendano/.irbrc | |
if File.exists?("#{ENV['HOME']}/.irbrc") | |
$irbrc_extensions_only = true | |
load "~/.irbrc" | |
end | |
cmd = ARGV.join(" ") | |
STDIN.each do |line| | |
puts line.chomp.instance_eval { eval cmd } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment