A tool to search the web with bang commands similar to DuckDuckGo. For example: .d hello
will search for "hello" on DuckDuckGo.
The tool is designed to be used as a custom search engine.
- Open the settings.
- Go to "Search engine".
- Click on "Manage search engines".
- Click on "Add".
- Enter a name (e.g. "Web Command").
- Enter a keyword (e.g. "w").
- Enter the url (e.g.
http://localhost:8012/%s
). - Click on "Add".
- Click on the three dots next to the new entry.
- Click on "Make default".
Firefox does not support custom search engines by default. You can use the Add custom search engine extension to add a custom search engine.
The commands are defined in a TOML file:
prefix = "."
[[sites]]
name = "duckduckgo"
key = "d"
url = "https://duckduckgo.com/?q={{s}}"
[[sites]]
name = "duden"
key = "du"
alias = ["duden"]
url = "http://www.duden.de/suchen/dudenonline/{{s}}"
The prefix is the character that precedes every command.
The first entry is the default. If no command is specified, the default command will be used.
Optionally a command can have an array of aliases. On load the aliases will be expanded to their own key. This is useful if you want to have multiple keys for the same site.
A full example can be found here.
If you update the configuration file, you can reload it by sending a GET request to http://wsh.example.com:$WEBCOMMAND_PORT/r/
.
The tool is a single executable. It is configured via environment variables.
Variable | Default | Description |
---|---|---|
WEBCOMMAND_PORT |
8012 |
The port the application is listening on. |
WEBCOMMAND_HOST_MODE |
false |
If the application runs in host mode or mirror mode. |
WEBCOMMAND_CONFIG |
./sites.toml |
If the application runs in mirror mode (the default), this variable needs to contain an url, that points to a wsh instance running in host mode. If the application runs in host mode, this variable is interpreted as a path to a toml configuration file. If you don't want to maintain your own configuration file, you can use https://wsh.draculente.eu/ as the url. This is the configuration file of my instance. If you want to add a site, you can create a pull request here. |
To speed up the service it is recommended to run it as a daemon in mirror-mode on your local machine (this is the default mode).
In this case, the service will try to fetch the configuration file from a remote location, so that you can have a single configuration file for all your machines.
If you have a remote machine you can run the service on it and set the host mode variable. In this case it will use a local configuration file and expose it via http://wsh.example.com:$WEBCOMMAND_PORT/u/
.
- Set the environment variables with
export WEBCOMMAND_CONFIG="URL/Path"
etc... - run the programm with
nix run github:draculente/web-command
- import the git repo into your flake.
inputs = {
wsh = {
url = "github:draculente/web-command";
inputs.nixpkgs.follows = "nixpkgs";
};
};
- import the module
wsh.nixosModules.<your system>.default
your system is for examplex86_64-linux
- Configure it as you like
example 1:
configFile can also be a Path to your config file :)
services.wsh = {
enable = true;
host_mode = "local";
configFile = pkgs.writeText "wsh-config.toml" ''
prefix = "."
[[sites]]
name = "duden"
key = "d"
url = "http://www.duden.de/suchen/dudenonline/{{s}}"
[[sites]]
name = "startpage"
key = "s"
alias = [ "startpage" ]
url = "https://www.startpage.com/sp/search?query={{s}}"
[[sites]]
name = "nixpkgs"
key = "nix"
url = "https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query={{s}}"
[[sites]]
name = "wikipedia"
key = "w"
alias = [ "wiki" ]
url = "https://de.wikipedia.org/wiki/Special:Search?search={{s}}"
'';
};
example 2:
services.wsh = {
enable = true;
host_mode = "mirror";
mirror.url = "https://wsh.draculente.eu";
}
The easiest way to run the service is to use docker-compose. You can find an example docker-compose file here.
We set the restart policy to unless-stopped
so that the service will be restarted on boot.
- Create a new directory.
- Download the docker-compose file into that directory.
- Create a
.env
file in that directory and set the environment variables as described inconfiguration
. - IF YOU RUN IT AS HOST: Create a
sites.toml
file in that directory and set the sites as described inconfiguration
. - Run
docker compose up -d
.
Of course you can also run the service directly with docker (docker run ...
).
After some benchmarking I found that running the service via docker-compose increases latency by about 68% compared to directly running it on the host (from 789µs to 1.2ms on my machine).
The recommended way to run the service is to use systemd. You can find an example systemd service file here.
- Create a new directory.
- Download the appropriate binary from the releases page into that directory.
- Create a
.env
file in that directory and set the environment variables as described inconfiguration
. - IF YOU RUN IT AS HOST: Create a
sites.toml
file in that directory and set the sites as described inconfiguration
. - Copy the systemd service file into
/etc/systemd/user/wsh.service
. - Adjust the service file to your needs.
- Run
systemctl --user daemon-reload
. - Run
systemctl --user enable wsh.service
. - Run
systemctl --user start wsh.service
.
If you want to, you could also run the service in a docker container but use systemd to manage it (even though I don't see any reason to do so). For further information see here.
git clone https://github.com/Draculente/web-command.git
cd web-command
cargo build --release
When you want to create a new release, follow these steps:
- Update the version in the project's Cargo.toml file (e.g. 1.2.3)
- Commit that change (
git commit -am v1.2.3
) - Tag the commit (
git tag v1.2.3
). Make sure your tag name's format isv*.*.*
The workflow will use this tag to detect when to create a release - Push the changes to GitHub (
git push && git push --tags
) - Edit and publish the release draft created by the workflow in GitHub
After building successfully, the action will publish the release artifacts in a new release draft that will be created on GitHub with download links for the app.