Strip url

This commit is contained in:
Daniel Ponte 2024-02-08 10:28:53 -05:00
parent c53b64203d
commit d68391cfc1
1 changed files with 13 additions and 7 deletions

View File

@ -57,11 +57,13 @@ def set_data(entry, data, exclude, get_fields, get_lines):
matching_lines = {}
for i, line in enumerate(filtered_tail):
for name, pattern in get_lines:
for name, pattern, subc in get_lines:
match = pattern.search(line)
if not match:
continue
matches = matching_lines.setdefault(name, [])
if subc is not None:
line = subc.sub('', line)
matches.append(line)
matching_indices.add(i)
break
@ -284,14 +286,14 @@ def parse_args(args=None):
parser.add_argument(
'-l', '--get-line',
metavar=('name', 'pattern'),
metavar=('name', 'pattern', 'replace'),
action='append',
nargs=2,
nargs=3,
type=str,
default=[['otp', 'otpauth://'], ['url', 'https?://']],
default=[['otp', 'otpauth://', ''], ['url', 'https?://', '^url: *']],
help=(
"a name and a regexp for which all lines that match are included"
" in a field with the chosen name"
" in a field with the chosen name. replace is a regex to remove matches of from entry."
),
dest='get_lines'
)
@ -386,11 +388,15 @@ def cli():
get_fields.append((name, regexp))
get_lines = []
for name, pattern in parsed.get_lines:
for name, pattern, subs in parsed.get_lines:
regexp = compile_regexp(pattern)
if not regexp:
failed = True
get_lines.append((name, regexp))
if subs == '':
subc = None
else:
subc = compile_regexp(subs)
get_lines.append((name, regexp, subc))
username_patterns = []
for pattern in parsed.usernames: