Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Make file picker mode work also for non-text files. #171

Open
hsanson opened this issue Feb 7, 2021 · 0 comments
Open

Make file picker mode work also for non-text files. #171

hsanson opened this issue Feb 7, 2021 · 0 comments

Comments

@hsanson
Copy link

hsanson commented Feb 7, 2021

Some editors (e.g. vim/neovim) are capable of opening and editing non text files such as xlsx, and even gcc dumps. Also the mime type sometimes is not identified properly (e.g. tex/latex files) that result in the editor opening external programs instead of opening the file in the editor.

When running in file picker mode (fff -p) it sould open any file in the editor independently of the mime type. The following simple patch implements the change:

--- /usr/bin/fff.bak    2021-02-07 22:41:23.096750364 +0900
+++ /usr/bin/fff        2021-02-07 22:41:29.148677864 +0900
@@ -588,6 +588,15 @@
         redraw full
 
     elif [[ -f $1 ]]; then
+
+        # If 'fff' was opened as a file picker, save the opened
+        # file in a file called 'opened_file'.
+        ((file_picker == 1)) && {
+            printf '%s\n' "$1" > \
+                "${XDG_CACHE_HOME:=${HOME}/.cache}/fff/opened_file"
+            exit
+        }
+
         # Figure out what kind of file we're working with.
         get_mime_type "$1"
 
@@ -595,14 +604,6 @@
         # Everything else goes through 'xdg-open'/'open'.
         case "$mime_type" in
             text/*|*x-empty*|*json*)
-                # If 'fff' was opened as a file picker, save the opened
-                # file in a file called 'opened_file'.
-                ((file_picker == 1)) && {
-                    printf '%s\n' "$1" > \
-                        "${XDG_CACHE_HOME:=${HOME}/.cache}/fff/opened_file"
-                    exit
-                }
-
                 clear_screen
                 reset_terminal
                 "${VISUAL:-${EDITOR:-vi}}" "$1"
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant