sayanarijit / xplr

A hackable, minimal, fast TUI file explorer
https://xplr.dev
MIT License
4.08k stars 74 forks source link

init: Fix error upon deleting file on non-GNU systems #658

Closed lcook closed 11 months ago

lcook commented 11 months ago

When passing arguments to xargs binaries can only be used, we cannot use a shells builtin command, so this issue cannot be subverted just by installing bash. In this instance, my systems printf implementation does not support the %q format specification—specifically a GNU extension. Yielding this error upon trying to delete a file:

printf: illegal format character q

For a more visual example;

navi:~
% uname ; man 1 printf | grep '%q' | wc -l
FreeBSD
       0
navi:~
% printf "%q\n" \f \oo 'bar'* baz
printf: illegal format character q
navi:~
% bash -c 'printf "%q\n" \f \oo 'bar'* baz '
f
oo
bar\*
baz

Remedying this is just a case of not using xargs and instead iterating through each line of the output pipe, then calling bash's builtin printf (oppose to an actual binary). While bash is still a hard requirement, this makes things less of a headache for new users on non-GNU-like system, in my case FreeBSD (to my understanding neither of the other BSD's support the %q format, seems to be another GNU-ism).

Retrospectively looking, I can only find xargs mentioned in the documentation;

% git grep 'xargs'
docs/en/src/awesome-hacks.md:            --preview="echo {}|sed 's#.*->  ##'| xargs exa --color=always" \
docs/en/src/awesome-plugins.md:[22]: https://github.com/sayanarijit/xargs.xplr

It might be worthwhile combing through the available plugins that may make use of xargs and GNU extensions.

Many thanks, and thank you for your continued work on xplr.

Closes: #652

sayanarijit commented 11 months ago

Thanks for the fix with detailed explanation. I'll try to keep a bsd handy to test things before the next release.

I don't think I have used xargs in plugins other than xargs.xplr. still will check again.

sayanarijit commented 11 months ago

Sorry mistakenly closed