buster / rrun

minimalistic command launcher in rust
GNU General Public License v2.0
112 stars 14 forks source link

Simple and modular caching #23

Closed nightscape closed 8 years ago

nightscape commented 8 years ago

There are completions that take too long to be run live every time. A simple form of caching would be nice here. I have an idea that would fit nicely with the current Unix-like "small combinable tools" philosophy: We add a command line option to rrun that doesn't show the GUI but instead runs a completion and prints the returned result string directly to STDOUT. One could then add something like this to the config:

[[completion]]
type="cache-request"
trigger="cache (.*)"
command="rrun list-completions {}"

[[runner]]
type="cache-request"
command="rrun complete {} > ~/.config/rrun/command_{}.cache"

and use the cache by just adding

[[completion]]
type="command"
command="cat ~/.config/rrun/command_*.cache | grep {}"

With some duplication in the config, you could do the same thing for URLs or whatever.

Note 1: You can already do this manually by running the code from the completion yourself and storing it into a file. The above proposal would just make it a lot more convenient. Note 2: If we additionally write which command was called how often somewhere, one could also easily implement a script that sorts the contents of the .cache files by their usage and get the most frequently used completions first.

nightscape commented 8 years ago

Closed by https://github.com/buster/rrun/pull/26