#!/bin/env fish
begin
    set -l dir (status dirname)
    source "$dir/../../Scripts/software.fish"

    function installSW
        configureSW
    end

    function configureSW -V dir
        source "$dir/../bash/profile.fish"
        source "$dir/../fish/profile.fish"
        set -l file /etc/aliae/aliae.yml
        echo "export ALIAE_CONFIG=$(string escape "$file")" | sudo tee /etc/profile.d/aliae.sh > /dev/null
        sudo install -Dm644 "$dir/aliae.yml" "$file"

        begin
            printf %s\n \
                "# aliae" \
                'eval "$(aliae init bash)"' \
                'eval "$(aliae completion bash)"'
        end | installBashProfile "aliae" "aliae"

        begin
            printf %s\n "" \
                "# aliae" \
                'eval "$(aliae init bash)"' \
                'eval "$(aliae completion bash)"'
        end | sudo tee /etc/skel/.bashrc > /dev/null

        if type -q fish
            begin
                printf %s\n \
                    "aliae init fish | source" \
                    "aliae completion fish | source"
            end | installFishProfile "aliae" "aliae"
        end
    end

    runInstaller $argv
end