Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
e26e40413f | |||
5e2943624a | |||
32e186695a |
37
README.md
37
README.md
@ -1,3 +1,27 @@
|
||||
Do you use `git difftool` to review changes before making a commit? The problem with that is that you get to see the diff of one file at a time. You can't easily stop it after few files and you can't go back to a previous file. `vimtabdiff.py` loads all the files with diffs, one in each vim tab page. You can move around any file and edit the diffs easily.
|
||||
|
||||
|
||||
# Install
|
||||
|
||||
```bash
|
||||
mkdir -p ~/bin
|
||||
|
||||
# for python version >= 3.10
|
||||
curl -o ~/bin/vimtabdiff.py "https://raw.githubusercontent.com/balki/vimtabdiff/master/vimtabdiff.py"
|
||||
|
||||
# for python version < 3.10
|
||||
curl -o ~/bin/vimtabdiff.py "https://raw.githubusercontent.com/balki/vimtabdiff/br-py38/vimtabdiff.py"
|
||||
|
||||
chmod +x ~/bin/vimtabdiff.py
|
||||
```
|
||||
|
||||
You may need to add `~/bin` to your PATH variable if not already done. See [here](https://wiki.archlinux.org/title/Environment_variables#Per_user) for help.
|
||||
👍 this [issue](https://github.com/balki/vimtabdiff/issues/1) for `pip install` support
|
||||
|
||||
|
||||
# Screenshot
|
||||
![image](https://user-images.githubusercontent.com/189196/206880555-c71b472c-144c-4c82-a4ab-f8a4fd36f7a5.png)
|
||||
|
||||
# Usage
|
||||
```help
|
||||
usage: vimtabdiff.py [-h] [--vim VIM] pathA pathB
|
||||
@ -34,6 +58,7 @@
|
||||
|
||||
## Using custom vim command
|
||||
|
||||
Using clean vim without reading `vimrc`
|
||||
```bash
|
||||
git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "vim --clean" $LOCAL $REMOTE'
|
||||
```
|
||||
@ -47,16 +72,14 @@ Git config file (`~/.gitconfig`) should look like this
|
||||
[difftool "vimtabdiff"]
|
||||
cmd = vimtabdiff.py --vim \"vim --clean\" $LOCAL $REMOTE
|
||||
```
|
||||
|
||||
|
||||
# Known issues
|
||||
|
||||
1. If your path to custom vim has space, it does not work. i.e. Following does *not* work
|
||||
Using better diff algorithm
|
||||
|
||||
```bash
|
||||
git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "/home/foo/my files/bin/vim" $LOCAL $REMOTE'
|
||||
git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "vim +\"set diffopt+=algorithm:patience\"" $LOCAL $REMOTE'
|
||||
|
||||
```
|
||||
2. Not tested in non-linux OS. Pull requests welcome if found any issues.
|
||||
|
||||
*Note:* Not tested in non-linux OS. But I guess it should work fine. Pull requests welcome if found any issues.
|
||||
|
||||
# Similar
|
||||
|
||||
|
@ -6,7 +6,7 @@ import pathlib
|
||||
import itertools
|
||||
import tempfile
|
||||
import subprocess
|
||||
|
||||
import shlex
|
||||
|
||||
def star(f):
|
||||
""" see https://stackoverflow.com/q/21892989 """
|
||||
@ -15,7 +15,8 @@ def star(f):
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Show diff of files from two directories in vim tabs")
|
||||
description="Show diff of files from two directories in vim tabs",
|
||||
epilog="See https://github.com/balki/vimtabdiff for more info")
|
||||
parser.add_argument("pathA")
|
||||
parser.add_argument("pathB")
|
||||
parser.add_argument("--vim", help="vim command to run", default="vim")
|
||||
@ -67,18 +68,27 @@ def main():
|
||||
args = parse_args()
|
||||
vimCmdFile = tempfile.NamedTemporaryFile(mode='w', delete=False)
|
||||
with vimCmdFile:
|
||||
cmds = f"""
|
||||
let s:spr = &splitright
|
||||
set splitright
|
||||
"""
|
||||
print(cmds, file=vimCmdFile)
|
||||
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
|
||||
print(
|
||||
f"tabedit {aPath} | diffthis | vsp {bPath} | diffthis | diffupdate",
|
||||
f"tabedit {aPath} | vsp {bPath}",
|
||||
file=vimCmdFile)
|
||||
cmds = f"""
|
||||
let &splitright = s:spr
|
||||
tabdo windo :1
|
||||
tabdo windo diffthis
|
||||
tabdo windo diffupdate
|
||||
tabfirst | tabclose
|
||||
call delete("{vimCmdFile.name}")
|
||||
"""
|
||||
print(cmds, file=vimCmdFile)
|
||||
subprocess.run(args.vim.split() + ["-S", vimCmdFile.name])
|
||||
subprocess.run(shlex.split(args.vim) + ["-S", vimCmdFile.name])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user