sefr (Search Engine FRontend)

Crates.io Crates.io

Terminal program for interactively opening search engines / parametric URLs.
It's kinda like surfraw but with interactive suggestions (via parsing opensearch json).

Motivation

I use custom url bar search engines a lot, but browser support for them is frustrating.

e.g. in stock Firefox, you can't create a search engine that, when you type "r foo" in your url bar, automatically goes to "reddit.com/r/foo". You have to manually write the URL, and you don't even get completions!

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).

Installation

There are two ways to install sefr: 1. Clone this repository, install the Rust toolchain, and either call cargo run in the cloned directory to try it out, or cargo build to create a binary located at target/debug/sefr. 2. Install via cargo by calling 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. For example, bind this to a convenient hotkey in your DE or WM and change the last argument to point at the binary.

sh uxterm -geometry 60x20+620+200 -fa 'Monospace' -fs 13 -bg grey27 -fg white -e ~/sefr/target/debug/sefr

For i3 + suckless terminal, this works well. Not sure why I have to specify $BROWSER.

sh 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 ~/sefr/target/debug/sefr

Configuration / Customization

Config file

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.

Adding new engines

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:

toml [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"

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:

toml [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:

toml [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 prompt - icon_bg: background color of the icon - icon_fg: foreground color of the icon - text: The text displayed after the icon in the prompt - text_bg: background color for the text - text_fg: foreground color for the text

Note 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

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:

Excerpt from the default config:

toml [keybinds] "<BackTab>" = "SelectPrev" "<Backspace>" = "DeleteChar" "<C-c>" = "Exit"

Progress

This project is currently in its alpha stage but is relatively stable.