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

    function setFlags
        argparse -i "user=" -- $argv
        set -l user "$_flag_user"
        set -l flags
        set -l bins codium code

        if [ -n "$user" ]
            set homeDir ~"$user"
            set flags -u "$user"
        else
            set homeDir /etc/skel
        end

        for bin in $bins
            if type -q "$bin"
                begin
                    set -l file "$homeDir/.config/$bin-flags.conf"
                    sudo $flags mkdir -p (dirname "$file")
                    echo --touch-events | sudo $flags tee "$file" >/dev/null
                end
            end
        end
    end

    function installSW
        yayinst \
            vscodium-bin \
            visual-studio-code-bin (
                # Trash functionality
            ) gvfs
    end

    function configureSW -V dir
        setFlags
    end

    function userConfig -V dir
        setFlags $argv
        fish "$dir/../../../Common/Software/vscode/main.fish" userConfig $argv
    end

    runInstaller $argv
end