#!@python@/bin/python import os import sys import shlex from xdg import BaseDirectory from pathlib import Path from configparser import ConfigParser import logging from logging.handlers import SysLogHandler syslog = SysLogHandler logging.basicConfig(handlers = [syslog], level = logging.DEBUG) config = ConfigParser() config_file = BaseDirectory.load_first_config('notmuch-ssh') if config_file is not None: config.read(config_file) original_command = os.environ.get('SSH_ORIGINAL_COMMAND') if original_command is None: sys.exit(os.EX_USAGE) original_command = shlex.split(original_command, comments = True) if len(original_command) < 1: sys.exit(os.EX_USAGE) config_section = original_command[0] command_environment = config[config_section] if config.has_section(config_section) else config[config.default_section] logging.info("notmuch %s # %s", original_command[1:], command_environment) os.execvpe('@notmuch@/bin/notmuch', original_command[1:], command_environment)