s Command-Line Utility

repository·master·Indexed 25 days ago

https://github.com/zquestz/s

A command-line utility for performing web searches from the terminal. It supports multiple search providers, tagging systems, custom provider configuration via UCL files, and a web-based interface server mode. Features include shell autocompletion for Bash, Zsh, Fish, and PowerShell, as well as machine-readable JSON output for provider and tag lists.

Tokens
1.9K
Snippets
8
Records
16
Agent score
83%

What's inside s

  1. Use s for web searches

    master

    The s command allows you to perform web searches directly from your terminal. By default, it opens the results in your default browser.

    Basic Usage

    s <query>

    Specifying a Provider Use the -p or --provider flag to search a specific site (e.g., google, amazon, wikipedia).

    s -p google dragonflies

    Searching by Tag Use the -t or --tag flag to search providers associated with a specific category (e.g., video, shopping).

    s -t video muppets

    Partial Matching s supports partial matching for both providers and tags.

    s -p fa hamsters  # Searches Facebook
    s -t te ssd       # Searches 'tech-news' tagged providers
    s puppies
    s -p google dragonflies
    s -t video muppets
  2. Set up autocompletion for s

    master

    You can enable autocompletion for providers and tags in your shell using the --completion flag.

    Bash (Linux)

    sudo bash -c "s --completion bash > /etc/bash_completion.d/s"

    Bash (macOS)

    sudo bash -c "s --completion bash > /usr/local/etc/bash_completion.d/s"

    Zsh Generate a _s script and place it in your $fpath:

    sudo zsh -c "s --completion zsh > /usr/local/share/zsh/site-functions/_s"

    Fish

    s --completion fish > ~/.config/fish/completions/s.fish

    PowerShell

    (& s --completion powershell) | Out-String | Invoke-Expression
    s --completion fish > ~/.config/fish/completions/s.fish
  3. Advanced usage: Custom binaries and aliases

    master

    You can extend how s behaves using flags and shell features.

    Use a specific binary instead of the default browser Use the -b or --binary flag. If the path contains spaces, use quotes carefully.

    s -b w3m cats
    s -b "chromium --incognito" conspiracy theories
    s -b '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' kittens

    Create shell aliases for frequent providers Add these to your .profile or shell config:

    alias sa="s -p amazon"
    alias sw="s -p wikipedia"

    Search specific subreddits

    s -p reddit /r/cscareerquestions best startups.
    s -b w3m cats
  4. Install s

    master

    You can install s using Go, Homebrew, or the Arch User Repository (AUR).

    Using Go Ensure GOPATH and GOBIN environment variables are set, then run:

    go install github.com/zquestz/s@latest

    Using Homebrew (macOS/Linux)

    brew install s-search

    Using AUR (Arch Linux)

    yay -S s
    go install github.com/zquestz/s@latest
  5. Configure s via config file

    master

    You can customize s behavior by creating a configuration file at ~/.config/s/config. The file uses the UCL format and must include a trailing newline to parse correctly.

    Supported Configuration Keys

    • blacklist: array of providers to exclude
    • binary: binary to launch search URI
    • cert: path to cert.pem for TLS
    • customProviders: array of custom provider objects
    • json: boolean to enable JSON output for list commands
    • key: path to key.pem for TLS
    • output: boolean for output only mode
    • port: server port (default 8080)
    • provider: default search provider
    • tag: default search tag
    • verbose: boolean for verbose mode
    • whitelist: array of providers to include

    Examples

    Set default provider:

    provider: duckduckgo

    Whitelist specific providers:

    whitelist: [google, amazon, wikipedia]

    Add a custom provider:

    customProviders [
      {
        name: example
        url: "https://example.com?q=%s"
        tags: [example]
      }
    ]

    Note: Custom provider names must be alphanumeric (^[a-zA-Z0-9_]*$) and the URL must contain a %s token for the query.

    provider: duckduckgo
  6. Configure the `s` CLI via configuration file

    master

    The s CLI loads its configuration from a file located at ~/.config/s/config. If that file does not exist, it attempts to fall back to a legacy path at ~/.s/config. The configuration file must be in UCL format.

    To apply settings, ensure your UCL file contains keys that match the supported configuration schema.

  7. Use the `s` CLI for web searches

    master

    The s command allows you to perform web searches directly from your terminal. You can provide a search query as arguments or pipe input from stdin. If no query is provided, the help screen is displayed.

    Basic Usage:

    s "your search query"

    Using Stdin: You can pipe text into the command to search for it:

    echo "golang tutorials" | s
  8. Launch s in Server Mode

    master

    The -s or --server flag launches a web interface.

    Start default server (port 8080)

    s -s

    Start server with TLS and custom port

    s -s -c /path/to/cert.pem -k /path/to/key.pem --port 8443
    s -s
  9. Get machine-readable JSON output

    master

    Use the -j or --json flag with list commands to get machine-readable output for scripting.

    List providers as JSON

    s -l -j

    List tags as JSON

    s --list-tags -j

    Include extra metadata Adding the -v (verbose) flag includes tags for each provider, or providers for each tag.

    s -l -v -j
    s --list-tags -v -j

    To make JSON the default for all list commands, add json: true to your ~/.config/s/config file.

    s -l -j
  10. Launch the `s` web server

    master

    The s tool can be run in server mode using the --server (or -s) flag. This launches a web server on a specified port. You can also configure TLS by providing paths to a certificate and a key.

    Basic Server Launch:

    s --server

    Server with custom port and TLS:

    s --server --port 9000 --cert ./cert.pem --key ./key.pem
  11. List supported providers and tags

    master

    You can inspect the available search providers and tags supported by the tool. Use the --json flag to get the output in JSON format, which is useful for programmatic consumption.

    List Providers:

    s --list-providers

    List Tags:

    s --list-tags

    List Providers in JSON:

    s --list-providers --json