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
This commit is contained in:
parent
bb6fa28de0
commit
da5e24260a
15
README.md
15
README.md
@ -3,6 +3,7 @@ Do you use `git difftool` to review changes before making a commit? The problem
|
||||
|
||||
# Install
|
||||
|
||||
```bash
|
||||
mkdir -p ~/bin
|
||||
|
||||
# for python version >= 3.10
|
||||
@ -12,6 +13,7 @@ Do you use `git difftool` to review changes before making a commit? The problem
|
||||
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
|
||||
@ -69,6 +71,7 @@ You may need to add `~/bin` to your PATH variable if not already done. See [here
|
||||
|
||||
## Using custom vim command
|
||||
|
||||
Using clean vim without reading `vimrc`
|
||||
```bash
|
||||
git config --global difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "vim --clean" $LOCAL $REMOTE'
|
||||
```
|
||||
@ -82,16 +85,14 @@ Git config file (`~/.gitconfig`) should look like this
|
||||
[difftool "vimtabdiff"]
|
||||
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 vim has a space, it does not work, i.e. Following does **not** work
|
||||
|
||||
```bash
|
||||
git config difftool.vimtabdiff.cmd 'vimtabdiff.py --vim "/home/foo/my program files/bin/vim" $LOCAL $REMOTE'
|
||||
```
|
||||
2. Not tested in non-linux OS. Pull requests welcome if found any issues but hopefully should work fine.
|
||||
*Note:* Not tested in non-linux OS. But I guess it should work fine. Pull requests welcome if found any issues.
|
||||
|
||||
# Similar
|
||||
|
||||
|
@ -9,6 +9,7 @@ import argparse
|
||||
import itertools
|
||||
import tempfile
|
||||
import subprocess
|
||||
import shlex
|
||||
from pathlib import Path
|
||||
from typing import Callable, TypeVar
|
||||
from collections.abc import Iterator, Sequence
|
||||
@ -23,8 +24,8 @@ def star(f: Callable[..., T]) -> Callable[[Sequence], T]:
|
||||
|
||||
def parse_args() -> argparse.Namespace:
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Show diff of files from two directories in vim tabs",
|
||||
epilog="See https://github.com/balki/vimtabdiff for more info")
|
||||
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", type=Path)
|
||||
parser.add_argument("pathB", type=Path)
|
||||
parser.add_argument("--vim", help="vim command to run", default="vim")
|
||||
@ -52,7 +53,7 @@ def get_pairs(aItems: list[Path],
|
||||
for _, items in itertools.groupby(abItems,
|
||||
key=star(lambda item, _: item.name)):
|
||||
match list(items):
|
||||
case [(aItem, _), (bItem, _)]:
|
||||
case [(aItem, _), (bItem, _)]:
|
||||
yield aItem, bItem
|
||||
case [(item, 'A'),]:
|
||||
yield item, None
|
||||
@ -77,14 +78,15 @@ def main() -> None:
|
||||
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} | windo diffthis | windo diffupdate",
|
||||
file=vimCmdFile)
|
||||
cmds = f"""
|
||||
tabdo windo :1
|
||||
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