brendano (owner)

Revisions

gist: 62916 Download_button fork
public
Description:
commandline map
Public Clone URL: git://gist.github.com/62916.git
map.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/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