diff kitten: add options to ignore paths when comparing directories

Tested locally & over SSH:

    $ kitty +kitten diff /local/path /local/path2
    $ kitty +kitten diff /local/path ssh:remote:/path
This commit is contained in:
Suvayu Ali
2022-06-05 00:02:13 +02:00
parent a42200a430
commit fbf1ec43c7
6 changed files with 37 additions and 2 deletions

8
kittens/diff/collect.py Normal file → Executable file
View File

@@ -4,6 +4,7 @@
import os
import re
from contextlib import suppress
from fnmatch import fnmatch
from functools import lru_cache
from hashlib import md5
from kitty.guess_mime_type import guess_type
@@ -37,6 +38,9 @@ class Segment:
class Collection:
file_ignores = ['']
ignore_paths = ['']
def __init__(self) -> None:
self.changes: Dict[str, str] = {}
self.renames: Dict[str, str] = {}
@@ -113,7 +117,11 @@ def collect_files(collection: Collection, left: str, right: str) -> None:
def walk(base: str, names: Set[str], pmap: Dict[str, str]) -> None:
for dirpath, dirnames, filenames in os.walk(base):
if any(fnmatch(dirpath, f"*/{pat}") for pat in collection.ignore_paths):
continue
for filename in filenames:
if any(fnmatch(filename, f"{pat}") for pat in collection.file_ignores):
continue
path = os.path.abspath(os.path.join(dirpath, filename))
path_name_map[path] = name = os.path.relpath(path, base)
names.add(name)