Module: RuVim::Gh::Link::HandlerMethods

Included in:
RuVim::Git::Handler
Defined in:
lib/ruvim/gh/link.rb

Instance Method Summary collapse

Instance Method Details

#gh_browse(ctx, argv: [], kwargs: {}) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/ruvim/gh/link.rb', line 145

def gh_browse(ctx, argv: [], kwargs: {}, **)
  url, warning = gh_resolve_url(ctx, argv: argv, kwargs: kwargs, command: "gh browse")
  return unless url

  unless Browser.open_url(url)
    ctx.editor.echo_error("gh browse: could not open browser")
    return
  end

  msg = warning ? "Opened #{url} #{warning}" : "Opened #{url}"
  ctx.editor.echo(msg)
end


133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ruvim/gh/link.rb', line 133

def gh_link(ctx, argv: [], kwargs: {}, **)
  url, warning = gh_resolve_url(ctx, argv: argv, kwargs: kwargs, command: "gh link")
  return unless url

  # Copy to clipboard via OSC 52
  $stdout.write(Link.osc52_copy_sequence(url))
  $stdout.flush

  msg = warning ? "#{url} #{warning}" : url
  ctx.editor.echo(msg)
end

#gh_pr(ctx) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/ruvim/gh/link.rb', line 158

def gh_pr(ctx, **)
  path = ctx.buffer.path || Dir.pwd
  url, err = Link.resolve_pr(path)
  unless url
    ctx.editor.echo_error("gh pr: #{err}")
    return
  end

  unless Browser.open_url(url)
    ctx.editor.echo_error("gh pr: could not open browser")
    return
  end

  ctx.editor.echo("Opened #{url}")
end