-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Work with arbitrary files #220
Comments
What doesn't work when you do When I try that on some local files it looks 90% correct. The only part that is not correct is the header line, and that's because we expect some git specific ANSI codes that aren't there. I still see the separator line, it's just not colored. Can you provide a |
In this screenshot note issues with:
Also note that with newer versions of |
I've been using |
I would definitely like to be able to handle:
@paulirish can you elaborate on your |
@scottchiefbaker I assume he's talking about doing |
Yup! What he said. :)
|
Oh that's cool. I had now idea you could use git to diff files that aren't in a repo. Since we're able to use git like this, making d-s-f to work with it shouldn't be too hard. How would we want it to look? Option 1
These seem logical to me, but we would have to add some logic to d-s-f to detect that this code snippet is NOT from a repo, and handle the rename header issue that @OJFord mentioned. Maybe add some sort of Option 2
This seems slightly less intuitive, but would be a lot easier to implement. We just modify d-s-f to pass the two files it sees to |
If I may, Option 3 diff-so-fancy file1 file2 If stdin is a file descriptor, normal git behaviour, else do this. Or not even check stdin - just look for args that aren't I think I like option 1 most though, it keeps dsf as the thing which does the fancifying - it's more UNIXey. |
In re detecting if a git diff - easiest way would be to |
The problem I see with option 1 is that it requires some git. D-s-f relies on git to colorize the diffed lines (d-s-f reads that and massages them), which is why We could work around that by just reading the output, scraping the file names and calling |
Iirc, |
I've updated the workaround (see top post) to create a
My preference now goes to option 3. It would be easy to detect if there were not exactly 2 non-option arguments and print a usage summary.
I would also love to be able to: |
make |
"diff-so-fancy" (1) has been designed to work within Git controlled directories. To allow to use it to compare files that are not controlled by Git the "--no-index" (2) option of "git-diff" has been used. The script pipes the output to "less" using the options * "-R, --RAW-CONTROL-CHARS" to only display ANSI "color" escape sequences in "raw" form * "-F, --quit-if-one-screen" to automatically exit if the entire file can be displayed on the first screen. * "-X, --no-init" to disable sending the termcap (de)initialization strings to the terminal to avoid unnecessary operations like clearing the screen. * "-x2, --tabs=2" to use two tab stops. References: * so-fancy/diff-so-fancy#220 (comment) (1) https://github.com/so-fancy/diff-so-fancy (2) https://git-scm.com/docs/git-diff#git-diff-emgitdiffem--no-index--options--ltpathgt823082
"diff-so-fancy" (1) has been designed to work within Git controlled directories. To allow to use it to compare files that are not controlled by Git the "--no-index" (2) option of "git-diff" has been used. The script pipes the output to "less" using the options * "-R, --RAW-CONTROL-CHARS" to only display ANSI "color" escape sequences in "raw" form * "-F, --quit-if-one-screen" to automatically exit if the entire file can be displayed on the first screen. * "-X, --no-init" to disable sending the termcap (de)initialization strings to the terminal to avoid unnecessary operations like clearing the screen. * "-x2, --tabs=2" to use two tab stops. References: * so-fancy/diff-so-fancy#220 (comment) (1) https://github.com/so-fancy/diff-so-fancy (2) https://git-scm.com/docs/git-diff#git-diff-emgitdiffem--no-index--options--ltpathgt823082 GH-61
I'm back looking at this... what types of formats do we want to support? |
What more would be needed apart from diff / patch? |
The problem I've run in to with this is that Git handles the line add/remove coloring. If we remove Git from the equation because we're processing standard diff/patch files d-s-f will have to do that line coloring itself. That's also doable, if d-s-f knows it's in standalone file mode. Detecting that may be complicated. I propose we do the following
That might break people's expectations if they expect something like this to work:
If we're just reading from STDIN it's really hard for d-s-f to know if the difference between Git output, and a regular patch file. Ideally the third diff syntax above, but we'll have to get creative about detecting if we're in standalone mode. |
I did some more thinking, and wrote up an initial implementation on
If you check out the |
Anyone had a chance to test this yet? |
I haven't, no. I was also excited for |
@paulirish doing |
Less consistent with what? GNU diff and git diff both operate like that. |
Consistent in that d-s-f is called the same way for all the different methods:
It's always reading piped in data via STDIN, whether it's from git, diff, or even cat. It certainly simplifies the logic in the code, and I think it's easier to remember. "For git I do git diff | d-s-f, but this is a raw patch file so do I do d-s-f < raw.patch" etc... No need to stop and think about what mode you're in. Everything is via a pipe. |
Works for me. Once we document it we should make a release :) |
not 100% sure, but I guess its the same use-case. I want
|
@staabm I just tested and it works for me. Are you using the |
I am using the latest stable version. |
@staabm this is a new unreleased feature. If you'd like to help us test you'll need to use the |
In addition to the things tweaked in the PR above, one thing that would be nice to change is that currently the filename line
gets turned into
instead of
....but I didn't attempt to fix that because I'm not sure what sorts of corner cases are going to come up in the process. |
This issue has been partially addressed in the just released v.1.2.5. In order to keep things clean I'm closing this issue. If we need to let's create a new issue for further improvements to this mechanism. |
The output format is indeed preeedy... so pretty I want to use it with standard
diff
.Would you consider supporting
diff -u file1 file2 | diff-so-fancy
?or
diff-so-fancy --files file1 file2
There is a workaround but it requires different commands if under
git
management or not.It would be great to have one command that works no matter what the
git
status of the files is.The text was updated successfully, but these errors were encountered: