Skip to content
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

Util: check parent process for filename #770

Merged
merged 1 commit into from
Nov 15, 2021
Merged

Conversation

th1000s
Copy link
Contributor

@th1000s th1000s commented Nov 10, 2021

Usecase: With delta used as a pager the command git blame main.rs calls
delta, but the piped data does not mention the filename. Instead try to
get the filename extension from the parent git process.

@th1000s th1000s mentioned this pull request Nov 10, 2021
@th1000s
Copy link
Contributor Author

th1000s commented Nov 10, 2021

Nice, this even works on windows, thanks to sysinfo:

windows-latest, x86_64-pc-windows-msvc:
    test utils::tests::test_process_parent_cmd_args ... ok

@dandavison
Copy link
Owner

Excellent! (There seem to be some test failures on one of the linux builds)

src/utils.rs Outdated
}

None
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is a crate dedicated to parsing arbitrary command lines known only at run time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is more a command line ignorer than parser it is a rather simple function, see skip_uninteresting_args.

Usecase: With delta used as a pager the command `git blame main.rs` calls
delta, but the piped data does not mention the filename. Instead try to
get the filename extension from the parent `git` process.

If that fails try the direct sibling or all other `git blame` processes.
@th1000s
Copy link
Contributor Author

th1000s commented Nov 15, 2021

Updated to also work in other cases, such as piped input (git blame src/main.rs | delta), but this is not guaranteed to work if the git process is too fast or the data too small.

The tests failed on ARM because there they are not executed on hardware but in emulation, so I try to detect that.

Also, utils.rs..., any other ideas? :)

@dandavison
Copy link
Owner

dandavison commented Nov 15, 2021

Also, utils.rs..., any other ideas? :)

How about process_utils.rs? (We already have bat_utils/ and syntect_utils/; it might be nice to reorganize as utils/* at some point.) EDIT I'm doing that in #775

I'm using the API provided in this PR in #774 to interrogate git grep arguments; very useful!

@dandavison dandavison merged commit 929345f into dandavison:master Nov 15, 2021
@dandavison
Copy link
Owner

Merged -- it looks like the only test complaints were clippy complaining that things were not called, as indeed they will not be until we use this in #761, and the coverage test for which I'll try adding tarpaulin as an expected argument along with test.

Thanks very much for this -- it is already quite sophisticated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants