1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-13 01:20:24 +02:00

simplify history code

This commit is contained in:
Kelly Brazil
2022-04-26 17:46:16 -07:00
parent 8417f2fe4e
commit 621f11e6f9
2 changed files with 7 additions and 10 deletions

View File

@ -87,4 +87,4 @@ Returns:
### Parser Information ### Parser Information
Compatibility: linux, darwin, cygwin, aix, freebsd Compatibility: linux, darwin, cygwin, aix, freebsd
Version 1.6 by Kelly Brazil (kellyjonbrazil@gmail.com) Version 1.7 by Kelly Brazil (kellyjonbrazil@gmail.com)

View File

@ -63,7 +63,7 @@ import jc.utils
class info(): class info():
"""Provides parser metadata (version, author, etc.)""" """Provides parser metadata (version, author, etc.)"""
version = '1.6' version = '1.7'
description = '`history` command parser' description = '`history` command parser'
author = 'Kelly Brazil' author = 'Kelly Brazil'
author_email = 'kellyjonbrazil@gmail.com' author_email = 'kellyjonbrazil@gmail.com'
@ -117,17 +117,14 @@ def parse(data, raw=False, quiet=False):
raw_output = {} raw_output = {}
if jc.utils.has_data(data): if jc.utils.has_data(data):
linedata = data.splitlines()
# split lines and clear out any non-ascii chars
linedata = data.encode('ascii', errors='ignore').decode().splitlines()
# Skip any blank lines
for entry in filter(None, linedata): for entry in filter(None, linedata):
try: try:
parsed_line = entry.split(maxsplit=1) number, command = entry.split(maxsplit=1)
raw_output[parsed_line[0]] = parsed_line[1] raw_output[number] = command
except IndexError: except ValueError:
# need to catch indexerror in case there is weird input from prior commands # need to catch ValueError in case there is weird input from prior commands
pass pass
if raw: if raw: