<commit_before>#!/bin/bash

set -eufo pipefail

usage() {
    cat <<EOS
Usage: $0

Install some terminfo:

- xterm-kitty
- tmux-256color
- tmux-direct
EOS
}

if [[ $# -ne 0 ]]; then
    usage
    exit 1
fi

tmp=$(mktemp)
trap 'rm "$tmp"' EXIT

has() {
    # Clear TERMINFO to avoid a false positive for xterm-kitty when running
    # within kitty (we still want to install it in ~/.terminfo, otherwise it
    # doesn't work when ssh'ing to localhost).
    TERMINFO="" infocmp "$1" &> /dev/null || return 1
}

if ! has xterm-kitty; then
    if [[ -z ${KITTY_PID+x} ]]; then
        cat >&2 <<EOS
Cannot install xterm-kitty because we are not (directly) in kitty.
If this is a remote machine, run this locally to install xterm-kitty here:

    kitty +kitten ssh $(whoami)@$(hostname)
EOS
    else
        infocmp -a xterm-kitty > "$tmp"
        tic -x -o ~/.terminfo "$tmp"
        echo "Installed xterm-kitty"
    fi
fi

tmux_terminfo() {
    has "$1" && return
    case $(uname -s) in
        Darwin) ;;
        *) echo >&2 "I only know how to install $1 on macOS"; return ;;
    esac
    prefix=$(brew --prefix ncurses)
    if ! [[ -d "$prefix" ]]; then
        brew install ncurses
    fi
    "$prefix/bin/infocmp" -A "$prefix/share/terminfo" "$1" > "$tmp"
    tic -o ~/.terminfo "$tmp"
    echo "Installed $1"
}

tmux_terminfo tmux-256color
tmux_terminfo tmux-direct<commit_msg>Just use xterm-kitty and tmux-256color<commit_after>#!/bin/bash

set -eufo pipefail

supported=(
    xterm-kitty
    tmux-256color
)

usage() {
    cat <<EOS
Usage: $0 [NAME]

Install terminfo entries

Arguments:
    NAME  The terminfo to install (if omitted, installs all)

Supported terminfos:
    ${supported[*]}
EOS
}

tmp=$(mktemp)
trap 'rm "$tmp"' EXIT

die() {
    echo >&2 "$0: $*"
    exit 1
}

ensure() {
    if [[ $# -gt 1 ]]; then
        for name; do
            ensure "$name"
        done
        return
    fi

    # Clear TERMINFO to avoid a false positive for xterm-kitty when running
    # within kitty (we still want to install it in ~/.terminfo, otherwise it
    # doesn't work when ssh'ing to localhost).
    if TERMINFO="" infocmp "$1" &> /dev/null; then
        echo "$1 is already installed"
        return
    fi

    case $1 in
        xterm-kitty)
            if [[ -z ${KITTY_PID+x} ]]; then
                cat >&2 <<EOS
Cannot install $1 because we are not (directly) in kitty.
If this is a remote machine, run this locally to install $1 on it:

    kitty +kitten ssh $(whoami)@$(hostname)
EOS
                return
            fi
            infocmp -a "$1" > "$tmp"
            tic -x -o ~/.terminfo "$tmp"
            ;;

        tmux-256color)
            case $(uname -s) in
                Darwin) ;;
                *) echo >&2 "I only know how to install $1 on macOS"; return ;;
            esac
            prefix=$(brew --prefix ncurses)
            if ! [[ -d "$prefix" ]]; then
                brew install ncurses
            fi
            "$prefix/bin/infocmp" -A "$prefix/share/terminfo" "$1" > "$tmp"
            tic -o ~/.terminfo "$tmp"
            ;;

        *) die "$1: unsupported terminfo"
    esac
    echo "Installed $1"
}

case $# in
    0)
        ensure "${supported[@]}"
        ;;
    *)
        case $1 in
            -h|--help|help) usage ;;
            *) ensure "$@" ;;
        esac
        ;;
esac
{'fraction_non_alphanumeric': 0.1329946204423192, 'fraction_numerical': 0.013448894202032277, 'mean_word_length': 1.9308231173380035, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 0, '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': '6496331', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1138, 'n_words': 380}