darrenburns / dunk Goto Github PK
View Code? Open in Web Editor NEWPrettier git diffs in the terminal ๐จ
Prettier git diffs in the terminal ๐จ
git diff
would show if a file was added or deleted to a repo. would be great if dunk
had the same functionality i think. thanks!
While we SHOULD be using black to limit the length of our lines, it doesn't mean we do in every project :)
Here is a minimum example the causes the crash:
cd /tmp
mkdir dunk-submodule-fail
cd dunk-submodule-fail
git init
mkdir this-is-submodule
cd this-is-submodule
git init
echo "test" > myfile.txt && git add --all && git commit -m "initial-sub"
cd ..
# git submodule add ./this-is-submodule # not actually needed.
git add --all && git commit -m "initial-parent"
# have an uncommitted changed file in the submodule
echo "breaking change" > this-is-submodule/myfile.txt
git diff | dunk
traceback
Traceback (most recent call last):
File "/home/user/.local/bin/dunk", line 8, in <module>
sys.exit(main())
File "/home/user/.local/pipx/venvs/dunk/lib/python3.10/site-packages/dunk/dunk.py", line 119, in main
target_code = target_file.read_text()
File "/usr/lib/python3.10/pathlib.py", line 1134, in read_text
with self.open(mode='r', encoding=encoding, errors=errors) as f:
File "/usr/lib/python3.10/pathlib.py", line 1119, in open
return self._accessor.open(self, mode, buffering, encoding, errors,
IsADirectoryError: [Errno 21] Is a directory: '/tmp/dunk-submodule-fail/this-is-submodule'
You can look at Choose a License and choose one you find appropriate.
To reproduce: get a very long diff, pipe the output of dunk to less or another pager, and quit without reading the entire thing.
python -c "print('line\n' * 1000)" > tmp
git add tmp
git diff HEAD | dunk | less -R # Exit pager without scrolling
# ...
# BrokenPipeError: [Errno 32] Broken pipe
The desired behavior would be to either 1) completely ignore broken pipe errors or 2) catch broken pipe errors and print a one-liner to stderr. I would much prefer the first one.
Thank you so much for the project btw ๐
When I try to view diff for a bare repo, it throws FileNotFoundError
.
To reproduce:
โฏ cd
โฏ git init --bare my_bare_repo
Initialized empty Git repository in /home/***/my_bare_repo/
โฏ alias bare="/usr/bin/git --git-dir=$HOME/my_bare_repo --work-tree=$HOME"
โฏ bare config --local status.showUntrackedFiles no
โฏ mkdir -p ~/.config/test_dir
โฏ touch ~/.config/test_dir/test_file
โฏ bare add ~/.config/test_dir/test_file
โฏ echo hello > ~/.config/test_dir/test_file
โฏ bare diff | dunk
1 file added
+1 โโโโโโโโโโโโโโโโโโโโโโโโโโโ -0
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Added .config/test_dir/test_file (1 additions, 0 removals) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒ @@ -0,0 +1,1 @@ โฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒโฒ
1 1 hello
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
/// dunk 0.4.0a0
โฏ cd .config
โฏ bare diff | dunk
1 file added
+1 โโโโโโโโโโโโโโโโโโโโโโโโโโโ -0
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Added .config/test_dir/test_file (1 additions, 0 removals) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Traceback (most recent call last):
File "/home/***/.local/bin//dunk", line 8, in <module>
sys.exit(main())
File "/home/***/.local/pipx/venvs/dunk/lib/python3.10/site-packages/dunk/dunk.py", line 119, in main
target_code = target_file.read_text()
File "/usr/lib/python3.10/pathlib.py", line 1132, in read_text
with self.open(mode='r', encoding=encoding, errors=errors) as f:
File "/usr/lib/python3.10/pathlib.py", line 1117, in open
return self._accessor.open(self, mode, buffering, encoding, errors,
FileNotFoundError: [Errno 2] No such file or directory: '/home/***/.config/.config/test_dir/test_file'
Not sure if it's within the scope of this program but it would be nice to support git show as well.
This tool looks amazing ๐คฉ
Any chance of a slight refactor so that I can import it into my tool and use it to render diffs that I already have as strings? At the moment it looks like the stdin is hard-coded..
$ pipx install dunk
installed package dunk 0.4.0a0, installed using Python 3.10.4
These apps are now globally available
- dunk
done! โจ ๐ โจ
$ git clone [email protected]:darrenburns/dunk.git
Cloning into 'dunk'...
remote: Enumerating objects: 129, done.
remote: Counting objects: 100% (129/129), done.
remote: Compressing objects: 100% (84/84), done.
remote: Total 129 (delta 52), reused 98 (delta 34), pack-reused 0
Receiving objects: 100% (129/129), 46.59 KiB | 11.65 MiB/s, done.
Resolving deltas: 100% (52/52), done.
$ cd dunk
$ git show 53acb8e | dunk
...lots of normal dunk content...
Traceback (most recent call last):
File "/Users/danielh/.local/pipx/venvs/dunk/lib/python3.9/site-packages/rich/syntax.py", line 458, in tokens_to_spans
_token_type, token = next(tokens)
StopIteration
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/danielh/.local/bin/dunk", line 8, in <module>
sys.exit(main())
File "/Users/danielh/.local/pipx/venvs/dunk/lib/python3.9/site-packages/dunk/dunk.py", line 352, in main
source_syntax_lines: List[List[Segment]] = console.render_lines(
File "/Users/danielh/.local/pipx/venvs/dunk/lib/python3.9/site-packages/rich/console.py", line 1334, in render_lines
lines = list(
File "/Users/danielh/.local/pipx/venvs/dunk/lib/python3.9/site-packages/rich/segment.py", line 291, in split_and_crop_lines
for segment in segments:
File "/Users/danielh/.local/pipx/venvs/dunk/lib/python3.9/site-packages/rich/console.py", line 1299, in render
for render_output in iter_render:
File "/Users/danielh/.local/pipx/venvs/dunk/lib/python3.9/site-packages/rich/syntax.py", line 554, in __rich_console__
text = self.highlight(code, self.line_range)
File "/Users/danielh/.local/pipx/venvs/dunk/lib/python3.9/site-packages/rich/syntax.py", line 470, in highlight
text.append_tokens(tokens_to_spans())
File "/Users/danielh/.local/pipx/venvs/dunk/lib/python3.9/site-packages/rich/text.py", line 969, in append_tokens
for content, style in tokens:
RuntimeError: generator raised StopIteration
Tested on macOS 12.3.1 with python 3.9.12 and ubuntu 22.04 with python 3.10.4, both installed via pipx.
I would suggest to use
git config --global alias.dunk '!git_dunk() { git diff $* | dunk; }; git_dunk'
instead of the alias in the README as this allows git dunk
to be used in the same way as git diff
, i.e. it enables git dunk abcde
or git dunk abcde 12345
I'm using iTerm2, and pretty much every color scheme I have available makes it challenging to see the removed lines. Even the screenshot that is currently in the README is quite challenging to see removed lines in.
I think that having preset color schemes that are available via args would be a good way to handle this. EG: git diff | dunk --colors=protanopic
or something.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.