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

README: use safer/better fzf script #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cuonglm
Copy link

@cuonglm cuonglm commented Dec 28, 2022

The current script has some drawbacks:

  • It spawns a sed command for each .age file.
  • If "$PREFIX" contains newline, sed command won't work correctly.
  • Using "$PREFIX" as pattern may lead to code injection.

Fixing those things are simple:

  • cd to "$PREFIX" before running find, we do this in subshell, so no effect to the current shell.
  • Use "find ... -exec sh -c '' sh-find {} +" form, so we can process as much as possible for each exec sh.
  • Use parameter expansion for stripping "./" prefix and ".age" suffix.

The script is now safer, maybe faster, and guarantee to work in all POSIX shells.

The current script has some drawbacks:

 - It spawns a sed command for each .age file.
 - If "$PREFIX" contains newline, sed command won't work correctly.
 - Using "$PREFIX" as pattern may lead to code injection.

Fixing those things are simple:

 - cd to "$PREFIX" before running find, we do this in subshell, so no
   effect to the current shell.
 - Use "find ... -exec sh -c '' sh-find {} +" form, so we can process as
   much as possible for each exec sh.
 - Use parameter expansion for stripping "./" prefix and ".age" suffix.

The script is now safer, maybe faster, and guarantee to work in all
POSIX shells.
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.

1 participant