Skip to content

Instantly share code, notes, and snippets.

@brendano
Created February 12, 2009 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendano/62916 to your computer and use it in GitHub Desktop.
Save brendano/62916 to your computer and use it in GitHub Desktop.
commandline map
#!/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