Skip to content

Open editor only for text files #3698

Closed Answered by LangLangBart
limaceous-bushwhacker asked this question in Q&A
Discussion options

You must be logged in to vote

One idea is to use the transform1 action to check if the file meets certain requirements. The
check below has been used by the maintainer in one of their scripts2 to verify if it's a text
file.

[[ -f {} && ! $(file --dereference --mime -- {}) =~ binary ]]

If the file meets the requirements, perform the desired action, such as become:vim …3, or do
nothing.

Tip

The placeholder, for instance {}, needs to be escaped in the echo statement for transform
actions. Otherwise it will cause issues with files that contain spaces in their names.

echo 'become:vim \{}'

echo 'become:vim {}'

fzf --bind "enter:transform:[[ -f {} && ! \$(file --dereference --mime -- {}) =~ binary ]] &&
  echo 'become:v…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@limaceous-bushwhacker
Comment options

Answer selected by limaceous-bushwhacker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants