fff icon indicating copy to clipboard operation
fff copied to clipboard

Example '$FFF_OPENER' script

Open dylanaraps opened this issue 6 years ago • 2 comments

#!/usr/bin/env bash
#
# opener
[[ -z $1 || ! -e $1 ]] &&
    exit 1

mime_type="$(file -biL "$1")"

case "$mime_type" in
    text/*|*/xml)
        "${VISUAL:-${EDITOR:-vi}}" "$1"
    ;;

    image/*)
        qiv -tBl "$1"
    ;;

    video/*)
        mpv "$1"
    ;;

    audio/*)
        mpv "$1"
    ;;

    application/pdf*)
        "${BROWSER:-firefox}" "$1"
    ;;

    *opendocument*|*openxmlformats*)
        libreoffice "$1"
    ;;

    *)
        printf '%s\n' "warn: No program defined for $mime_type"
    ;;
esac

dylanaraps avatar Feb 07 '19 07:02 dylanaraps

Thanks! I'm currently using this script. But I switched from file to perl-file-mimeinfo because it follows the XDG standard.

lieux avatar Apr 05 '19 01:04 lieux

I have expanded on this idea to create a file-opener script https://github.com/Docbroke/opener

However to use this with fff, some code change is needed. Under the funciton open() entire case statement for file opening may be replaced with below code

                clear_screen
                reset_terminal
                opener "$1"
                setup_terminal
                redraw

I have removed nohup and redirection of terminal output to allow for terminal commands,

Docbroke avatar Aug 11 '21 18:08 Docbroke