Support searching of windows .lnk file fields.

I'm currently migrating my shortcuts that point to Py 3.7 to 3.8
so this saves a lot of time!
This commit is contained in:
voussoir 2020-01-25 00:39:18 -08:00
parent 08782fdaf9
commit 9d8c9fdf51

View file

@ -6,6 +6,10 @@ import re
import stat import stat
import sys import sys
import traceback import traceback
try:
import winshell
except ImportError:
winshell = None
from voussoirkit import clipext from voussoirkit import clipext
from voussoirkit import expressionmatch from voussoirkit import expressionmatch
@ -59,6 +63,29 @@ def search_contents_generic(filepath, content_args):
yield from results yield from results
yield '' yield ''
def search_contents_windows_lnk(filepath, content_args):
try:
shortcut = winshell.Shortcut(filepath.absolute_path)
except Exception:
return
text = [
f'Target: {shortcut.path}',
f'Start In: {shortcut.working_directory}',
f'Comment: {shortcut.description}',
]
text = '\n'.join(text)
content_args['text'] = text
results = search(**content_args)
results = list(results)
if not results:
return
yield filepath.absolute_path
yield from results
yield ''
def search( def search(
*, *,
yes_all=None, yes_all=None,
@ -147,7 +174,10 @@ def search(
if not filepath.is_file: if not filepath.is_file:
continue continue
yield from search_contents_generic(filepath, content_args) if filepath.extension.lower() == 'lnk' and winshell:
yield from search_contents_windows_lnk(filepath, content_args)
else:
yield from search_contents_generic(filepath, content_args)
def argparse_to_dict(args): def argparse_to_dict(args):
text = args.text text = args.text