From 4188c510817171b46d8535d258dd0b279cf8d761 Mon Sep 17 00:00:00 2001 From: Ilya Grigoriev Date: Tue, 28 Feb 2023 17:58:54 -0800 Subject: [PATCH] Option to skip creating tabs for identical files --- README.md | 3 ++- vimtabdiff.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 620c0e7..13fbabd 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ You may need to add `~/bin` to your PATH variable if not already done. See [here # Usage ```help -usage: vimtabdiff.py [-h] [--vim VIM] pathA pathB +usage: vimtabdiff.py [-h] [--vim VIM] [--onlydiffs] pathA pathB Show diff of files from two directories in vim tabs @@ -35,6 +35,7 @@ positional arguments: options: -h, --help show this help message and exit --vim VIM vim command to run + --onlydiffs only open files where there is a diff ``` ## Relevant vim tips diff --git a/vimtabdiff.py b/vimtabdiff.py index d84705b..0db3849 100755 --- a/vimtabdiff.py +++ b/vimtabdiff.py @@ -29,6 +29,9 @@ def parse_args() -> argparse.Namespace: parser.add_argument("pathA", type=Path) parser.add_argument("pathB", type=Path) parser.add_argument("--vim", help="vim command to run", default="vim") + parser.add_argument( + "--onlydiffs", help="only open files where there is a diff", action="store_true" + ) return parser.parse_args() @@ -78,6 +81,12 @@ def main() -> None: for a, b in get_file_pairs(args.pathA, args.pathB): aPath = a.resolve() if a else os.devnull bPath = b.resolve() if b else os.devnull + if ( + args.onlydiffs + and a and b + and open(aPath, mode="rb").read() == open(bPath, mode="rb").read() + ): + continue print(f"tabedit {aPath} | vsp {bPath}", file=vimCmdFile) cmds = f""" tabdo windo :1