add support for Nemo file manager

This commit is contained in:
Daniel Langbein 2021-12-18 21:41:45 +01:00
parent abf2e31f83
commit 5cb1d82a7a

View File

@ -52,6 +52,7 @@ def main():
NAUTILUS_SELECTION = 'NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'
NEMO_SELECTION = 'NEMO_SCRIPT_SELECTED_FILE_PATHS'
SCRIPT_NAME = 'relative-xopp-background'
@ -64,14 +65,10 @@ def parse_args() -> List[Path]:
# get list of selected paths
selected_paths: List[Path] = []
selected_files_str = getenv(NAUTILUS_SELECTION)
if selected_files_str:
selected_files = selected_files_str.split('\n')
# if last filename is empty, remove it
if len(selected_files[-1]) < 1:
selected_files = selected_files[:-1]
selected_paths = [Path(file) for file in selected_files]
else:
selected_paths += selection_from_env(NAUTILUS_SELECTION)
selected_paths += selection_from_env(NEMO_SELECTION)
# if no selected files from NAUTILUS or NEMO were added
if len(selected_paths) == 0:
selected_paths = [Path(file) for file in argv[1:]]
# for each selected path
@ -91,7 +88,22 @@ def parse_args() -> List[Path]:
if path.suffix == '.xopp':
xopp_files.append(path.absolute())
return xopp_files
# don't return duplicates
return list(set(xopp_files))
def selection_from_env(key: str) -> List[Path]:
"""
Splits the value of environment key "key" by newlines and returns each element as Path object.
"""
newline_delimited_selection = getenv(key)
if newline_delimited_selection:
selected_files = newline_delimited_selection.split('\n')
# if last filename is empty, remove it
if len(selected_files[-1]) < 1:
selected_files = selected_files[:-1]
return [Path(file) for file in selected_files]
return []
def usage():