-
Notifications
You must be signed in to change notification settings - Fork 14
Config Snippets
Martin Mauch edited this page Feb 2, 2016
·
10 revisions
For completions that take too long to be calculated on the fly, the following snippet can generate .cache
files (simple text files that contain output in the exact same way as completions generate it).
[[completion]]
type="command"
trigger="cache (.*?) (.*)"
command="""echo 'rrun completions {1} "{2}" > ~/.config/rrun/{1}_{2}.cache\tCache completions for {1} {2}'"""
If rrun
itself is not in the PATH specify the absolute path to it like this
echo '/path/to/rrun completions ...
Once you have added the above completion, type something like the following in rrun to perform the caching
cache the_completion_type the_query_to_cache
You can use the code from a completion and store the STDOUT output to a .cache
file somewhere (preferrably in your ~/.config/rrun
directory).
Then use a snippet like the following to use the cached results:
[[completion]]
type="url"
command="cat ~/.config/rrun/url*.cache | grep -i {}"
trigger="u (.*)"
[[completion]]
type="url"
trigger="g (.*)"
command='''
ruby -r uri -r net/http -r json -e '
q = "{}"
q_quoted = URI.escape(q)
suggestions = [q] + JSON.parse(Net::HTTP.get(URI.parse("http://suggestqueries.google.com/complete/search?client=firefox&q=#{q_quoted}"))).last
puts suggestions.map {|s| s_quoted = URI.escape(s); "https://www.google.com/search?q=#{s_quoted}\tGoogle for #{s}"}.join("\n")'
'''
Requires the jsonpath gem to be available in your ruby installation (gem install jsonpath
).
[[completion]]
type="url"
trigger="url (.*)"
command='''
ruby -r json -r jsonpath -e'
bookmarks_hash = JSON.parse(File.read(File.expand_path("~/.config/google-chrome/Default/Bookmarks", Dir.home)))
children = JsonPath.new("$..children").on(bookmarks_hash).flatten
selector = "{}"
urls = children.select {|c| c.include?("name") && c.include?("url")}.map {|c| [c["url"],c["name"]]}
puts urls.map {|c| c.join("\t")}.grep(/#{selector}/i).join("\n")'
'''
[[completion]]
type="url"
trigger="de (.*)"
command='''
ruby -r uri -r net/http -r json -e '
q = "{}"
q_quoted = URI.escape(q)
suggestions = JSON.parse(Net::HTTP.get(URI.parse("http://dict.leo.org/dictQuery/m-query/conf/ende/query.conf/strlist.json?q=#{q_quoted}&sort=PLa&shortQuery&noDescription&sideInfo=on&where=0&term=#{q_quoted}")))[0..-2].flatten
puts suggestions.map {|s| s_quoted = URI.escape(s); "http://dict.leo.org/ende/index_de.html#/search=#{s_quoted}\tDE-EN for #{s}"}.join("\n")'
'''
[[completion]]
type="numeric_expression"
trigger="([0-9]+.*)"
command="echo 'scale=6;{}' | bc"
Install xsel
first.
[[runner]]
type="numeric_expression"
command="printf '{}' | xsel --clipboard --input"