Merge pull request #6 from ilyagr/diffonly

Option to skip creating tabs for identical files. Useful outside git.
This commit is contained in:
Balki 2023-03-01 05:04:30 +00:00 committed by GitHub
commit e81277ecb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 8 deletions

View File

@ -24,17 +24,18 @@ 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
Show diff of files from two directories in vim tabs
positional arguments:
pathA
pathB
positional arguments:
pathA
pathB
options:
-h, --help show this help message and exit
--vim VIM vim command to run
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

View File

@ -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