def search(self, tok):
        """
        Search the history.
        :param tok:
        :type tok:
        :return: last entry in history matching the search
        :rtype: str
        """
        history = self.getlist()
        search_string = tok[1:]
        if search_string == '':
            return ''
        if search_string == '!':
            return history[0]
        try:
            idx = int(search_string)
            try:
                return history[::-1][idx]
            except IndexError:
                raise ShEventNotFound(tok)
        except ValueError:
            for entry in history:
                if entry.startswith(search_string):
                    return entry
            raise ShEventNotFound(tok)

        Search the history.
        :param tok:
        :type tok:
        :return: last entry in history matching the search
        :rtype: str
        
system/shhistory.py