diff options
-rw-r--r-- | scripts/desc/xdg-mime.xml | 11 | ||||
-rw-r--r-- | scripts/html/xdg-mime.html | 11 | ||||
-rw-r--r-- | scripts/man/xdg-mime.1 | 15 | ||||
-rwxr-xr-x | scripts/xdg-mime | 173 | ||||
-rwxr-xr-x | scripts/xdg-mime.in | 158 |
5 files changed, 210 insertions, 158 deletions
diff --git a/scripts/desc/xdg-mime.xml b/scripts/desc/xdg-mime.xml index 974bdb8..fec2433 100644 --- a/scripts/desc/xdg-mime.xml +++ b/scripts/desc/xdg-mime.xml @@ -42,7 +42,7 @@ and adding descriptions for new file types</refpurpose> <arg choice="plain">filetype</arg> <arg choice="plain">default</arg> </group> - <arg choice="plain"><replaceable>FILE</replaceable></arg> + <arg choice="plain">...</arg> </cmdsynopsis> <cmdsynopsis> <command>xdg-mime</command> @@ -92,8 +92,7 @@ and adding descriptions for new file types</refpurpose> <term>query</term> <listitem> <simpara> - Returns information related to the file type of - <replaceable>FILE</replaceable>. + Returns information related to file types. </simpara> <simpara> The <emphasis>query</emphasis> option is for use inside a desktop session only. @@ -102,12 +101,12 @@ and adding descriptions for new file types</refpurpose> <simpara> The following queries are supported: </simpara> - <simpara><emphasis>filetype</emphasis>: + <simpara>query filetype <replaceable>FILE</replaceable>: Returns the file type of <replaceable>FILE</replaceable> in the form of a MIME type. </simpara> - <simpara><emphasis>default</emphasis>: + <simpara>query default <replaceable>mimetype</replaceable>: Returns the default application that the desktop environment uses for opening - <replaceable>FILE</replaceable>. The default applications is + files of type <replaceable>mimetype</replaceable>. The default application is identified by its *.desktop file. </simpara> </listitem> diff --git a/scripts/html/xdg-mime.html b/scripts/html/xdg-mime.html index a0b1038..1f5ddea 100644 --- a/scripts/html/xdg-mime.html +++ b/scripts/html/xdg-mime.html @@ -1,20 +1,19 @@ <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>xdg-mime</title><meta name="generator" content="DocBook XSL Stylesheets V1.69.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en"><a name="xdg-mime"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>xdg-mime — command line tool for querying information about file type handling -and adding descriptions for new file types</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p><code class="command">xdg-mime</code> query { filetype | default } <em class="replaceable"><code>FILE</code></em> </p></div><div class="cmdsynopsis"><p><code class="command">xdg-mime</code> default <em class="replaceable"><code>application</code></em> <em class="replaceable"><code>mimetype(s)</code></em> </p></div><div class="cmdsynopsis"><p><code class="command">xdg-mime</code> install { <code class="option">--user</code> | <code class="option">--system</code> } <em class="replaceable"><code>mimetypes-file</code></em> </p></div><div class="cmdsynopsis"><p><code class="command">xdg-mime</code> uninstall { <code class="option">--user</code> | <code class="option">--system</code> } <em class="replaceable"><code>mimetypes-file</code></em> </p></div><div class="cmdsynopsis"><p><code class="command">xdg-mime</code> { <code class="option">--help</code> | <code class="option">--manual</code> | <code class="option">--version</code> }</p></div></div><div class="refsect1" lang="en"><a name="description"></a><h2>Description</h2><p> +and adding descriptions for new file types</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p><code class="command">xdg-mime</code> query { filetype | default } ... </p></div><div class="cmdsynopsis"><p><code class="command">xdg-mime</code> default <em class="replaceable"><code>application</code></em> <em class="replaceable"><code>mimetype(s)</code></em> </p></div><div class="cmdsynopsis"><p><code class="command">xdg-mime</code> install { <code class="option">--user</code> | <code class="option">--system</code> } <em class="replaceable"><code>mimetypes-file</code></em> </p></div><div class="cmdsynopsis"><p><code class="command">xdg-mime</code> uninstall { <code class="option">--user</code> | <code class="option">--system</code> } <em class="replaceable"><code>mimetypes-file</code></em> </p></div><div class="cmdsynopsis"><p><code class="command">xdg-mime</code> { <code class="option">--help</code> | <code class="option">--manual</code> | <code class="option">--version</code> }</p></div></div><div class="refsect1" lang="en"><a name="description"></a><h2>Description</h2><p> The xdg-mime program can be used to query information about file types and to add descriptions for new file types. </p></div><div class="refsect1" lang="en"><a name="commands"></a><h2>Commands</h2><div class="variablelist"><dl><dt><span class="term">query</span></dt><dd><p> - Returns information related to the file type of - <em class="replaceable"><code>FILE</code></em>. + Returns information related to file types. </p><p> The <span class="emphasis"><em>query</em></span> option is for use inside a desktop session only. It is not recommended to use xdg-mime query as root. </p><p> The following queries are supported: - </p><p><span class="emphasis"><em>filetype</em></span>: + </p><p>query filetype <em class="replaceable"><code>FILE</code></em>: Returns the file type of <em class="replaceable"><code>FILE</code></em> in the form of a MIME type. - </p><p><span class="emphasis"><em>default</em></span>: + </p><p>query default <em class="replaceable"><code>mimetype</code></em>: Returns the default application that the desktop environment uses for opening - <em class="replaceable"><code>FILE</code></em>. The default applications is + files of type <em class="replaceable"><code>mimetype</code></em>. The default application is identified by its *.desktop file. </p></dd><dt><span class="term">default</span></dt><dd><p> Ask the desktop environment to make <em class="replaceable"><code>application</code></em> diff --git a/scripts/man/xdg-mime.1 b/scripts/man/xdg-mime.1 index 4c1878c..7128b7f 100644 --- a/scripts/man/xdg-mime.1 +++ b/scripts/man/xdg-mime.1 @@ -2,7 +2,7 @@ .\" It was generated using the DocBook XSL Stylesheets (version 1.69.1). .\" Instead of manually editing it, you probably should edit the DocBook XML .\" source for it and then use the DocBook XSL Stylesheets to regenerate it. -.TH "XDG\-MIME" "1" "07/17/2006" "This is release 0.5 of the xdg\-mime Manu" "" +.TH "XDG\-MIME" "1" "07/28/2006" "This is release 0.5 of the xdg\-mime Manu" "" .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) @@ -11,7 +11,7 @@ xdg\-mime \- command line tool for querying information about file type handling and adding descriptions for new file types .SH "SYNOPSIS" .HP 9 -\fBxdg\-mime\fR query {filetype default} \fIFILE\fR +\fBxdg\-mime\fR query {filetype default} ... .HP 9 \fBxdg\-mime\fR default \fIapplication\fR \fImimetype(s)\fR .HP 9 @@ -26,8 +26,7 @@ The xdg\-mime program can be used to query information about file types and to a .SH "COMMANDS" .TP query -Returns information related to the file type of -\fIFILE\fR. +Returns information related to file types. .sp The \fIquery\fR @@ -35,12 +34,14 @@ option is for use inside a desktop session only. It is not recommended to use xd .sp The following queries are supported: .sp -\fIfiletype\fR: Returns the file type of +query filetype +\fIFILE\fR: Returns the file type of \fIFILE\fR in the form of a MIME type. .sp -\fIdefault\fR: Returns the default application that the desktop environment uses for opening -\fIFILE\fR. The default applications is identified by its *.desktop file. +query default +\fImimetype\fR: Returns the default application that the desktop environment uses for opening files of type +\fImimetype\fR. The default application is identified by its *.desktop file. .TP default Ask the desktop environment to make diff --git a/scripts/xdg-mime b/scripts/xdg-mime index 7575312..163339b 100755 --- a/scripts/xdg-mime +++ b/scripts/xdg-mime @@ -42,7 +42,7 @@ and adding descriptions for new file types Synopsis -xdg-mime query { filetype | default } FILE +xdg-mime query { filetype | default } ... xdg-mime default application mimetype(s) @@ -61,18 +61,19 @@ Commands query - Returns information related to the file type of FILE. + Returns information related to file types. The query option is for use inside a desktop session only. It is not recommended to use xdg-mime query as root. The following queries are supported: - filetype: Returns the file type of FILE in the form of a MIME type. + query filetype FILE: Returns the file type of FILE in the form of a MIME + type. - default: Returns the default application that the desktop environment uses - for opening FILE. The default applications is identified by its *.desktop - file. + query default mimetype: Returns the default application that the desktop + environment uses for opening files of type mimetype. The default + application is identified by its *.desktop file. default @@ -193,7 +194,7 @@ and adding descriptions for new file types Synopsis -xdg-mime query { filetype | default } FILE +xdg-mime query { filetype | default } ... xdg-mime default application mimetype(s) @@ -439,29 +440,37 @@ make_default_generic() defapp_kde() { - DEBUG 1 "Running kfile \"$1\"" - MIME=`kfile "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1` - DEBUG 2 "MIME = $MIME" - - if [ x"$MIME" != x"" ]; then - DEBUG 1 "Running ktradertest \"$MIME\" Application" - trader_result=`ktradertest "$MIME" Application 2>/dev/null | grep DesktopEntryPath \ + MIME="$1" + DEBUG 1 "Running ktradertest \"$MIME\" Application" + trader_result=`ktradertest "$MIME" Application 2>/dev/null | grep DesktopEntryPath \ | head -n 1 | cut -d ':' -f 2 | cut -d \' -f 2` - if [ -n "$trader_result" ] ; then - basename "$trader_result" - fi + if [ -n "$trader_result" ] ; then + basename "$trader_result" exit_success else exit_failure_operation_failed fi } -defapp_gnome() +defapp_generic() { - DEBUG 1 "Running gnomevfs-info \"$1\"" - gnomevfs-info "$1" 2> /dev/null | grep "Default app" | cut -d ":" -f 2 \ - | cut -d " " -f 2 - +# FIXME: +# Find XDG-DATA-DIRS/applications/defaults.list + MIME="$1" + xdg_user_dir="$XDG_DATA_HOME" + [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" + xdg_user_dir="$xdg_user_dir/$xdg_dir_name" + xdg_system_dirs="$XDG_DATA_DIRS" + [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/ + + for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do + DEBUG 2 "Checking $x/applications/defaults.list" + trader_result=`grep "$MIME=" $x/applications/defaults.list 2> /dev/null | cut -d '=' -f 2` + if [ -n "$trader_result" ] ; then + echo $trader_result + exit_success + fi + done exit_success } @@ -542,6 +551,7 @@ uninstall_xsl() mode= action= filename= +mimetype= case $1 in install) @@ -562,10 +572,40 @@ case $1 in case $1 in filetype) action=info + + filename="$2" + if [ -z "$filename" ] ; then + exit_failure_syntax "FILE argument missing" + fi + case $filename in + -*) + exit_failure_syntax "unexpected option '$filename'" + ;; + esac + if [ ! -f "$filename" ] ; then + exit_failure_file_missing "file '$filename' does not exist" + fi ;; default) action=defapp + mimetype="$2" + if [ -z "$mimetype" ] ; then + exit_failure_syntax "mimetype argument missing" + fi + case $mimetype in + -*) + exit_failure_syntax "unexpected option '$mimetype'" + ;; + + */*) + # Ok + ;; + + *) + exit_failure_syntax "mimetype '$mimetype' is not in the form 'minor/major'" + ;; + esac ;; *) @@ -624,47 +664,7 @@ if [ "$action" = "makedefault" ]; then exit_success fi -while [ $# -gt 0 ] ; do - parm="$1" - shift - - case $parm in - --user) - mode=user - ;; - - --system) - mode=system - ;; - - -*) - exit_failure_syntax "unexpected option '$parm'" - ;; - - *) - if [ -n "$filename" ] ; then - exit_failure_syntax "unexpected argument '$parm'" - fi - if [ ! -f "$parm" ] ; then - exit_failure_file_missing "file '$parm' does not exist" - fi - filename="$parm" - ;; - esac -done - -if [ -z "$action" ] ; then - exit_failure_syntax "command argument missing" -fi - if [ "$action" = "info" ]; then - if [ -n "$mode" ] ; then - exit_failure_syntax "unexpected option '--$mode'" - fi - if [ -z "$filename" ] ; then - exit_failure_syntax "FILE argument missing" - fi - detectDE if [ x"$DE" = x"" ]; then @@ -690,27 +690,54 @@ if [ "$action" = "info" ]; then fi if [ "$action" = "defapp" ]; then - if [ -n "$mode" ] ; then - exit_failure_syntax "unexpected option '--$mode'" - fi - if [ -z "$filename" ] ; then - exit_failure_syntax "FILE argument missing" - fi - detectDE case "$DE" in kde) - defapp_kde "$filename" + defapp_kde "$mimetype" ;; - gnome) - defapp_gnome "$filename" + *) + defapp_generic "$mimetype" + ;; + esac + exit_failure_operation_impossible "no method available for quering default application for '$mimetype'" +fi + +while [ $# -gt 0 ] ; do + parm="$1" + shift + + case $parm in + --user) + mode=user + ;; + + --system) + mode=system + ;; + + -*) + exit_failure_syntax "unexpected option '$parm'" + ;; + + *) + if [ -n "$filename" ] ; then + exit_failure_syntax "unexpected argument '$parm'" + fi + if [ ! -f "$parm" ] ; then + exit_failure_file_missing "file '$parm' does not exist" + fi + filename="$parm" ;; esac - exit_failure_operation_impossible "no method available for quering default application for file '$filename'" +done + +if [ -z "$action" ] ; then + exit_failure_syntax "command argument missing" fi + if [ -z "$mode" ] ; then exit_failure_syntax "expected --user or --system option" fi diff --git a/scripts/xdg-mime.in b/scripts/xdg-mime.in index c7986eb..ec1605a 100755 --- a/scripts/xdg-mime.in +++ b/scripts/xdg-mime.in @@ -125,29 +125,37 @@ make_default_generic() defapp_kde() { - DEBUG 1 "Running kfile \"$1\"" - MIME=`kfile "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1` - DEBUG 2 "MIME = $MIME" - - if [ x"$MIME" != x"" ]; then - DEBUG 1 "Running ktradertest \"$MIME\" Application" - trader_result=`ktradertest "$MIME" Application 2>/dev/null | grep DesktopEntryPath \ + MIME="$1" + DEBUG 1 "Running ktradertest \"$MIME\" Application" + trader_result=`ktradertest "$MIME" Application 2>/dev/null | grep DesktopEntryPath \ | head -n 1 | cut -d ':' -f 2 | cut -d \' -f 2` - if [ -n "$trader_result" ] ; then - basename "$trader_result" - fi + if [ -n "$trader_result" ] ; then + basename "$trader_result" exit_success else exit_failure_operation_failed fi } -defapp_gnome() +defapp_generic() { - DEBUG 1 "Running gnomevfs-info \"$1\"" - gnomevfs-info "$1" 2> /dev/null | grep "Default app" | cut -d ":" -f 2 \ - | cut -d " " -f 2 - +# FIXME: +# Find XDG-DATA-DIRS/applications/defaults.list + MIME="$1" + xdg_user_dir="$XDG_DATA_HOME" + [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share" + xdg_user_dir="$xdg_user_dir/$xdg_dir_name" + xdg_system_dirs="$XDG_DATA_DIRS" + [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/ + + for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do + DEBUG 2 "Checking $x/applications/defaults.list" + trader_result=`grep "$MIME=" $x/applications/defaults.list 2> /dev/null | cut -d '=' -f 2` + if [ -n "$trader_result" ] ; then + echo $trader_result + exit_success + fi + done exit_success } @@ -228,6 +236,7 @@ uninstall_xsl() mode= action= filename= +mimetype= case $1 in install) @@ -248,10 +257,40 @@ case $1 in case $1 in filetype) action=info + + filename="$2" + if [ -z "$filename" ] ; then + exit_failure_syntax "FILE argument missing" + fi + case $filename in + -*) + exit_failure_syntax "unexpected option '$filename'" + ;; + esac + if [ ! -f "$filename" ] ; then + exit_failure_file_missing "file '$filename' does not exist" + fi ;; default) action=defapp + mimetype="$2" + if [ -z "$mimetype" ] ; then + exit_failure_syntax "mimetype argument missing" + fi + case $mimetype in + -*) + exit_failure_syntax "unexpected option '$mimetype'" + ;; + + */*) + # Ok + ;; + + *) + exit_failure_syntax "mimetype '$mimetype' is not in the form 'minor/major'" + ;; + esac ;; *) @@ -310,47 +349,7 @@ if [ "$action" = "makedefault" ]; then exit_success fi -while [ $# -gt 0 ] ; do - parm="$1" - shift - - case $parm in - --user) - mode=user - ;; - - --system) - mode=system - ;; - - -*) - exit_failure_syntax "unexpected option '$parm'" - ;; - - *) - if [ -n "$filename" ] ; then - exit_failure_syntax "unexpected argument '$parm'" - fi - if [ ! -f "$parm" ] ; then - exit_failure_file_missing "file '$parm' does not exist" - fi - filename="$parm" - ;; - esac -done - -if [ -z "$action" ] ; then - exit_failure_syntax "command argument missing" -fi - if [ "$action" = "info" ]; then - if [ -n "$mode" ] ; then - exit_failure_syntax "unexpected option '--$mode'" - fi - if [ -z "$filename" ] ; then - exit_failure_syntax "FILE argument missing" - fi - detectDE if [ x"$DE" = x"" ]; then @@ -376,27 +375,54 @@ if [ "$action" = "info" ]; then fi if [ "$action" = "defapp" ]; then - if [ -n "$mode" ] ; then - exit_failure_syntax "unexpected option '--$mode'" - fi - if [ -z "$filename" ] ; then - exit_failure_syntax "FILE argument missing" - fi - detectDE case "$DE" in kde) - defapp_kde "$filename" + defapp_kde "$mimetype" ;; - gnome) - defapp_gnome "$filename" + *) + defapp_generic "$mimetype" + ;; + esac + exit_failure_operation_impossible "no method available for quering default application for '$mimetype'" +fi + +while [ $# -gt 0 ] ; do + parm="$1" + shift + + case $parm in + --user) + mode=user + ;; + + --system) + mode=system + ;; + + -*) + exit_failure_syntax "unexpected option '$parm'" + ;; + + *) + if [ -n "$filename" ] ; then + exit_failure_syntax "unexpected argument '$parm'" + fi + if [ ! -f "$parm" ] ; then + exit_failure_file_missing "file '$parm' does not exist" + fi + filename="$parm" ;; esac - exit_failure_operation_impossible "no method available for quering default application for file '$filename'" +done + +if [ -z "$action" ] ; then + exit_failure_syntax "command argument missing" fi + if [ -z "$mode" ] ; then exit_failure_syntax "expected --user or --system option" fi |