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 sys
import traceback
try:
import winshell
except ImportError:
winshell = None
from voussoirkit import clipext
from voussoirkit import expressionmatch
@ -59,6 +63,29 @@ def search_contents_generic(filepath, content_args):
yield from results
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(
*,
yes_all=None,
@ -147,6 +174,9 @@ def search(
if not filepath.is_file:
continue
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):