-
Notifications
You must be signed in to change notification settings - Fork 97
Follow an uri
agorf edited this page Dec 9, 2014
·
5 revisions
Sup 0.20 introduces the possibility to open the uri that is under the cursor with the g
key. When the user presses the key, sup parses the text that is under the cursor and in the following lines, up to the next paragraph jump (ie 2 newlines). If there is an uri and there is goto
hook, it is called with the uri that is parsed.
A good, generic hook is the following script:
system("xdg-open #{uri} > /dev/null")
Warning: Any special shell characters are already escaped in uri
, so do not attempt to wrap it in double quotes. This will not work: system("xdg-open \"#{uri}\" > /dev/null")
This requires installation of xdg-utils. On archlinux, there is a packet for this, called xdg-utils
An interactive hook to choose the browser:
### goto.rb -- follow an uri
# interactively choose the browser to use
## Configuration
# Hash containing name => browser command
browsers = {
'firefox' => '/usr/bin/firefox',
'uzbl' => '/usr/bin/uzbl-tabbed',
'elinks' => '/usr/bin/elinks'
}
# default browser
default = "uzbl"
# prompt
prompt = "Follow Link with"
help = "(<tab> for choices, empty line for #{default})"
## Logic
# ask for browser
browser_key = nil
# ensure browser_key is in browsers.keys
until browsers.key? browser_key
# use BufferManager's dialog function (compare lib/sup/buffer.rb)
browser_key = BufferManager.ask_with_completions(
:sign, # token for BufferManager's sake.
"#{prompt}: ", # Prompt
browsers.keys) # Array with posible completions
# add help in case the first attempt was not successful
prompt = "#{prompt} #{help}"
# check for empty line and select default browser
if browser_key == ""
browser_key = default
break
end
end
# call browser with uri
system("#{browsers[browser_key]} \"#{uri}\" > /dev/null")