You are not logged in.

#1 2011-09-18 11:22:25

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

o.sh — Opening Files in the Unknown

#
# o.sh -- File Opener
#
# This is only a skeleton.
# The order is important, e.g. foo/bar must appear before foo/*
#

o () {
    if [ -d "$@" ]; then
        cd "$@"
    elif [ -e "$@" ]; then
        local mime_type=$(file -L -b --mime-type "$@")
        # filter by mime type
        case $mime_type in
            video/*)
                video_player "$@";;
            audio/*)
                music_$BROWSER "$@";;
            image/vnd.djvu)
                apvlv "$@";;
            image/x-canon-cr2)
                dcraw -T -w "$@";;
            image/*)
                image_viewer "$@";;
            application/postscript)
                gv -presentation "$@";;
            application/pdf)
                document_reader "$@";;
            application/zip)
                unzip -d "${@%.*}" "$@";;
            application/x-rar)
                unrar x "$@";;
            image/svg+xml|application/x-shockwave-flash)
                $BROWSER "$@";;
            application/x-bittorrent)
                diana add "$@";;
            application/msword)
                catdoc -s cp1252 "$@";;
            application/vnd.ms-opentype|application/x-font-ttf)
                fontforge "$@";;
            text/html)
                $BROWSER "$@";;
            *)
                # filter by extension
                case "$@" in
                    *.tar.gz|*.tgz)
                        tar xvzf "$@";;
                    *.tar.bz2)
                        tar xvjf "$@";;
                    *.bz2)
                        bunzip2 "$@";;
                    *.tar)
                        tar xvf "$@";;
                    *.gz)
                        gunzip "$@";;
                    *.chm)
                        xchm "$@";;
                    *.xpm)
                        image_viewer "$@";;
                    *.mp4|*.mpg|*.mpeg|*.mkv|*.ogv|*.f4v)
                        video_player "$@";;
                    *)
                        # filter by mime encoding 
                        local mime_encoding=$(file -L -b --mime-encoding "$@")
                        case $mime_encoding in
                            *binary)
                                xxd -l 256 "$@";;
                            *)
                                $EDITOR "$@";;
                        esac
                        ;;
                esac
                ;;
        esac
    else
        case "$@" in
            *://*)
                $BROWSER "$@";;
            *)
                echo "$@ doesn't exist.";;
        esac
    fi
}

It seems Dave Reisner have written a similar script:
https://raw.github.com/falconindy/bin-scripts/master/xo

Last edited by bloom (2013-02-13 10:19:33)


gh · da · ds

Offline

#2 2011-09-18 11:52:51

3])
Member
From: Netherlands
Registered: 2009-10-12
Posts: 215

Re: o.sh — Opening Files in the Unknown

Would be nice if you gave us an explanation of what it does.

From looking at the bash code, it just opens files with certain programs according to suffix or file type.

Would be quite useful when working at a terminal, and not remembering which programs you have installed.

Last edited by 3]) (2011-09-18 11:53:26)


“There are two ways of constructing a software design. One way is to make it so simple that there are obviously no deficiencies. And the other way is to make it so complicated that there are no obvious deficiencies.”-- C.A.R. Hoare

Offline

#3 2011-09-18 13:43:54

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

Re: o.sh — Opening Files in the Unknown

3]) wrote:

Would be nice if you gave us an explanation of what it does.

It opens a file on the basis of its mime type, extension and mime encoding.
Of course, it has to be modified to suit your preferred applications.


gh · da · ds

Offline

#4 2011-09-19 13:20:40

shpelda
Member
Registered: 2008-08-07
Posts: 59

Re: o.sh — Opening Files in the Unknown

how about alias o.sh=xdg-open  instead?

Last edited by shpelda (2011-09-19 13:20:56)

Offline

#5 2011-09-19 17:49:30

bloom
Member
Registered: 2010-08-18
Posts: 749
Website

Re: o.sh — Opening Files in the Unknown

shpelda wrote:

how about alias o.sh=xdg-open  instead?

(You certainly meant alias o=xdg-open.)
Consider this a minimal and flexible alternative to the aforementioned program.


gh · da · ds

Offline

Board footer

Powered by FluxBB