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

Second attempt at #1566 #1570

Merged
merged 3 commits into from
Jan 28, 2023
Merged

Second attempt at #1566 #1570

merged 3 commits into from
Jan 28, 2023

Conversation

KlzXS
Copy link
Collaborator

@KlzXS KlzXS commented Jan 25, 2023

get_output() no longer uses UTIL_SH_EXEC since that presented the usual shell expansion problems. Now it directly invoked the command.
Tried it out with the examples of failing commands in #1566 and those seem fine now.

BTW sorry for the terrible commit message. Didn't realize it wouldn't allow me to merge all the commits again. Besides a bunch of "Revert 'Revert ...'" is not that pretty.

src/nnn.c Show resolved Hide resolved
src/nnn.c Show resolved Hide resolved
@jarun
Copy link
Owner

jarun commented Jan 27, 2023

I see the following problem with this:

I have an entry in NNN_PLUG as: c:!|cp -rv "$nnn" "$nnn".cp*

I have a file: IEEE. SpectrumCollections.1.HandsOn.072221.pdf

When I press Alt-c on the above file I get the following error:

cp: cannot stat '"$nnn"': No such file or directory

I have also modified run_cmd_as_plugin() as:

static void run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags)
{
        size_t len; 

        xstrsncpy(g_buf, file, PATH_MAX);

        len = xstrlen(g_buf);
        if (len > 1 && g_buf[len - 1] == '*') {
                flags &= ~F_CONFIRM; /* Skip user confirmation */
                g_buf[len - 1] = '\0'; /* Get rid of trailing no confirmation symbol */
                --len;
        }

        if (flags & F_PAGE) {
                get_output(g_buf, NULL, NULL, -1, TRUE);                                                              
#if 0
        if ((flags & F_PAGE) || (flags & F_NOTRACE)) {
                if (is_suffix(g_buf, " $nnn"))
                        g_buf[len - 5] = '\0';
                else
                        runfile = NULL;

                if (flags & F_PAGE)
                        get_output(g_buf, runfile, NULL, -1, TRUE);
                else // F_NOTRACE
                        spawn(g_buf, runfile, NULL, NULL, flags);
#endif
        } else 
                spawn(utils[UTIL_SH_EXEC], g_buf, NULL, NULL, flags);
}

@KlzXS
Copy link
Collaborator Author

KlzXS commented Jan 27, 2023

You used |, it's going the F_PAGE path, but you didn't set it to use UTIL_SH_EXEC. The env variable is not getting expanded.

@jarun
Copy link
Owner

jarun commented Jan 27, 2023

I don't get it. You mentioned:

No longer uses UTIL_SH_EXEC since that presented the usual shell expansion problems.

Can you share the steps you meant? My UTIL_SH_EXEC is sh.

@jarun
Copy link
Owner

jarun commented Jan 27, 2023

In this case I wanted to page the output as well as complete the copy operation.

@jarun
Copy link
Owner

jarun commented Jan 27, 2023

OK. I changed:

get_output(g_buf, NULL, NULL, -1, TRUE);

to

get_output(utils[UTIL_SH_EXEC], g_buf, NULL, -1, TRUE);

and it worked. Is this what you meant?

@jarun
Copy link
Owner

jarun commented Jan 27, 2023

Let me use this for some more time and if there are no issues, I'll merge.

@KlzXS
Copy link
Collaborator Author

KlzXS commented Jan 27, 2023

Is this what you meant?

That's exactly it. I updated the main comment to better reflect what the change compared to the previous PR is.

@jarun jarun merged commit 1a5a7da into jarun:master Jan 28, 2023
@jarun
Copy link
Owner

jarun commented Jan 28, 2023

Thank you!

@jarun
Copy link
Owner

jarun commented Jan 28, 2023

Thanks @KlzXS! This is a great improvement.
Not only $nnn, run commands as plugin now supports all exported variables. Something I wanted for very long...

@github-actions github-actions bot locked and limited conversation to collaborators Feb 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants