private function getHistorySlice($show, $head, $tail)
    {
        $history = $this->readline->listHistory();

        // don't show the current `history` invocation
        \array_pop($history);

        if ($show) {
            list($start, $end) = $this->extractRange($show);
            $length = $end - $start;
        } elseif ($head) {
            if (!\preg_match('/^\d+$/', $head)) {
                throw new \InvalidArgumentException('Please specify an integer argument for --head');
            }

            $start  = 0;
            $length = \intval($head);
        } elseif ($tail) {
            if (!\preg_match('/^\d+$/', $tail)) {
                throw new \InvalidArgumentException('Please specify an integer argument for --tail');
            }

            $start  = \count($history) - $tail;
            $length = \intval($tail) + 1;
        } else {
            return $history;
        }

        return \array_slice($history, $start, $length, true);
    }