You are not logged in.
#
# 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)
Offline
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
Offline
how about alias o.sh=xdg-open instead?
Last edited by shpelda (2011-09-19 13:20:56)
Offline