#!/usr/bin/env fish

set engines \
    "d DuckDuckGo https://duckduckgo.com/?q=" \
    "m Marginalia https://marginalia-search.com/search?query=" \
    "w Wikipedia https://wikipedia.org/w/index.php?search=" \
    "wa WolframAlpha https://www.wolframalpha.com/input?i="

set bindings (string split --field 1 ' ' $engines)
set names (string split --fields 2 ' ' $engines)
set urls (string split --fields 3 ' ' $engines)

function search
    set input (string join -- ' ' (prompt --prompt="$names[$argv[1]] " --mesg=(string join ', ' $bindings) || exit))
    echo $input[1]
    if contains $input $bindings
        search (contains -i $input $bindings)
        exit
    end

    xdg-open "$urls[$argv[1]]$input"
end

search 1
