<commit_before><?php

/*
 * This file is part of Psy Shell
 *
 * (c) 2013 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Psy\Readline;

use Psy\Readline\GNUReadline;

/**
 * A Libedit-based Readline implementation.
 *
 * This is largely the same as the Readline implementation, but it emulates
 * support for `readline_list_history` since PHP decided it was a good idea to
 * ship a fake Readline implementation that is missing history support.
 *
 * Note that this implementation relies on the `unvis` binary to parse the
 * Libedit history file. Without that, PsySH will fall back to LibeditTransient.
 */
class Libedit extends GNUReadline
{
    /**
     * If `unvis` is available, we can emulate GNU Readline by manually reading
     * and parsing the history file. Without it, we're pretty much outta luck.
     *
     * @return boolean
     */
    public static function isSupported()
    {
        return function_exists('readline') && (`which unvis` !== null);
    }

    /**
     * {@inheritDoc}
     */
    public function listHistory()
    {
        $history = array();
        $file = escapeshellarg($this->historyFile);
        exec("unvis $file", $history);

        // shift the history signature, ensure it's valid
        if (array_shift($history) !== '_HiStOrY_V2_') {
            return array();
        }

        return $history;
    }
}<commit_msg>Fix for `which` on systems that do dumb things.<commit_after><?php

/*
 * This file is part of Psy Shell
 *
 * (c) 2013 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Psy\Readline;

use Psy\Readline\GNUReadline;

/**
 * A Libedit-based Readline implementation.
 *
 * This is largely the same as the Readline implementation, but it emulates
 * support for `readline_list_history` since PHP decided it was a good idea to
 * ship a fake Readline implementation that is missing history support.
 *
 * Note that this implementation relies on the `unvis` binary to parse the
 * Libedit history file. Without that, PsySH will fall back to LibeditTransient.
 */
class Libedit extends GNUReadline
{
    /**
     * If `unvis` is available, we can emulate GNU Readline by manually reading
     * and parsing the history file. Without it, we're pretty much outta luck.
     *
     * @return boolean
     */
    public static function isSupported()
    {
        return function_exists('readline') && (`which unvis 2>/dev/null` !== null);
    }

    /**
     * {@inheritDoc}
     */
    public function listHistory()
    {
        $history = array();
        $file = escapeshellarg($this->historyFile);
        exec("unvis $file", $history);

        // shift the history signature, ensure it's valid
        if (array_shift($history) !== '_HiStOrY_V2_') {
            return array();
        }

        return $history;
    }
}
{'fraction_non_alphanumeric': 0.09686038744154976, 'fraction_numerical': 0.003674014696058784, 'mean_word_length': 2.8055908513341805, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '6484534', 'n_tokens_mistral': 847, 'n_tokens_neox': 826, 'n_words': 327}