I'm writing a humble file manager and am seeking a list of different file types and what default applications Ubuntu uses to open them with.
So far I've only figured out "text" open with gedit
, "image" open with eog
(eye-of-gnome) and "audio" open with ogg123
. I'm not sure if ogg123
is a default application though.
I'd appreciate a little help expanding the list in the code below:
function OpenFileWithMagic () {
local FileType
FileType=$(file -i "$DfName/$2" | grep -oP '(?<=: ).*?(?=/)')
logger "bafman - OpenFileWithMagic - FileType: $FileType DfName: - $DfName parm 1: $1 2: $2 3: $3 4: $4"
case $FileType in
text)
# TODO: expand list of file types and associated applications to open them with
if [[ $4 == root ]]; then
gsu gedit $DfName/$2
else
gedit $DfName/$2
fi ;;
image)
eog $DfName/$2 ;;
audio)
ogg123 $DfName/$2 ;;
esac
} ### OpenFileWithMagic ()
export -f OpenFileWithMagic
Notes: export
is only required because file is opened when double-clicking from yad
dialog box. I also need help figuring out "magic" numbers and how one might interpret them. Perhaps an educating link?
Edit This is not a duplicate of How to open file with default application from command line? because:
- That question is how to open a file from the command line. This question is how do it from a bash script within a
case
structure. - The answer there would result in
rhythembox
being used for sound files which is not wanted.ogg123
is more suited for playing sounds without a new window being opened and closing with python error messages. The answer there would use
xdg-open /bin/mv
resulting in:gvfs-open: /bin/mv: error opening location: No application is registered as handling this file
With the above bash script the
file -i /bin/mv
command results in:/bin/mv: application/x-executable; charset=binary
After filtering out processing for all desired file types within the bash script then the left overs could be passed to xdg-open
which is used in the duplicate candidate.
Reply to comments As pointed out by DK Bose major file types can be found in /usr/share/mime/types
. Here there are additional types to be considered such as Video
(a suitable default Ubuntu video player needs to be sourced), Application
(rather than running it, info about the application needs to be displayed) and Message
(I have no clue how to display this). Additional mime types needing further research are inode
, model
, multipart
and x-content
.
rinzwind pointed out ogg123
is not a default sound file player in Ubuntu. A suitable installed-by-default Ubuntu application to play sound files is canberra-gtk-play
as answered October 5, 2016 by wjzndrea in this Q&A: Can line draw characters (or colors) be added to a Bash file list menu?.
/usr/share/mime
? For example, there's/usr/share/mime/types
.