function kitten --description 'Run kitten and restore Kitty theme overrides'
    command kitten $argv
    set -l kitten_status $status

    if test $kitten_status -eq 0
        and test (count $argv) -gt 0
        and test "$argv[1]" = themes
        set -l config_dir "$HOME/.config/kitty"
        if set -q KITTY_CONFIG_DIRECTORY
            set config_dir "$KITTY_CONFIG_DIRECTORY"
        end

        "$HOME/.config/kitty/repair-auto-themes.sh" "$config_dir"
        or return $status

        if set -q KITTY_WINDOW_ID
            command kitty @ load-config
            or return $status
        end
    end

    return $kitten_status
end
