Use shlex to split custom vim command
This allows to include spaces in vim command
Add example to change default diff algorithm
Move to first line on each file
Backport from da5e24260
This commit is contained in:
parent
32e186695a
commit
5e2943624a
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/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
|
# Usage
|
||||||
```help
|
```help
|
||||||
usage: vimtabdiff.py [-h] [--vim VIM] pathA pathB
|
usage: vimtabdiff.py [-h] [--vim VIM] pathA pathB
|
||||||
@ -34,6 +58,7 @@
|
|||||||
|
|
||||||
## Using custom vim command
|
## Using custom vim command
|
||||||
|
|
||||||
|
Using clean vim without reading `vimrc`
|
||||||
```bash
|
```bash
|
||||||
git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "vim --clean" $LOCAL $REMOTE'
|
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"]
|
[difftool "vimtabdiff"]
|
||||||
cmd = vimtabdiff.py --vim \"vim --clean\" $LOCAL $REMOTE
|
cmd = vimtabdiff.py --vim \"vim --clean\" $LOCAL $REMOTE
|
||||||
```
|
```
|
||||||
|
Using better diff algorithm
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "vim +\"set diffopt+=algorithm:patience\"" $LOCAL $REMOTE'
|
||||||
|
|
||||||
# Known issues
|
```
|
||||||
|
|
||||||
1. If your path to custom vim has space, it does not work. i.e. Following does *not* work
|
*Note:* Not tested in non-linux OS. But I guess it should work fine. Pull requests welcome if found any issues.
|
||||||
|
|
||||||
```bash
|
|
||||||
git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "/home/foo/my files/bin/vim" $LOCAL $REMOTE'
|
|
||||||
```
|
|
||||||
2. Not tested in non-linux OS. Pull requests welcome if found any issues.
|
|
||||||
|
|
||||||
# Similar
|
# Similar
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import pathlib
|
|||||||
import itertools
|
import itertools
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import shlex
|
||||||
|
|
||||||
def star(f):
|
def star(f):
|
||||||
""" see https://stackoverflow.com/q/21892989 """
|
""" see https://stackoverflow.com/q/21892989 """
|
||||||
@ -15,7 +15,8 @@ def star(f):
|
|||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser(
|
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("pathA")
|
||||||
parser.add_argument("pathB")
|
parser.add_argument("pathB")
|
||||||
parser.add_argument("--vim", help="vim command to run", default="vim")
|
parser.add_argument("--vim", help="vim command to run", default="vim")
|
||||||
@ -76,7 +77,7 @@ def main():
|
|||||||
aPath = a.resolve() if a else os.devnull
|
aPath = a.resolve() if a else os.devnull
|
||||||
bPath = b.resolve() if b else os.devnull
|
bPath = b.resolve() if b else os.devnull
|
||||||
print(
|
print(
|
||||||
f"tabedit {aPath} | diffthis | vsp {bPath} | diffthis | diffupdate",
|
f"tabedit {aPath} | vsp {bPath}",
|
||||||
file=vimCmdFile)
|
file=vimCmdFile)
|
||||||
cmds = f"""
|
cmds = f"""
|
||||||
let &splitright = s:spr
|
let &splitright = s:spr
|
||||||
@ -87,7 +88,7 @@ def main():
|
|||||||
call delete("{vimCmdFile.name}")
|
call delete("{vimCmdFile.name}")
|
||||||
"""
|
"""
|
||||||
print(cmds, file=vimCmdFile)
|
print(cmds, file=vimCmdFile)
|
||||||
subprocess.run(args.vim.split() + ["-S", vimCmdFile.name])
|
subprocess.run(shlex.split(args.vim) + ["-S", vimCmdFile.name])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user