Module: CopyPaste

Includes:
ColorPuts
Defined in:
lib/copy-paste.rb,
lib/copy-paste/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



63
64
65
# File 'lib/copy-paste.rb', line 63

def self.included(base)
  cputs "%white{_cp} command available, type '%white{_cp_help}' for more info"
end

Instance Method Details

#_cp(obj = Readline::HISTORY.entries[-2], *options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/copy-paste.rb', line 6

def _cp(obj = Readline::HISTORY.entries[-2], *options)
  if obj.respond_to?(:join) && !options.include?(:a)
    if options.include?(:s)
      obj = obj.map { |element| ":#{element.to_s}" }
    end
    out = obj.join(", ")
  elsif obj.respond_to?(:inspect)
    out = obj.is_a?(String) ? obj : obj.inspect
  end

  if out
    IO.popen('pbcopy', 'w') { |io| io.write(out) }
    "copied!"
  end
end

#_cp_helpObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/copy-paste.rb', line 22

def _cp_help
  cputs "\n\n%white{_cp - copy stuff to OS X clipboard}\n\n\nIf no argument is given it takes the last line in HISTORY:\n  >> 5.times { \"nothing\"  }\n  # => 5\n  >> _cp\n  # => \"copied!\"\n  Pasteboard: 5.times { \"nothing\"  }\n\nCopy the result of the given argument:\n  >> _cp [\"foo\", \"bar\"]\n  # => \"copied!\"\n  Pasteboard: foo, bar\n\nConvert array elements to symbols:\n  >> _cp [\"foo\", \"bar\"], :s\n  # => \"copied!\"\n  Pasteboard: :foo, :bar\n\nCopy an array as syntax:\n  >> _cp [\"foo\", \"bar\"], :a\n  # => \"copied!\"\n  Pasteboard: [\"foo\", \"bar\"]\n\n\nCopy a hash:\n  >> h={:foo=>\"bar\", \"foo\"=>:bar}\n  # => {:foo=>\"bar\", \"foo\"=>:bar}\n  # >> _cp h\n  # => \"copied!\"\n  Pasteboard: {:foo=>\"bar\", \"foo\"=>:bar}\n\n\n  HELP\nend\n"