Top Level Namespace

Defined Under Namespace

Modules: Togist

Instance Method Summary collapse

Instance Method Details

#checkIfPipedObject



61
62
63
# File 'lib/togist.rb', line 61

def checkIfPiped
  return !STDIN.tty?
end

#checkoutput(out) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/togist.rb', line 47

def checkoutput(out)
  if STDIN.tty? || out.include?("Usage: gist [options]")
    puts "Oops, you forgot to pipe something to ToGist\n\n"
    help
  elsif out.include?("getaddrinfo") || out.include?("Error")
    puts "There was an unknown error. Are you sure you can connect to github? \n\n"
    help
  else
    Clipboard.copy(out)
    puts "Gist: #{out} (copied to clipboard)"
    `open #{out}` if @open
  end
end

#helpObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/togist.rb', line 17

def help
  puts "ToGist #{Togist::VERSION}, the simple way to gist\n\n"
  puts "Usage:"
  puts "  Output files or commands and pipe them into either shortcut"
  puts "  e.g.:"
  puts "    echo 'foo' | 2g"
  puts "    cat foo.rb | 2g\n\n"
  puts "Shortcuts:"
  puts "  2g : Uploads to private gist and copies gist url to mac clipboard"
  puts "  2gpub : Same as above except public\n\n"
  puts "Tips:"
  puts "  Add an 'o' to the end of a shortcut to make it open your browser to the gist\n\n"
  puts "  e.g.:"
  puts "    echo 'foo' | 2go # Will open to the private gist url"
  puts "    echo 'foo' | 2gpubo # Will open to the public gist url"

end

#run2gObject



35
36
37
38
39
# File 'lib/togist.rb', line 35

def run2g
  out = `gist -p`

  checkoutput(out)
end

#run2gpubObject



41
42
43
44
45
# File 'lib/togist.rb', line 41

def run2gpub
  out = `gist`

  checkoutput(out)
end

#togistObject



8
9
10
11
12
13
14
15
# File 'lib/togist.rb', line 8

def togist
  if checkIfPiped
    run2g
  else
    help
  end

end