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

Have NNN_PREVIEWIMGPROG accept a generic command for preview-tui #1930

Merged
merged 4 commits into from
Sep 15, 2024

Conversation

danielb2
Copy link
Contributor

@danielb2 danielb2 commented Sep 13, 2024

Make NNN_PREVIEWIMGPROG flexible enough to accept any program, including necessary flags.

make NNN_PREVIEWIMGPROG flexible enough to accept any program. programs like `timg` would also work (my preference), but it seems odd to add every single program out there when it's easy to add new ones by just this one variable
@@ -460,6 +460,8 @@ image_preview() {
chafa "$3" &
elif exists img2sixel && [[ "$NNN_PREVIEWIMGPROG" == +(|img2sixel) ]]; then
img2sixel -g "$3" &
elif exists "$NNN_PREVIEWIMGPROG"; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems odd to add every single program out there

Some of the provided options require a bunch of flags, which this script provides for the user. But yes, adding a more generic else clause would be good. In that case I would change the exists check to check the first word in the variable like so:

Suggested change
elif exists "$NNN_PREVIEWIMGPROG"; then
elif exists "${NNN_PREVIEWIMGPROG%% *}"; then

That way the user can add any necessary flags to the command as well. Feel free to also remove the current else clauses that do not contain any flags and would be covered by this generic one.

Copy link
Contributor Author

@danielb2 danielb2 Sep 15, 2024

Choose a reason for hiding this comment

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

I modified exists instead since it will never check more than one file exists() { type "${1%% *}" >/dev/null 2>&1 ;}

Copy link
Collaborator

@luukvbaal luukvbaal Sep 15, 2024

Choose a reason for hiding this comment

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

Not sure I prefer that, it obfuscates what we are doing. Would be better to properly document NNN_PREVIEWIMGPROG in that it can be a full command including flags, rather than just a program path. And then keep the variable expansion at the callsite like I suggested. I have pushed a commit that does that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It still can. I'm just moving the logic over to exists to check the first part of the argument since exists may be used in other places and it's cleaner this way because then the argument doesn't need to be changed everytime before passing

@luukvbaal luukvbaal changed the title Update preview-tui Have NNN_PREVIEWIMGPROG accept a generic command for preview-tui Sep 15, 2024
@jarun jarun merged commit 07a972a into jarun:master Sep 15, 2024
7 checks passed
@jarun
Copy link
Owner

jarun commented Sep 15, 2024

Thank you!

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.

3 participants