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

Example '$FFF_OPENER' script #101

Open
dylanaraps opened this issue Feb 7, 2019 · 2 comments
Open

Example '$FFF_OPENER' script #101

dylanaraps opened this issue Feb 7, 2019 · 2 comments

Comments

@dylanaraps
Copy link
Owner

dylanaraps commented Feb 7, 2019

#!/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
@lieux
Copy link

lieux commented Apr 5, 2019

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

@Docbroke
Copy link

Docbroke commented Aug 11, 2021

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,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants