doronbehar / pistol

General purpose file previewer designed for Ranger, Lf to make scope.sh redundant

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Piping is not working

nacro90 opened this issue · comments

Hi,
Piping in preview commands does not work. Is it the behaviour it should have?

This is working:

column -s, -t < %s

But this is not (Outputs nothing):

column -s, -t < %s | head

And this is working:

rar lb %s

This is not (Outputs nothing):

rar lb %s | sort

Pistol version: 0.0.2.r15.gbd918ca-1
I am using lf and also tried previewing with pistol executable in shell.

Thanks :)

Well this behavior is not a bug but certainly we can improve it - The reason this is not working is because pistol doesn't run the commands you specify inside a shell, hence this (untested), should be working:

sh -c 'rar lb %s | sort'

BTW I'm using golang's "os/exec" which, (quoting):

Unlike the "system" library call from C and other languages, the os/exec package intentionally does not invoke the system shell and does not expand any glob patterns or handle other expansions, pipelines, or redirections typically done by shells. The package behaves more like C's "exec" family of functions. To expand glob patterns, either call the shell directly, taking care to escape any dangerous input, or use the path/filepath package's Glob function. To expand environment variables, use package os's ExpandEnv.

This suggests to me that it might introduce unexpected behavior to execute the configured command inside a shell by default.

Ok, thank you for the good explanation. Go's perspective is very reasonable 👍 I think this issue can be closed now.

Thank you @nacro90 do you think this should be documented?

I think it should be documented because according to README, pistol is created to be a replacement to scope.sh, which has the piping capability.

And unfortunately, the sh -c '...' solution is not working. I tried

sh -c 'head %s'
sh -c \'head %s\'
sh -c "head %s"
sh -c \"head %s\"

Reading my code now, I see why this does not work: pistol splits the command string by spaces while sh -c expects the next argument to be all of the shell code to run - the last argument should contain spaces. Meaning this doesn't necessarily affect inline shell code but any kind of quotes usage in a command definition.

I really don't know yet how would I go about and improve the situation, without making the config parser overly complicated and unreliable.

The best advice in the meantime would be to use a wrapper script which is by all means against the philosophy of Pistol :(.

I reviewed the PR and it seems OK to me. I can't build from the code and test it right now but I will when I'm able to. Thank you for the quick response :)