-
-
Notifications
You must be signed in to change notification settings - Fork 762
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
Conversation
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
plugins/preview-tui
Outdated
@@ -460,6 +460,8 @@ image_preview() { | |||
chafa "$3" & | |||
elif exists img2sixel && [[ "$NNN_PREVIEWIMGPROG" == +(|img2sixel) ]]; then | |||
img2sixel -g "$3" & | |||
elif exists "$NNN_PREVIEWIMGPROG"; then |
There was a problem hiding this comment.
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:
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.
There was a problem hiding this comment.
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 ;}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Thank you! |
Make NNN_PREVIEWIMGPROG flexible enough to accept any program, including necessary flags.