From 31ea5d74a76ca3ce5b3b1a9aa8be5d33fa3ede5c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 6 Mar 2022 10:00:02 +0530 Subject: [PATCH] Exclude junk directories when adding user files as well --- kittens/ssh/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kittens/ssh/main.py b/kittens/ssh/main.py index 9fc8aeacc..796862cef 100644 --- a/kittens/ssh/main.py +++ b/kittens/ssh/main.py @@ -71,6 +71,10 @@ def make_tarfile(ssh_opts: SSHOptions, base_env: Dict[str, str]) -> bytes: def filter_from_globs(*pats: str) -> Callable[[tarfile.TarInfo], Optional[tarfile.TarInfo]]: def filter(tarinfo: tarfile.TarInfo) -> Optional[tarfile.TarInfo]: + for junk_dir in ('.DS_Store', '__pycache__'): + for pat in (f'*/{junk_dir}', '*/{junk_dir}/*'): + if fnmatch.fnmatch(tarinfo.name, pat): + return None for pat in pats: if fnmatch.fnmatch(tarinfo.name, pat): return None @@ -110,7 +114,6 @@ def make_tarfile(ssh_opts: SSHOptions, base_env: Dict[str, str]) -> bytes: tf.add(shell_integration_dir, arcname=arcname, filter=filter_from_globs( f'{arcname}/ssh/bootstrap.*', # bootstrap files are sent as command line args f'{arcname}/zsh/kitty.zsh', # present for legacy compat not needed by ssh kitten - '*/.DS_Store', )) tf.add(terminfo_dir, arcname='home/.terminfo', filter=normalize_tarinfo) return buf.getvalue()