<commit_before>set -g fisher_version 3.0.3

type source >/dev/null; or function source; . $argv; end

if command which perl >/dev/null
    function _fisher_now -a elapsed
        command perl -MTime::HiRes -e 'printf("%.0f\n", (Time::HiRes::time() * 1000) - $ARGV[0])' $elapsed
    end
else
    function _fisher_now -a elapsed
        command date "+%s%3N" | command awk "{ sub(/3N\$/,\"000\"); print \$0 - 0$elapsed }"
    end
end

function fisher -a cmd -d "fish package manager"
    if not command which curl >/dev/null
        echo "curl is required to use fisher -- install curl and try again" >&2
        return 1
    end

    test -z "$XDG_CACHE_HOME"; and set XDG_CACHE_HOME ~/.cache
    test -z "$XDG_CONFIG_HOME"; and set XDG_CONFIG_HOME ~/.config

    set -g fish_config $XDG_CONFIG_HOME/fish
    set -g fisher_cache $XDG_CACHE_HOME/fisher
    set -g fisher_config $XDG_CONFIG_HOME/fisher

    test -z "$fisher_path"; and set -g fisher_path $fish_config

    command mkdir -p {$fish_config,$fisher_path}/{functions,completions,conf.d} $fisher_cache

    if test ! -e "$fisher_path/completions/fisher.fish"
        echo "fisher self-complete" > $fisher_path/completions/fisher.fish
        _fisher_self_complete
    end

    switch "$cmd"
        case self-complete
            _fisher_self_complete
        case ls
            _fisher_ls | command sed "s|$HOME|~|"
        case -v {,--}version
            _fisher_version (status -f)
        case -h {,--}help
            _fisher_help
        case self-update
            _fisher_self_update (status -f); or return
            _fisher_self_complete
        case self-uninstall
            _fisher_self_uninstall
        case add rm ""
            if test ! -z "$argv"
                if not isatty
                    while read -l i
                        set argv $argv $i
                    end
                end
            end
            _fisher_commit $argv; or return
            _fisher_self_complete
        case \*
            echo "error: unknown flag or command \"$cmd\"" >&2
            _fisher_help >&2
            return 1
    end
end

function _fisher_self_complete
    complete -c fisher --erase
    complete -xc fisher -n __fish_use_subcommand -a version -d "Show version"
    complete -xc fisher -n __fish_use_subcommand -a help -d "Show help"
    complete -xc fisher -n __fish_use_subcommand -a self-update -d "Update fisher"
    complete -xc fisher -n __fish_use_subcommand -a ls -d "List installed packages"
    complete -xc fisher -n __fish_use_subcommand -a rm -d "Remove packages"
    complete -xc fisher -n __fish_use_subcommand -a add -d "Add packages"
    for pkg in (_fisher_ls)
        complete -xc fisher -n "__fish_seen_subcommand_from rm" -a $pkg
    end
end

function _fisher_ls
    set -l pkgs $fisher_config/*/*/*
    for pkg in $pkgs
        command readlink $pkg; and continue; or echo $pkg
    end | command sed "s|$fisher_config/||;s|github\.com/||"
end

function _fisher_version -a file
    echo "fisher version $fisher_version $file" | command sed "s|$HOME|~|"
end

function _fisher_help
    echo "usage: fisher add <PACKAGES>    add packages"
    echo "       fisher rm  <PACKAGES>    remove packages"
    echo "       fisher ls                list installed packages"
    echo "       fisher self-update       update fisher"
    echo "       fisher self-uninstall    uninstall fisher & all packages"
    echo "       fisher help              show this help"
    echo "       fisher version           show version"
    echo
    echo "examples:"
    echo "       fisher add jethrokuan/z rafaelrinaldi/pure"
    echo "       fisher add gitlab.com/owner/foobar@v2"
    echo "       fisher add ~/myfish/mypkg"
    echo "       fisher rm rafaelrinaldi/pure"
    echo "       fisher ls | fisher rm"
end

function _fisher_self_update -a file
    set -l url "https://raw.githubusercontent.com/jorgebucaran/fisher/master/fisher.fish"
    echo "fetching $url" >&2

    curl -s "$url?nocache" >$file@

    set -l next_version (awk 'NR == 1 { print $4; exit }' < $file@)
    switch "$next_version"
        case "" $fisher_version
            command rm -f $file@
            if test -z "$next_version"
                echo "cannot update fisher -- are you offline?" >&2
                return 1
            end
            echo "fisher is already up-to-date" >&2
        case \*
            echo "linking $file" | command sed "s|$HOME|~|" >&2
            command mv -f $file@ $file
            source $file
            echo "updated fisher to $fisher_version -- hooray!" >&2
    end
end

function _fisher_self_uninstall
    set -l current_pkgs $fisher_config/*/*/*
    set -l removed_pkgs (_fisher_pkg_remove_all $current_pkgs)
    printf "removing %s\n" $removed_pkgs $fisher_config $fisher_cache $fisher_path/{functions,completions}/fisher.fish $fish_config/fishfile | command sed "s|$HOME|~|"

    command rm -rf $fisher_config $fisher_cache 2>/dev/null
    command rm $fisher_path/{functions,completions}/fisher.fish $fish_config/fishfile 2>/dev/null

    set -e fisher_cache
    set -e fisher_config
    set -e fisher_path
    set -e fisher_version

    complete -c fisher --erase
    functions -e (functions -a | command awk '/^_fisher/') fisher
end

function _fisher_commit
    set -l elapsed (_fisher_now)
    set -l current_pkgs $fisher_config/*/*/*
    set -l removed_pkgs (_fisher_pkg_remove_all $current_pkgs)
    command rm -rf $fisher_config
    command mkdir -p $fisher_config

    set -l fishfile $fish_config/fishfile
    if test ! -e "$fishfile"
        command touch $fishfile
        echo "created empty fishfile in $fishfile" | command sed "s|$HOME|~|" >&2
    end
    _fisher_fishfile_indent (echo -s $argv\;) < $fishfile > $fishfile@
    command mv -f $fishfile@ $fishfile
    command rm -f $fishfile@

    set -l added_pkgs (_fisher_pkg_fetch_all (_fisher_fishfile_load < $fishfile))
    set -l updated_pkgs (
        for pkg in $removed_pkgs
            set pkg (echo $pkg | command sed "s|$fisher_config/||")
            if contains -- $pkg $added_pkgs
                echo $pkg<commit_msg>refactor: dry self-uninstall; add farewell message<commit_after>set -g fisher_version 3.0.3

type source >/dev/null; or function source; . $argv; end

if command which perl >/dev/null
    function _fisher_now -a elapsed
        command perl -MTime::HiRes -e 'printf("%.0f\n", (Time::HiRes::time() * 1000) - $ARGV[0])' $elapsed
    end
else
    function _fisher_now -a elapsed
        command date "+%s%3N" | command awk "{ sub(/3N\$/,\"000\"); print \$0 - 0$elapsed }"
    end
end

function fisher -a cmd -d "fish package manager"
    if not command which curl >/dev/null
        echo "curl is required to use fisher -- install curl and try again" >&2
        return 1
    end

    test -z "$XDG_CACHE_HOME"; and set XDG_CACHE_HOME ~/.cache
    test -z "$XDG_CONFIG_HOME"; and set XDG_CONFIG_HOME ~/.config

    set -g fish_config $XDG_CONFIG_HOME/fish
    set -g fisher_cache $XDG_CACHE_HOME/fisher
    set -g fisher_config $XDG_CONFIG_HOME/fisher

    test -z "$fisher_path"; and set -g fisher_path $fish_config

    command mkdir -p {$fish_config,$fisher_path}/{functions,completions,conf.d} $fisher_cache

    if test ! -e "$fisher_path/completions/fisher.fish"
        echo "fisher self-complete" > $fisher_path/completions/fisher.fish
        _fisher_self_complete
    end

    switch "$cmd"
        case self-complete
            _fisher_self_complete
        case ls
            _fisher_ls | command sed "s|$HOME|~|"
        case -v {,--}version
            _fisher_version (status -f)
        case -h {,--}help
            _fisher_help
        case self-update
            _fisher_self_update (status -f); or return
            _fisher_self_complete
        case self-uninstall
            _fisher_self_uninstall
        case add rm ""
            if test ! -z "$argv"
                if not isatty
                    while read -l i
                        set argv $argv $i
                    end
                end
            end
            _fisher_commit $argv; or return
            _fisher_self_complete
        case \*
            echo "error: unknown flag or command \"$cmd\"" >&2
            _fisher_help >&2
            return 1
    end
end

function _fisher_self_complete
    complete -c fisher --erase
    complete -xc fisher -n __fish_use_subcommand -a version -d "Show version"
    complete -xc fisher -n __fish_use_subcommand -a help -d "Show help"
    complete -xc fisher -n __fish_use_subcommand -a self-update -d "Update fisher"
    complete -xc fisher -n __fish_use_subcommand -a ls -d "List installed packages"
    complete -xc fisher -n __fish_use_subcommand -a rm -d "Remove packages"
    complete -xc fisher -n __fish_use_subcommand -a add -d "Add packages"
    for pkg in (_fisher_ls)
        complete -xc fisher -n "__fish_seen_subcommand_from rm" -a $pkg
    end
end

function _fisher_ls
    set -l pkgs $fisher_config/*/*/*
    for pkg in $pkgs
        command readlink $pkg; and continue; or echo $pkg
    end | command sed "s|$fisher_config/||;s|github\.com/||"
end

function _fisher_version -a file
    echo "fisher version $fisher_version $file" | command sed "s|$HOME|~|"
end

function _fisher_help
    echo "usage: fisher add <PACKAGES>    add packages"
    echo "       fisher rm  <PACKAGES>    remove packages"
    echo "       fisher ls                list installed packages"
    echo "       fisher self-update       update fisher"
    echo "       fisher self-uninstall    uninstall fisher & all packages"
    echo "       fisher help              show this help"
    echo "       fisher version           show version"
    echo
    echo "examples:"
    echo "       fisher add jethrokuan/z rafaelrinaldi/pure"
    echo "       fisher add gitlab.com/owner/foobar@v2"
    echo "       fisher add ~/myfish/mypkg"
    echo "       fisher rm rafaelrinaldi/pure"
    echo "       fisher ls | fisher rm"
end

function _fisher_self_update -a file
    set -l url "https://raw.githubusercontent.com/jorgebucaran/fisher/master/fisher.fish"
    echo "fetching $url" >&2

    curl -s "$url?nocache" >$file@

    set -l next_version (awk 'NR == 1 { print $4; exit }' < $file@)
    switch "$next_version"
        case "" $fisher_version
            command rm -f $file@
            if test -z "$next_version"
                echo "cannot update fisher -- are you offline?" >&2
                return 1
            end
            echo "fisher is already up-to-date" >&2
        case \*
            echo "linking $file" | command sed "s|$HOME|~|" >&2
            command mv -f $file@ $file
            source $file
            echo "updated fisher to $fisher_version -- hooray!" >&2
    end
end

function _fisher_self_uninstall
    set -l current_pkgs $fisher_config/*/*/*
    for path in $fisher_cache (_fisher_pkg_remove_all $current_pkgs) $fisher_config $fisher_path/{functions,completions}/fisher.fish $fish_config/fishfile
        echo "removing $path"
        command rm -rf $path 2>/dev/null
    end | command sed "s|$HOME|~|" >&2

    set -e fisher_cache
    set -e fisher_config
    set -e fisher_path
    set -e fisher_version

    complete -c fisher --erase
    functions -e (functions -a | command awk '/^_fisher/') fisher

    echo "done -- see you again!" >&2
end

function _fisher_commit
    set -l elapsed (_fisher_now)
    set -l current_pkgs $fisher_config/*/*/*
    set -l removed_pkgs (_fisher_pkg_remove_all $current_pkgs)
    command rm -rf $fisher_config
    command mkdir -p $fisher_config

    set -l fishfile $fish_config/fishfile
    if test ! -e "$fishfile"
        command touch $fishfile
        echo "created empty fishfile in $fishfile" | command sed "s|$HOME|~|" >&2
    end
    _fisher_fishfile_indent (echo -s $argv\;) < $fishfile > $fishfile@
    command mv -f $fishfile@ $fishfile
    command rm -f $fishfile@

    set -l added_pkgs (_fisher_pkg_fetch_all (_fisher_fishfile_load < $fishfile))
    set -l updated_pkgs (
        for pkg in $removed_pkgs
            set pkg (echo $pkg | command sed "s|$fisher_config/||")
            if contains -- $pkg $added_pkgs
                echo $pkg
{'fraction_non_alphanumeric': 0.09690399934302374, 'fraction_numerical': 0.005502176233883551, 'mean_word_length': 2.214040643969385, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 42, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '558365', 'n_tokens_mistral': 4030, 'n_tokens_neox': 3885, 'n_words': 1225}