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

    function configureSW -V dir
        source "$dir/../bash/profile.fish";
        source "$dir/../fish/profile.fish";
        set -l functionName _PortValhalla_ls_

        function dump_header
            echo "# logo-ls"
        end

        function dump_aliases -V functionName
            printf %s\n \
                "alias ls='$functionName'" \
                "alias ll='ls -al'" \
                "alias l='ls'"
        end

        begin
            dump_header

            printf %s\n \
                "function $functionName() {" \
                "    if [ -t 1 ]" \
                "    then" \
                '        logo-ls -D "$@";' \
                "    else" \
                '        ls --color=auto "$@"' \
                "    fi;" \
                "}" \
                ""

            dump_aliases
        end | installBashProfile "logo-ls"

        if type -q fish
            begin
                dump_header

                printf %s\n \
                    "function $functionName" \
                    "    if [ -t 1 ]" \
                    '        logo-ls -D $argv' \
                    "    else" \
                    '        command ls --color=auto $argv' \
                    "    end" \
                    "end" \
                    ""

                dump_aliases
            end | installFishProfile "logo-ls"
        end
    end

    runInstaller $argv
end