Crates.io | sefr |
lib.rs | sefr |
version | 0.3.1 |
source | src |
created_at | 2019-05-15 20:22:28.107427 |
updated_at | 2019-05-30 00:08:49.058794 |
description | Terminal program for interactively opening search engines / parametric URLs. |
homepage | |
repository | https://github.com/efskap/sefr |
max_upload_size | |
id | 134573 |
size | 307,559 |
Terminal program for interactively opening search engines / parametric URLs It's kinda like surfraw but with interactive suggestions (via parsing opensearch json).
I use custom url bar search engines a lot, but browser support for them is frustrating.
e.g. in stock Firefox, while you can create a bookmark keyword so that when you type "r foo" in your url bar, it automatically goes to "reddit.com/r/foo", you can't get completions, and you can't set it as the default search engine.
This is meant to be a customizable crossplatform solution, and since it uses your default browser (more details), you can integrate it into a GUI workflow with a global hotkey (see below).
There are two ways to install sefr
:
cargo run
in the cloned directory to try it out, or cargo build
to create a binary located at target/debug/sefr
.cargo install sefr
. This should make it runnable from anywhere.A convenient way to integrate it into your desktop environment is by mapping a global hotkey to launch it in a lightweight terminal, making for rofi-like UX.
For example, I currently use this in KDE (using the fantastically lightweight suckless terminal), globally bound to Super+s, with a kwin rule that hides window decorations for wmclass=sefr st
:
st -n sefr -g 70x18 -f 'Monospace:size=14' -e ~/src/sefr/target/debug/sefr
For i3, this works well. Not sure why I have to specify $BROWSER
.
for_window [instance="^sefr$"] floating enable, resize set 640 480, move position center
bindsym Mod4+s exec BROWSER=/usr/bin/firefox st -n sefr -f 'Monospace:size=14' -e ~/src/sefr/target/debug/sefr
On its first startup, sefr
will automatically generate a TOML configuration file in the config directory provided by the directories crate. Any subsequent changes should be made inside it.
e.g. For Linux, the config file will be found in ~/.config/sefr/config.toml
.
Warning: The current configuration format might be changed in the future!
New engines can be added for use by sefr
by adding them to the config.toml
file.
A basic engine definition looks like this:
[engines.yt]
name = "YouTube"
search_url = "https://www.youtube.com/results?q=%s"
suggestion_url = "http://suggestqueries.google.com/complete/search?client=firefox&ds=yt&q=%s"
[engines.PREFIX]
defines what prefix (also known as a keyword or trigger) activates the engine.name
is the name of the engine, used for the prompt text if not defined in the prompt section (more on that later).search_url
is opened in your browser with %s
replaced by the search term when enter is pressed.suggestion_url
(optional) is the endpoint queried for suggestions (with %s
replaced by the search term) while typing. It must return OpenSearch suggestions schema json.space_becomes
(optional, +
by default) search_url
is opened.""
, because we now urlencode the search term.
In the default config:
engines.wkt
(Wiktionary) and engines.w
(Wikipedia) _
, because that's how Wikis encode spaces in their URLs.engines.r
(Subreddit) has it set to a blank string, because subreddits can't have spaces in their names (note that this value prevents spaces from being entered into the input buffer when the engine is selected so that space can be used to select a suggestion without performing a search).The engine used when no prefix is entered is defined as _default
in the config, and it is obligatory for the program to start. Example:
[engines._default]
name = "Google"
search_url = "https://www.google.com/search?q=%s"
suggestion_url = "https://www.google.com/complete/search?client=chrome&q=%s"
Along with this, there is also an optional prompt
section which handles the prompt displayed when the engine is called. It will usually look like this:
[engines.yt.prompt]
icon = " ▶ "
icon_bg = "Red"
icon_fg = "White"
text = " Youtube "
text_bg = "White"
text_fg = "Black"
The following fields are supported, and all are optional:
icon
: the icon displayed in the prompticon_bg
: background color of the iconicon_fg
: foreground color of the icontext
: The text displayed after the icon in the prompttext_bg
: background color for the texttext_fg
: foreground color for the textNote that icon
and text
are padded with whitespace for aesthetics in the example configuration, but this is not required.
The fields are all strings except for colors (*_bg
, *_fg
). They can be strings (corresponding to the color names here), 8-bit numbers (corresponding to Ansi color codes), or 8-bit RGB tuples like [255,255,255]
If this section is left out for a particular engine, a basic prompt displaying the engine's name will be used.
Keybindings are a work in progress, but all of the current functions are rebindable under the [keybinds]
section.
Keybinds are in a vim-like syntax (e.g. <Down>
, <C-w>
, <F12>
), but there are a few things to note:
The binding and action are double quoted. So the entire binding is a line like "<Backspace>" = "DeleteChar"
.
All bindings are in p
, as in "p" = "Exit"
).
But why would you make a binding like that?
Ctrl
is represented by C-
(e.g. <C-w>
means 'control + w'). Alt
is represented by either A-
or M-
.
Everything inside <
angle brackets>
is case-insensitive except the normal key after a modifier.
That is, <a-p>
, <A-p>
, <m-p>
, and <M-p>
all mean the same thing ('alt + p') but <m-P>
means 'alt + shift + p'.
So that means there is no "shift" modifier. To register 'alt + shift + s' you'd write <a-S>
or <A-S>
.
'shift + tab' is represented by <Backtab>
.
'enter' can be <CR>
or <Enter>
. 'backspace' can be <BS>
or <Backspace>
.
An empty string represents the NULL
character, whatever that is.
If you assign two functions two the same key, the one registered later will override the first.
Excerpt from the default config:
[keybinds]
"<BackTab>" = "SelectPrev"
"<Backspace>" = "DeleteChar"
"<C-c>" = "Exit"
This project is currently in its alpha stage but is relatively stable.