[GB.DESKTOP]
* NEW: Update xdg-utils scripts to the last version (1.1.1). git-svn-id: svn://localhost/gambas/trunk@7502 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
145edbfec5
commit
da9e37f4c0
13 changed files with 3397 additions and 2990 deletions
|
@ -18,13 +18,14 @@ LastCommit="[GB.DESKTOP]\n* BUG: Change the Mime loading code so it not fail on
|
|||
|
||||
[OpenFile]
|
||||
File[1]=".src/DesktopMime.class:0.90"
|
||||
Active=6
|
||||
Active=5
|
||||
File[2]=".src/Tests/Form11.form"
|
||||
Count=6
|
||||
Count=7
|
||||
File[3]=".src/Main.module:18.10"
|
||||
File[4]=".src/DesktopFile.class:0.347"
|
||||
File[5]=".src/Desktop.class:12.83"
|
||||
File[6]=".src/DesktopWatcher.class:2.33"
|
||||
File[7]="xdg-utils/xdg-open:0.0"
|
||||
|
||||
[VersionControl]
|
||||
User="gambix"
|
||||
|
|
|
@ -1,303 +0,0 @@
|
|||
#!/bin/sh
|
||||
#---------------------------------------------
|
||||
# xdg-copy
|
||||
#
|
||||
# Utility script to copy files specified by URLs, including
|
||||
# downloading and uploading from/to remote sites.
|
||||
#
|
||||
# Refer to the usage() function below for usage.
|
||||
#
|
||||
# Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
|
||||
# Copyright 2006, Jeremy White <jwhite@codeweavers.com>
|
||||
#
|
||||
# LICENSE:
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the "Software"),
|
||||
# to deal in the Software without restriction, including without limitation
|
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
# and/or sell copies of the Software, and to permit persons to whom the
|
||||
# Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included
|
||||
# in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
# OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
#---------------------------------------------
|
||||
|
||||
manualpage()
|
||||
{
|
||||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-copy -- command line tool for copying files between desktop URIs
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-copy source destination
|
||||
|
||||
xdg-copy { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
xdg-copy copies source to destination and provides visual feedback to the
|
||||
user during the operation. Both source and destination can either be a
|
||||
file or URL. Supported URL types are file, ftp, http and https. Additional
|
||||
URL types may be supported depending on the desktop environment.
|
||||
|
||||
xdg-copy is for use inside a desktop session only. It is not recommended
|
||||
to use xdg-copy as root.
|
||||
|
||||
Options
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
|
||||
--manual
|
||||
Show this manualpage.
|
||||
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
|
||||
2
|
||||
One of the files passed on the command line did not exist.
|
||||
|
||||
3
|
||||
A required tool could not be found.
|
||||
|
||||
4
|
||||
The action failed.
|
||||
|
||||
Examples
|
||||
|
||||
xdg-copy "http://portland.freedesktop.org/png/freedesktop-logo.png" .
|
||||
|
||||
xdg-copy "/tmp/foobar.png" "/home/user/foobar-copy.png"
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-copy -- command line tool for copying files between desktop URIs
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-copy source destination
|
||||
|
||||
xdg-copy { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
||||
#@xdg-utils-common@
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Common utility functions included in all XDG wrapper scripts
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
exit_success()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "$@"
|
||||
echo
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------
|
||||
# Exit script on malformed arguments, not enough arguments
|
||||
# or missing required option.
|
||||
# prints usage information
|
||||
|
||||
exit_failure_syntax()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-copy: $@" >&2
|
||||
echo "Try 'xdg-copy --help' for more information." >&2
|
||||
else
|
||||
usage
|
||||
echo "Use 'man xdg-copy' or 'xdg-copy --manual' for additional info."
|
||||
fi
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on missing file specified on command line
|
||||
|
||||
exit_failure_file_missing()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-copy: $@" >&2
|
||||
fi
|
||||
|
||||
exit 2
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on failure to locate necessary tool applications
|
||||
|
||||
exit_failure_operation_impossible()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-copy: $@" >&2
|
||||
fi
|
||||
|
||||
exit 3
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on failure returned by a tool application
|
||||
|
||||
exit_failure_operation_failed()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-copy: $@" >&2
|
||||
fi
|
||||
|
||||
exit 4
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------
|
||||
# Checks for shared commands, e.g. --help
|
||||
|
||||
check_common_commands()
|
||||
{
|
||||
while [ $# -gt 0 ] ; do
|
||||
parm=$1
|
||||
shift
|
||||
|
||||
case $parm in
|
||||
--help)
|
||||
usage
|
||||
echo "Use 'man xdg-copy' or 'xdg-copy --manual' for additional info."
|
||||
exit_success
|
||||
;;
|
||||
|
||||
--manual)
|
||||
manualpage
|
||||
exit_success
|
||||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-copy 1.0beta1"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
check_common_commands "$@"
|
||||
|
||||
#--------------------------------------
|
||||
# Checks for known desktop environments
|
||||
# set variable DE to the desktop environments name, lowercase
|
||||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
fi
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
copy_kde()
|
||||
{
|
||||
kfmclient copy "$1" "$2"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
}
|
||||
|
||||
copy_gnome()
|
||||
{
|
||||
if gvfs-copy --help 2>/dev/null 1>&2; then
|
||||
gvfs-copy "$1" "$2"
|
||||
else
|
||||
gnomevfs-copy "$1" "$2"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
}
|
||||
|
||||
[ x"$1" != x"" ] || exit_failure_syntax
|
||||
|
||||
source=
|
||||
dest=
|
||||
while [ $# -gt 0 ] ; do
|
||||
parm=$1
|
||||
shift
|
||||
|
||||
case $parm in
|
||||
-*)
|
||||
exit_failure_syntax "unexpected option '$parm'"
|
||||
;;
|
||||
|
||||
*)
|
||||
if [ -n "$dest" ] ; then
|
||||
exit_failure_syntax "unexpected argument '$parm'"
|
||||
fi
|
||||
if [ -n "$source" ] ; then
|
||||
dest=$parm
|
||||
else
|
||||
source=$parm
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "${source}" ] ; then
|
||||
exit_failure_syntax "source argument missing"
|
||||
fi
|
||||
if [ -z "${dest}" ] ; then
|
||||
exit_failure_syntax "destination argument missing"
|
||||
fi
|
||||
|
||||
detectDE
|
||||
|
||||
case "$DE" in
|
||||
kde)
|
||||
copy_kde "$source" "$dest"
|
||||
;;
|
||||
|
||||
gnome)
|
||||
copy_gnome "$source" "$dest"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit_failure_operation_impossible "no method available for copying '$source' to '$dest'"
|
||||
;;
|
||||
esac
|
378
comp/src/gb.desktop/xdg-utils/xdg-desktop-icon
Normal file → Executable file
378
comp/src/gb.desktop/xdg-utils/xdg-desktop-icon
Normal file → Executable file
|
@ -36,15 +36,16 @@
|
|||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-desktop-icon - command line tool for (un)installing icons to the desktop
|
||||
xdg-desktop-icon - command line tool for (un)installing icons
|
||||
to the desktop
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-desktop-icon install [--novendor] FILE
|
||||
xdg-desktop-icon install [--novendor] FILE
|
||||
|
||||
xdg-desktop-icon uninstall FILE
|
||||
xdg-desktop-icon uninstall FILE
|
||||
|
||||
xdg-desktop-icon { --help | --manual | --version }
|
||||
xdg-desktop-icon { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
@ -54,136 +55,160 @@ manualpage()
|
|||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-desktop-icon - command line tool for (un)installing icons to the desktop
|
||||
xdg-desktop-icon - command line tool for (un)installing icons
|
||||
to the desktop
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-desktop-icon install [--novendor] FILE
|
||||
xdg-desktop-icon install [--novendor] FILE
|
||||
|
||||
xdg-desktop-icon uninstall FILE
|
||||
xdg-desktop-icon uninstall FILE
|
||||
|
||||
xdg-desktop-icon { --help | --manual | --version }
|
||||
xdg-desktop-icon { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
The xdg-desktop-icon program can be used to install an application launcher or
|
||||
other file on the desktop of the current user.
|
||||
The xdg-desktop-icon program can be used to install an
|
||||
application launcher or other file on the desktop of the
|
||||
current user.
|
||||
|
||||
An application launcher is represented by a *.desktop file. Desktop files are
|
||||
defined by the freedesktop.org Desktop Entry Specification. The most important
|
||||
aspects of *.desktop files are summarized below.
|
||||
An application launcher is represented by a *.desktop file.
|
||||
Desktop files are defined by the freedesktop.org Desktop Entry
|
||||
Specification. The most important aspects of *.desktop files
|
||||
are summarized below.
|
||||
|
||||
Commands
|
||||
|
||||
install
|
||||
Installs FILE to the desktop of the current user. FILE can be a *.desktop
|
||||
file or any other type of file.
|
||||
uninstall
|
||||
Removes FILE from the desktop of the current user.
|
||||
install
|
||||
Installs FILE to the desktop of the current user. FILE
|
||||
can be a *.desktop file or any other type of file.
|
||||
|
||||
uninstall
|
||||
Removes FILE from the desktop of the current user.
|
||||
|
||||
Options
|
||||
|
||||
--novendor
|
||||
--novendor
|
||||
Normally, xdg-desktop-icon checks to ensure that a
|
||||
*.desktop file to be installed has a vendor prefix. This
|
||||
option can be used to disable that check.
|
||||
|
||||
Normally, xdg-desktop-icon checks to ensure that a *.desktop file to be
|
||||
installed has a vendor prefix. This option can be used to disable that
|
||||
check.
|
||||
A vendor prefix consists of alpha characters ([a-zA-Z])
|
||||
and is terminated with a dash ("-"). Companies and
|
||||
organizations are encouraged to use a word or phrase,
|
||||
preferably the organizations name, for which they hold a
|
||||
trademark as their vendor prefix. The purpose of the
|
||||
vendor prefix is to prevent name conflicts.
|
||||
|
||||
A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated
|
||||
with a dash ("-"). Companies and organizations are encouraged to use a word
|
||||
or phrase, preferably the organizations name, for which they hold a
|
||||
trademark as their vendor prefix. The purpose of the vendor prefix is to
|
||||
prevent name conflicts.
|
||||
--help
|
||||
Show command synopsis.
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
--manual
|
||||
Show this manualpage.
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
--manual
|
||||
Show this manual page.
|
||||
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Desktop Files
|
||||
|
||||
An application launcher can be added to the desktop by installing a *.desktop
|
||||
file. A *.desktop file consists of a [Desktop Entry] header followed by several
|
||||
Key=Value lines.
|
||||
An application launcher can be added to the desktop by
|
||||
installing a *.desktop file. A *.desktop file consists of a
|
||||
[Desktop Entry] header followed by several Key=Value lines.
|
||||
|
||||
A *.desktop file can provide a name and description for an application in
|
||||
several different languages. This is done by adding a language code as used by
|
||||
LC_MESSAGES in square brackets behind the Key. This way one can specify
|
||||
different values for the same Key depending on the currently selected language.
|
||||
A *.desktop file can provide a name and description for an
|
||||
application in several different languages. This is done by
|
||||
adding a language code as used by LC_MESSAGES in square
|
||||
brackets behind the Key. This way one can specify different
|
||||
values for the same Key depending on the currently selected
|
||||
language.
|
||||
|
||||
The following keys are often used:
|
||||
The following keys are often used:
|
||||
|
||||
Value=1.0
|
||||
This is a mandatory field to indicate that the *.desktop file follows the
|
||||
1.0 version of the specification.
|
||||
Type=Application
|
||||
This is a mandatory field that indicates that the *.desktop file describes
|
||||
an application launcher.
|
||||
Name=Application Name
|
||||
The name of the application. For example Mozilla
|
||||
GenericName=Generic Name
|
||||
A generic description of the application. For example Web Browser
|
||||
Comment=Comment
|
||||
Optional field to specify a tooltip for the application. For example Visit
|
||||
websites on the Internet
|
||||
Icon=Icon File
|
||||
The icon to use for the application. This can either be an absolute path to
|
||||
an image file or an icon-name. If an icon-name is provided an image lookup
|
||||
by name is done in the user's current icon theme. The xdg-icon-resource
|
||||
command can be used to install image files into icon themes. The advantage
|
||||
of using an icon-name instead of an absolute path is that with an icon-name
|
||||
the application icon can be provided in several different sizes as well as
|
||||
in several differently themed styles.
|
||||
Exec=Command Line
|
||||
The command line to start the application. If the application can open
|
||||
files the %f placeholder should be specified. When a file is dropped on the
|
||||
application launcher the %f is replaced with the file path of the dropped
|
||||
file. If multiple files can be specified on the command line the %F
|
||||
placeholder should be used instead of %f. If the application is able to
|
||||
open URLs in addition to local files then %u or %U can be used instead of
|
||||
%f or %F.
|
||||
Type=Application
|
||||
This is a mandatory field that indicates that the
|
||||
*.desktop file describes an application launcher.
|
||||
|
||||
For a complete oveview of the *.desktop file format please visit http://
|
||||
www.freedesktop.org/wiki/Standards/desktop-entry-spec
|
||||
Name=Application Name
|
||||
The name of the application. For example Mozilla
|
||||
|
||||
GenericName=Generic Name
|
||||
A generic description of the application. For example
|
||||
Web Browser
|
||||
|
||||
Comment=Comment
|
||||
Optional field to specify a tooltip for the application.
|
||||
For example Visit websites on the Internet
|
||||
|
||||
Icon=Icon File
|
||||
The icon to use for the application. This can either be
|
||||
an absolute path to an image file or an icon-name. If an
|
||||
icon-name is provided an image lookup by name is done in
|
||||
the user's current icon theme. The xdg-icon-resource
|
||||
command can be used to install image files into icon
|
||||
themes. The advantage of using an icon-name instead of
|
||||
an absolute path is that with an icon-name the
|
||||
application icon can be provided in several different
|
||||
sizes as well as in several differently themed styles.
|
||||
|
||||
Exec=Command Line
|
||||
The command line to start the application. If the
|
||||
application can open files the %f placeholder should be
|
||||
specified. When a file is dropped on the application
|
||||
launcher the %f is replaced with the file path of the
|
||||
dropped file. If multiple files can be specified on the
|
||||
command line the %F placeholder should be used instead
|
||||
of %f. If the application is able to open URLs in
|
||||
addition to local files then %u or %U can be used
|
||||
instead of %f or %F.
|
||||
|
||||
For a complete overview of the *.desktop file format please
|
||||
visit
|
||||
http://www.freedesktop.org/wiki/Specifications/desktop-entry-sp
|
||||
ec
|
||||
|
||||
Environment Variables
|
||||
|
||||
xdg-desktop-icon honours the following environment variables:
|
||||
xdg-desktop-icon honours the following environment variables:
|
||||
|
||||
XDG_UTILS_DEBUG_LEVEL
|
||||
Setting this environment variable to a non-zero numerical value makes
|
||||
xdg-desktop-icon do more verbose reporting on stderr. Setting a higher
|
||||
value increases the verbosity.
|
||||
XDG_UTILS_DEBUG_LEVEL
|
||||
Setting this environment variable to a non-zero
|
||||
numerical value makes xdg-desktop-icon do more verbose
|
||||
reporting on stderr. Setting a higher value increases
|
||||
the verbosity.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
An exit code of 0 indicates success while a non-zero exit code
|
||||
indicates failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
2
|
||||
One of the files passed on the command line did not exist.
|
||||
3
|
||||
A required tool could not be found.
|
||||
4
|
||||
The action failed.
|
||||
5
|
||||
No permission to read one of the files passed on the command line.
|
||||
1
|
||||
Error in command line syntax.
|
||||
|
||||
2
|
||||
One of the files passed on the command line did not
|
||||
exist.
|
||||
|
||||
3
|
||||
A required tool could not be found.
|
||||
|
||||
4
|
||||
The action failed.
|
||||
|
||||
5
|
||||
No permission to read one of the files passed on the
|
||||
command line.
|
||||
|
||||
See Also
|
||||
|
||||
xdg-icon-resource(1)
|
||||
xdg-icon-resource(1)
|
||||
|
||||
Examples
|
||||
|
||||
The company ShinyThings Inc. has developed an application named "WebMirror" and
|
||||
would like to add a launcher for for on the desktop. The company will use
|
||||
"shinythings" as its vendor id. In order to add the application to the desktop
|
||||
there needs to be a .desktop file for the application:
|
||||
|
||||
The company ShinyThings Inc. has developed an application named
|
||||
"WebMirror" and would like to add a launcher for for on the
|
||||
desktop. The company will use "shinythings" as its vendor id.
|
||||
In order to add the application to the desktop there needs to
|
||||
be a .desktop file for the application:
|
||||
shinythings-webmirror.desktop:
|
||||
|
||||
[Desktop Entry]
|
||||
|
@ -196,15 +221,13 @@ shinythings-webmirror.desktop:
|
|||
Name=WebMirror
|
||||
Name[nl]=WebSpiegel
|
||||
|
||||
Now the xdg-desktop-icon tool can be used to add the webmirror.desktop file to
|
||||
the desktop:
|
||||
|
||||
Now the xdg-desktop-icon tool can be used to add the
|
||||
webmirror.desktop file to the desktop:
|
||||
xdg-desktop-icon install ./shinythings-webmirror.desktop
|
||||
|
||||
To add a README file to the desktop as well, the following command can be used:
|
||||
|
||||
To add a README file to the desktop as well, the following
|
||||
command can be used:
|
||||
xdg-desktop-icon install ./shinythings-README
|
||||
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
|
@ -222,6 +245,64 @@ DEBUG()
|
|||
echo "$@" >&2
|
||||
}
|
||||
|
||||
# This handles backslashes but not quote marks.
|
||||
first_word()
|
||||
{
|
||||
read first rest
|
||||
echo "$first"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a binary to a .desktop file
|
||||
binary_to_desktop_file()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
binary="`which "$1"`"
|
||||
binary="`readlink -f "$binary"`"
|
||||
base="`basename "$binary"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] || continue
|
||||
[ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
|
||||
for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
|
||||
[ -r "$file" ] || continue
|
||||
# Check to make sure it's worth the processing.
|
||||
grep -q "^Exec.*$base" "$file" || continue
|
||||
# Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
|
||||
grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
if [ x"`readlink -f "$command"`" = x"$binary" ]; then
|
||||
# Fix any double slashes that got added path composition
|
||||
echo "$file" | sed -e 's,//*,/,g'
|
||||
return
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a .desktop file to a binary
|
||||
## FIXME: handle vendor dir case
|
||||
desktop_file_to_binary()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
desktop="`basename "$1"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] && [ -d "$dir/applications" ] || continue
|
||||
file="$dir/applications/$desktop"
|
||||
[ -r "$file" ] || continue
|
||||
# Remove any arguments (%F, %f, %U, %u, etc.).
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
readlink -f "$command"
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
|
@ -330,7 +411,7 @@ check_vendor_prefix()
|
|||
[ -n "$file_label" ] || file_label="filename"
|
||||
file=`basename "$1"`
|
||||
case "$file" in
|
||||
[a-zA-Z]*-*)
|
||||
[[:alpha:]]*-*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
@ -352,7 +433,7 @@ check_output_file()
|
|||
fi
|
||||
else
|
||||
DIR=`dirname "$1"`
|
||||
if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
|
||||
if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
|
||||
exit_failure_file_permission_write "no permission to create file '$1'"
|
||||
fi
|
||||
fi
|
||||
|
@ -380,7 +461,7 @@ check_common_commands()
|
|||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-desktop-icon 1.1.0 rc1"
|
||||
echo "xdg-desktop-icon 1.1.0 rc3"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
|
@ -404,12 +485,86 @@ fi
|
|||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
|
||||
else DE=""
|
||||
# see https://bugs.freedesktop.org/show_bug.cgi?id=34164
|
||||
unset GREP_OPTIONS
|
||||
|
||||
if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
|
||||
case "${XDG_CURRENT_DESKTOP}" in
|
||||
# only recently added to menu-spec, pre-spec X- still in use
|
||||
Cinnamon|X-Cinnamon)
|
||||
DE=cinnamon;
|
||||
;;
|
||||
ENLIGHTENMENT)
|
||||
DE=enlightenment;
|
||||
;;
|
||||
# GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
|
||||
GNOME*)
|
||||
DE=gnome;
|
||||
;;
|
||||
KDE)
|
||||
DE=kde;
|
||||
;;
|
||||
LXDE)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
XFCE)
|
||||
DE=xfce
|
||||
;;
|
||||
X-Generic)
|
||||
DE=generic
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# classic fallbacks
|
||||
if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
|
||||
elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to checking $DESKTOP_SESSION
|
||||
case "$DESKTOP_SESSION" in
|
||||
gnome)
|
||||
DE=gnome;
|
||||
;;
|
||||
LXDE|Lubuntu)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
xfce|xfce4|'Xfce Session')
|
||||
DE=xfce;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to uname output for other platforms
|
||||
case "$(uname 2>/dev/null)" in
|
||||
CYGWIN*)
|
||||
DE=cygwin;
|
||||
;;
|
||||
Darwin)
|
||||
DE=darwin;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"gnome" ]; then
|
||||
# gnome-default-applications-properties is only available in GNOME 2.x
|
||||
# but not in GNOME 3.x
|
||||
which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -420,7 +575,6 @@ detectDE()
|
|||
|
||||
kfmclient_fix_exit_code()
|
||||
{
|
||||
[ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
|
||||
version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
|
||||
major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
|
||||
minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
|
||||
|
@ -519,7 +673,7 @@ if [ -n "$desktop_dir_kde" ]; then
|
|||
umask $save_umask
|
||||
fi
|
||||
# Is the KDE desktop dir != $HOME/Desktop ?
|
||||
if [ x`readlink -f "$desktop_dir"` != x`readlink -f "$desktop_dir_kde"` ]; then
|
||||
if [ "x`readlink -f "$desktop_dir"`" != "x`readlink -f "$desktop_dir_kde"`" ]; then
|
||||
# If so, don't create $HOME/Desktop if it doesn't exist
|
||||
[ -w "$desktop_dir" ] || desktop_dir=
|
||||
else
|
||||
|
|
663
comp/src/gb.desktop/xdg-utils/xdg-desktop-menu
Normal file → Executable file
663
comp/src/gb.desktop/xdg-utils/xdg-desktop-menu
Normal file → Executable file
|
@ -37,254 +37,295 @@ manualpage()
|
|||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-desktop-menu - command line tool for (un)installing desktop menu items
|
||||
xdg-desktop-menu - command line tool for (un)installing desktop
|
||||
menu items
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-desktop-menu install [--noupdate] [--novendor] [--mode mode] directory-file
|
||||
(s) desktop-file(s)
|
||||
xdg-desktop-menu install [--noupdate] [--novendor] [--mode
|
||||
mode] directory-file(s) desktop-file(s)
|
||||
|
||||
xdg-desktop-menu uninstall [--noupdate] [--mode mode] directory-file(s)
|
||||
desktop-file(s)
|
||||
xdg-desktop-menu uninstall [--noupdate] [--mode mode]
|
||||
directory-file(s) desktop-file(s)
|
||||
|
||||
xdg-desktop-menu forceupdate [--mode mode]
|
||||
xdg-desktop-menu forceupdate [--mode mode]
|
||||
|
||||
xdg-desktop-menu { --help | --manual | --version }
|
||||
xdg-desktop-menu { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
The xdg-desktop-menu program can be used to install new menu entries to the
|
||||
desktop's application menu.
|
||||
The xdg-desktop-menu program can be used to install new menu
|
||||
entries to the desktop's application menu.
|
||||
|
||||
The application menu works according to the XDG Desktop Menu Specification at
|
||||
http://www.freedesktop.org/Standards/menu-spec
|
||||
The application menu works according to the XDG Desktop Menu
|
||||
Specification at
|
||||
http://www.freedesktop.org/wiki/Specifications/menu-spec
|
||||
|
||||
Commands
|
||||
|
||||
install
|
||||
install
|
||||
Install one or more applications in a submenu of the
|
||||
desktop menu system.
|
||||
|
||||
Install one or more applications in a submenu of the desktop menu system.
|
||||
desktop-file: A desktop file represents a single menu
|
||||
entry in the menu. Desktop files are defined by the
|
||||
freedesktop.org Desktop Entry Specification. The most
|
||||
important aspects of *.desktop files are summarized
|
||||
below.
|
||||
|
||||
desktop-file: A desktop file represents a single menu entry in the menu.
|
||||
Desktop files are defined by the freedesktop.org Desktop Entry
|
||||
Specification. The most important aspects of *.desktop files are summarized
|
||||
below.
|
||||
Menu entries can be added to the menu system in two
|
||||
different ways. They can either be added to a predefined
|
||||
submenu in the menu system based on one or more category
|
||||
keywords, or they can be added to a new submenu.
|
||||
|
||||
Menu entries can be added to the menu system in two different ways. They
|
||||
can either be added to a predefined submenu in the menu system based on one
|
||||
or more category keywords, or they can be added to a new submenu.
|
||||
To add a menu entry to a predefined submenu the desktop
|
||||
file that represents the menu entry must have a
|
||||
Categories= entry that lists one or more keywords. The
|
||||
menu item will be included in an appropriate submenu
|
||||
based on the included keywords.
|
||||
|
||||
To add a menu entry to a predefined submenu the desktop file that
|
||||
represents the menu entry must have a Categories= entry that lists one or
|
||||
more keywords. The menu item will be included in an appropriate submenu
|
||||
based on the included keywords.
|
||||
To add menu items to a new submenu the desktop-files
|
||||
must be preceded by a directory-file that describes the
|
||||
submenu. If multiple desktop-files are specified, all
|
||||
entries will be added to the same menu. If entries are
|
||||
installed to a menu that has been created with a
|
||||
previous call to xdg-desktop-menu the entries will be
|
||||
installed in addition to any already existing entries.
|
||||
|
||||
To add menu items to a new submenu the desktop-files must be preceded by a
|
||||
directory-file that describes the submenu. If multiple desktop-files are
|
||||
specified, all entries will be added to the same menu. If entries are
|
||||
installed to a menu that has been created with a previous call to
|
||||
xdg-desktop-menu the entries will be installed in addition to any already
|
||||
existing entries.
|
||||
directory-file: The *.directory file indicated by
|
||||
directory-file represents a submenu. The directory file
|
||||
provides the name and icon for a submenu. The name of
|
||||
the directory file is used to identify the submenu.
|
||||
|
||||
directory-file: The *.directory file indicated by directory-file represents
|
||||
a submenu. The directory file provides the name and icon for a submenu. The
|
||||
name of the directory file is used to identify the submenu.
|
||||
If multiple directory files are provided each file will
|
||||
represent a submenu within the menu that precedes it,
|
||||
creating a nested menu hierarchy (sub-sub-menus). The
|
||||
menu entries themselves will be added to the last
|
||||
submenu.
|
||||
|
||||
If multiple directory files are provided each file will represent a submenu
|
||||
within the menu that preceeds it, creating a nested menu hierarchy
|
||||
(sub-sub-menus). The menu entries themselves will be added to the last
|
||||
submenu.
|
||||
Directory files follow the syntax defined by the
|
||||
freedesktop.org Desktop Entry Specification.
|
||||
|
||||
Directory files follow the syntax defined by the freedesktop.org Desktop
|
||||
Entry Specification.
|
||||
uninstall
|
||||
Remove applications or submenus from the desktop menu
|
||||
system previously installed with xdg-desktop-menu
|
||||
install.
|
||||
|
||||
uninstall
|
||||
A submenu and the associated directory file is only
|
||||
removed when the submenu no longer contains any menu
|
||||
entries.
|
||||
|
||||
Remove applications or submenus from the desktop menu system previously
|
||||
installed with xdg-desktop-menu install.
|
||||
forceupdate
|
||||
Force an update of the menu system.
|
||||
|
||||
A submenu and the associated directory file is only removed when the
|
||||
submenu no longer contains any menu entries.
|
||||
|
||||
forceupdate
|
||||
|
||||
Force an update of the menu system.
|
||||
|
||||
This command is only useful if the last call to xdg-desktop-menu included
|
||||
the --noupdate option.
|
||||
This command is only useful if the last call to
|
||||
xdg-desktop-menu included the --noupdate option.
|
||||
|
||||
Options
|
||||
|
||||
--noupdate
|
||||
Postpone updating the menu system. If multiple updates to the menu system
|
||||
are made in sequence this flag can be used to indicate that additional
|
||||
changes will follow and that it is not necassery to update the menu system
|
||||
right away.
|
||||
--novendor
|
||||
--noupdate
|
||||
Postpone updating the menu system. If multiple updates
|
||||
to the menu system are made in sequence this flag can be
|
||||
used to indicate that additional changes will follow and
|
||||
that it is not necessary to update the menu system right
|
||||
away.
|
||||
|
||||
Normally, xdg-desktop-menu checks to ensure that any *.directory and
|
||||
*.desktop files to be installed has a vendor prefix. This option can be
|
||||
used to disable that check.
|
||||
--novendor
|
||||
Normally, xdg-desktop-menu checks to ensure that any
|
||||
*.directory and *.desktop files to be installed has a
|
||||
vendor prefix. This option can be used to disable that
|
||||
check.
|
||||
|
||||
A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated
|
||||
with a dash ("-"). Companies and organizations are encouraged to use a word
|
||||
or phrase, preferably the organizations name, for which they hold a
|
||||
trademark as their vendor prefix. The purpose of the vendor prefix is to
|
||||
prevent name conflicts.
|
||||
A vendor prefix consists of alpha characters ([a-zA-Z])
|
||||
and is terminated with a dash ("-"). Companies and
|
||||
organizations are encouraged to use a word or phrase,
|
||||
preferably the organizations name, for which they hold a
|
||||
trademark as their vendor prefix. The purpose of the
|
||||
vendor prefix is to prevent name conflicts.
|
||||
|
||||
--mode mode
|
||||
--mode mode
|
||||
mode can be user or system. In user mode the file is
|
||||
(un)installed for the current user only. In system mode
|
||||
the file is (un)installed for all users on the system.
|
||||
Usually only root is allowed to install in system mode.
|
||||
|
||||
mode can be user or system. In user mode the file is (un)installed for the
|
||||
current user only. In system mode the file is (un)installed for all users
|
||||
on the system. Usually only root is allowed to install in system mode.
|
||||
The default is to use system mode when called by root
|
||||
and to use user mode when called by a non-root user.
|
||||
|
||||
The default is to use system mode when called by root and to use user mode
|
||||
when called by a non-root user.
|
||||
--help
|
||||
Show command synopsis.
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
--manual
|
||||
Show this manualpage.
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
--manual
|
||||
Show this manual page.
|
||||
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Desktop Files
|
||||
|
||||
An application item in the application menu is represented by a *.desktop file.
|
||||
A *.desktop file consists of a [Desktop Entry] header followed by several Key=
|
||||
Value lines.
|
||||
An application item in the application menu is represented by a
|
||||
*.desktop file. A *.desktop file consists of a [Desktop Entry]
|
||||
header followed by several Key=Value lines.
|
||||
|
||||
A *.desktop file can provide a name and description for an application in
|
||||
several different languages. This is done by adding a language code as used by
|
||||
LC_MESSAGES in square brackets behind the Key. This way one can specify
|
||||
different values for the same Key depending on the currently selected language.
|
||||
A *.desktop file can provide a name and description for an
|
||||
application in several different languages. This is done by
|
||||
adding a language code as used by LC_MESSAGES in square
|
||||
brackets behind the Key. This way one can specify different
|
||||
values for the same Key depending on the currently selected
|
||||
language.
|
||||
|
||||
The following keys are often used:
|
||||
The following keys are often used:
|
||||
|
||||
Value=1.0
|
||||
This is a mandatory field to indicate that the *.desktop file follows the
|
||||
1.0 version of the specification.
|
||||
Type=Application
|
||||
This is a mandatory field that indicates that the *.desktop file describes
|
||||
an application launcher.
|
||||
Name=Application Name
|
||||
The name of the application. For example Mozilla
|
||||
GenericName=Generic Name
|
||||
A generic description of the application. For example Web Browser
|
||||
Comment=Comment
|
||||
Optional field to specify a tooltip for the application. For example Visit
|
||||
websites on the Internet
|
||||
Icon=Icon File
|
||||
The icon to use for the application. This can either be an absolute path to
|
||||
an image file or an icon-name. If an icon-name is provided an image lookup
|
||||
by name is done in the user's current icon theme. The xdg-icon-resource
|
||||
command can be used to install image files into icon themes. The advantage
|
||||
of using an icon-name instead of an absolute path is that with an icon-name
|
||||
the application icon can be provided in several different sizes as well as
|
||||
in several differently themed styles.
|
||||
Exec=Command Line
|
||||
The command line to start the application. If the application can open
|
||||
files the %f placeholder should be specified. When a file is dropped on the
|
||||
application launcher the %f is replaced with the file path of the dropped
|
||||
file. If multiple files can be specified on the command line the %F
|
||||
placeholder should be used instead of %f. If the application is able to
|
||||
open URLs in addition to local files then %u or %U can be used instead of
|
||||
%f or %F.
|
||||
Categories=Categories
|
||||
Type=Application
|
||||
This is a mandatory field that indicates that the
|
||||
*.desktop file describes an application launcher.
|
||||
|
||||
A list of categories separated by semi-colons. A category is a keyword that
|
||||
describes and classifies the application. By default applications are
|
||||
organized in the application menu based on category. When menu entries are
|
||||
explicitly assigned to a new submenu it is not necassery to list any
|
||||
categories.
|
||||
Name=Application Name
|
||||
The name of the application. For example Mozilla
|
||||
|
||||
When using categories it is recommended to include one of the following
|
||||
categories: AudioVideo, Development, Education, Game, Graphics, Network,
|
||||
Office, Settings, System, Utility.
|
||||
GenericName=Generic Name
|
||||
A generic description of the application. For example
|
||||
Web Browser
|
||||
|
||||
See Appendix A of the XDG Desktop Menu Specification for information about
|
||||
additional categories. http://standards.freedesktop.org/menu-spec/
|
||||
menu-spec-1.0.html
|
||||
Comment=Comment
|
||||
Optional field to specify a tooltip for the application.
|
||||
For example Visit websites on the Internet
|
||||
|
||||
MimeType=Mimetypes
|
||||
A list of mimetypes separated by semi-colons. This field is used to
|
||||
indicate which file types the application is able to open.
|
||||
Icon=Icon File
|
||||
The icon to use for the application. This can either be
|
||||
an absolute path to an image file or an icon-name. If an
|
||||
icon-name is provided an image lookup by name is done in
|
||||
the user's current icon theme. The xdg-icon-resource
|
||||
command can be used to install image files into icon
|
||||
themes. The advantage of using an icon-name instead of
|
||||
an absolute path is that with an icon-name the
|
||||
application icon can be provided in several different
|
||||
sizes as well as in several differently themed styles.
|
||||
|
||||
For a complete oveview of the *.desktop file format please visit http://
|
||||
www.freedesktop.org/wiki/Standards/desktop-entry-spec
|
||||
Exec=Command Line
|
||||
The command line to start the application. If the
|
||||
application can open files the %f placeholder should be
|
||||
specified. When a file is dropped on the application
|
||||
launcher the %f is replaced with the file path of the
|
||||
dropped file. If multiple files can be specified on the
|
||||
command line the %F placeholder should be used instead
|
||||
of %f. If the application is able to open URLs in
|
||||
addition to local files then %u or %U can be used
|
||||
instead of %f or %F.
|
||||
|
||||
Categories=Categories
|
||||
A list of categories separated by semi-colons. A
|
||||
category is a keyword that describes and classifies the
|
||||
application. By default applications are organized in
|
||||
the application menu based on category. When menu
|
||||
entries are explicitly assigned to a new submenu it is
|
||||
not necessary to list any categories.
|
||||
|
||||
When using categories it is recommended to include one
|
||||
of the following categories: AudioVideo, Development,
|
||||
Education, Game, Graphics, Network, Office, Settings,
|
||||
System, Utility.
|
||||
|
||||
See Appendix A of the XDG Desktop Menu Specification for
|
||||
information about additional categories:
|
||||
http://standards.freedesktop.org/menu-spec/menu-spec-1.0
|
||||
.html#category-registry
|
||||
|
||||
MimeType=Mimetypes
|
||||
A list of mimetypes separated by semi-colons. This field
|
||||
is used to indicate which file types the application is
|
||||
able to open.
|
||||
|
||||
For a complete overview of the *.desktop file format please
|
||||
visit
|
||||
http://www.freedesktop.org/wiki/Specifications/desktop-entry-sp
|
||||
ec
|
||||
|
||||
Directory Files
|
||||
|
||||
The appearance of submenu in the application menu is provided by a *.directory
|
||||
file. In particular it provides the title of the submenu and a possible icon. A
|
||||
*.directory file consists of a [Desktop Entry] header followed by several Key=
|
||||
Value lines.
|
||||
The appearance of submenu in the application menu is provided
|
||||
by a *.directory file. In particular it provides the title of
|
||||
the submenu and a possible icon. A *.directory file consists of
|
||||
a [Desktop Entry] header followed by several Key=Value lines.
|
||||
|
||||
A *.directory file can provide a title (name) for the submenu in several
|
||||
different languages. This is done by adding a language code as used by
|
||||
LC_MESSAGES in square brackets behind the Key. This way one can specify
|
||||
different values for the same Key depending on the currently selected language.
|
||||
A *.directory file can provide a title (name) for the submenu
|
||||
in several different languages. This is done by adding a
|
||||
language code as used by LC_MESSAGES in square brackets behind
|
||||
the Key. This way one can specify different values for the same
|
||||
Key depending on the currently selected language.
|
||||
|
||||
The following keys are relevqnt for submenus:
|
||||
The following keys are relevant for submenus:
|
||||
|
||||
Value=1.0
|
||||
This is a mandatory field to indicate that the *.directory file follows the
|
||||
1.0 version of the Desktop Entry specification.
|
||||
Type=Directory
|
||||
This is a mandatory field that indicates that the *.directory file
|
||||
describes a submenu.
|
||||
Name=Menu Name
|
||||
The title of submenu. For example Mozilla
|
||||
Comment=Comment
|
||||
Optional field to specify a tooltip for the submenu.
|
||||
Icon=Icon File
|
||||
The icon to use for the submenu. This can either be an absolute path to an
|
||||
image file or an icon-name. If an icon-name is provided an image lookup by
|
||||
name is done in the user's current icon theme. The xdg-icon-resource
|
||||
command can be used to install image files into icon themes. The advantage
|
||||
of using an icon-name instead of an absolute path is that with an icon-name
|
||||
the submenu icon can be provided in several different sizes as well as in
|
||||
several differently themed styles.
|
||||
Type=Directory
|
||||
This is a mandatory field that indicates that the
|
||||
*.directory file describes a submenu.
|
||||
|
||||
Name=Menu Name
|
||||
The title of submenu. For example Mozilla
|
||||
|
||||
Comment=Comment
|
||||
Optional field to specify a tooltip for the submenu.
|
||||
|
||||
Icon=Icon File
|
||||
The icon to use for the submenu. This can either be an
|
||||
absolute path to an image file or an icon-name. If an
|
||||
icon-name is provided an image lookup by name is done in
|
||||
the user's current icon theme. The xdg-icon-resource
|
||||
command can be used to install image files into icon
|
||||
themes. The advantage of using an icon-name instead of
|
||||
an absolute path is that with an icon-name the submenu
|
||||
icon can be provided in several different sizes as well
|
||||
as in several differently themed styles.
|
||||
|
||||
Environment Variables
|
||||
|
||||
xdg-desktop-menu honours the following environment variables:
|
||||
xdg-desktop-menu honours the following environment variables:
|
||||
|
||||
XDG_UTILS_DEBUG_LEVEL
|
||||
Setting this environment variable to a non-zero numerical value makes
|
||||
xdg-desktop-menu do more verbose reporting on stderr. Setting a higher
|
||||
value increases the verbosity.
|
||||
XDG_UTILS_INSTALL_MODE
|
||||
This environment variable can be used by the user or administrator to
|
||||
override the installation mode. Valid values are user and system.
|
||||
XDG_UTILS_DEBUG_LEVEL
|
||||
Setting this environment variable to a non-zero
|
||||
numerical value makes xdg-desktop-menu do more verbose
|
||||
reporting on stderr. Setting a higher value increases
|
||||
the verbosity.
|
||||
|
||||
XDG_UTILS_INSTALL_MODE
|
||||
This environment variable can be used by the user or
|
||||
administrator to override the installation mode. Valid
|
||||
values are user and system.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
An exit code of 0 indicates success while a non-zero exit code
|
||||
indicates failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
2
|
||||
One of the files passed on the command line did not exist.
|
||||
3
|
||||
A required tool could not be found.
|
||||
4
|
||||
The action failed.
|
||||
5
|
||||
No permission to read one of the files passed on the command line.
|
||||
1
|
||||
Error in command line syntax.
|
||||
|
||||
2
|
||||
One of the files passed on the command line did not
|
||||
exist.
|
||||
|
||||
3
|
||||
A required tool could not be found.
|
||||
|
||||
4
|
||||
The action failed.
|
||||
|
||||
5
|
||||
No permission to read one of the files passed on the
|
||||
command line.
|
||||
|
||||
See Also
|
||||
|
||||
xdg-desktop-icon(1), xdg-icon-resource(1), xdg-mime(1)
|
||||
xdg-desktop-icon(1), xdg-icon-resource(1), xdg-mime(1), Desktop
|
||||
entry specification, Desktop menu specification
|
||||
|
||||
Examples
|
||||
|
||||
The company ShinyThings Inc. has developed an application named "WebMirror" and
|
||||
would like to add it to the application menu. The company will use
|
||||
"shinythings" as its vendor id. In order to add the application to the menu
|
||||
there needs to be a .desktop file with a suitable Categories entry:
|
||||
|
||||
The company ShinyThings Inc. has developed an application named
|
||||
"WebMirror" and would like to add it to the application menu.
|
||||
The company will use "shinythings" as its vendor id. In order
|
||||
to add the application to the menu there needs to be a .desktop
|
||||
file with a suitable Categories entry:
|
||||
shinythings-webmirror.desktop:
|
||||
|
||||
[Desktop Entry]
|
||||
|
@ -299,22 +340,23 @@ shinythings-webmirror.desktop:
|
|||
|
||||
Categories=Network;WebDevelopment;
|
||||
|
||||
Now the xdg-desktop-menu tool can be used to add the
|
||||
shinythings-webmirror.desktop file to the desktop application menu:
|
||||
|
||||
Now the xdg-desktop-menu tool can be used to add the
|
||||
shinythings-webmirror.desktop file to the desktop application
|
||||
menu:
|
||||
xdg-desktop-menu install ./shinythings-webmirror.desktop
|
||||
|
||||
Note that for the purpose of this example the menu items are available in two
|
||||
languages, English and Dutch. The language code for Dutch is nl.
|
||||
Note that for the purpose of this example the menu items are
|
||||
available in two languages, English and Dutch. The language
|
||||
code for Dutch is nl.
|
||||
|
||||
In the next example the company ShinyThings Inc. will add its own submenu to
|
||||
the desktop application menu consisting of a "WebMirror" menu item and a
|
||||
"WebMirror Admin Tool" menu item.
|
||||
|
||||
First the company needs to create two .desktop files that describe the two menu
|
||||
items. Since the items are to be added to a new submenu it is not necassery to
|
||||
include a Categories= line:
|
||||
In the next example the company ShinyThings Inc. will add its
|
||||
own submenu to the desktop application menu consisting of a
|
||||
"WebMirror" menu item and a "WebMirror Admin Tool" menu item.
|
||||
|
||||
First the company needs to create two .desktop files that
|
||||
describe the two menu items. Since the items are to be added to
|
||||
a new submenu it is not necessary to include a Categories=
|
||||
line:
|
||||
shinythings-webmirror.desktop:
|
||||
|
||||
[Desktop Entry]
|
||||
|
@ -340,9 +382,8 @@ shinythings-webmirror-admin.desktop:
|
|||
Name=WebMirror Admin Tool
|
||||
Name[nl]=WebSpiegel Administratie Tool
|
||||
|
||||
In addition a .directory file needs to be created to provide a title and icon
|
||||
for the sub-menu itself:
|
||||
|
||||
In addition a .directory file needs to be created to provide a
|
||||
title and icon for the sub-menu itself:
|
||||
shinythings-webmirror.directory:
|
||||
|
||||
[Desktop Entry]
|
||||
|
@ -353,53 +394,58 @@ shinythings-webmirror.directory:
|
|||
Name=WebMirror
|
||||
Name[nl]=WebSpiegel
|
||||
|
||||
These file can now be installed with:
|
||||
|
||||
These file can now be installed with:
|
||||
xdg-desktop-menu install ./shinythings-webmirror.directory \
|
||||
./shinythings-webmirror.desktop ./shinythings-webmirror-admin.desktop
|
||||
|
||||
The menu entries could also be installed one by one:
|
||||
./shinythings-webmirror.desktop ./shinythings-webmirror-admin.desk
|
||||
top
|
||||
|
||||
The menu entries could also be installed one by one:
|
||||
xdg-desktop-menu install --noupdate ./shinythings-webmirror.directory \
|
||||
./shinythings-webmirror.desktop
|
||||
xdg-desktop-menu install --noupdate ./shinythings-webmirror.directory \
|
||||
./shinythings-webmirror-admin.desktop
|
||||
xdg-desktop-menu forceupdate
|
||||
|
||||
Although the result is the same it is slightly more efficient to install all
|
||||
files at the same time.
|
||||
|
||||
The *.desktop and *.directory files reference icons with the names webmirror,
|
||||
webmirror-admin and webmirror-menu which should also be installed. In this
|
||||
example the icons are installed in two different sizes, once with a size of
|
||||
22x22 pixels and once with a size of 64x64 pixels:
|
||||
|
||||
xdg-icon-resource install --size 22 ./wmicon-22.png shinythings-webmirror
|
||||
xdg-icon-resource install --size 22 ./wmicon-menu-22.png shinythings-webmirror-menu
|
||||
xdg-icon-resource install --size 22 ./wmicon-admin-22.png shinythings-webmirror-admin
|
||||
xdg-icon-resource install --size 64 ./wmicon-64.png shinythings-webmirror
|
||||
xdg-icon-resource install --size 64 ./wmicon-menu-64.png shinythings-webmirror-menu
|
||||
xdg-icon-resource install --size 64 ./wmicon-admin-64.png shinythings-webmirror-admin
|
||||
Although the result is the same it is slightly more efficient
|
||||
to install all files at the same time.
|
||||
|
||||
The *.desktop and *.directory files reference icons with the
|
||||
names webmirror, webmirror-admin and webmirror-menu which
|
||||
should also be installed. In this example the icons are
|
||||
installed in two different sizes, once with a size of 22x22
|
||||
pixels and once with a size of 64x64 pixels:
|
||||
xdg-icon-resource install --size 22 ./wmicon-22.png shinythings-webmirro
|
||||
r
|
||||
xdg-icon-resource install --size 22 ./wmicon-menu-22.png shinythings-web
|
||||
mirror-menu
|
||||
xdg-icon-resource install --size 22 ./wmicon-admin-22.png shinythings-we
|
||||
bmirror-admin
|
||||
xdg-icon-resource install --size 64 ./wmicon-64.png shinythings-webmirro
|
||||
r
|
||||
xdg-icon-resource install --size 64 ./wmicon-menu-64.png shinythings-web
|
||||
mirror-menu
|
||||
xdg-icon-resource install --size 64 ./wmicon-admin-64.png shinythings-we
|
||||
bmirror-admin
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-desktop-menu - command line tool for (un)installing desktop menu items
|
||||
xdg-desktop-menu - command line tool for (un)installing desktop
|
||||
menu items
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-desktop-menu install [--noupdate] [--novendor] [--mode mode] directory-file
|
||||
(s) desktop-file(s)
|
||||
xdg-desktop-menu install [--noupdate] [--novendor] [--mode
|
||||
mode] directory-file(s) desktop-file(s)
|
||||
|
||||
xdg-desktop-menu uninstall [--noupdate] [--mode mode] directory-file(s)
|
||||
desktop-file(s)
|
||||
xdg-desktop-menu uninstall [--noupdate] [--mode mode]
|
||||
directory-file(s) desktop-file(s)
|
||||
|
||||
xdg-desktop-menu forceupdate [--mode mode]
|
||||
xdg-desktop-menu forceupdate [--mode mode]
|
||||
|
||||
xdg-desktop-menu { --help | --manual | --version }
|
||||
xdg-desktop-menu { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
@ -418,6 +464,64 @@ DEBUG()
|
|||
echo "$@" >&2
|
||||
}
|
||||
|
||||
# This handles backslashes but not quote marks.
|
||||
first_word()
|
||||
{
|
||||
read first rest
|
||||
echo "$first"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a binary to a .desktop file
|
||||
binary_to_desktop_file()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
binary="`which "$1"`"
|
||||
binary="`readlink -f "$binary"`"
|
||||
base="`basename "$binary"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] || continue
|
||||
[ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
|
||||
for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
|
||||
[ -r "$file" ] || continue
|
||||
# Check to make sure it's worth the processing.
|
||||
grep -q "^Exec.*$base" "$file" || continue
|
||||
# Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
|
||||
grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
if [ x"`readlink -f "$command"`" = x"$binary" ]; then
|
||||
# Fix any double slashes that got added path composition
|
||||
echo "$file" | sed -e 's,//*,/,g'
|
||||
return
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a .desktop file to a binary
|
||||
## FIXME: handle vendor dir case
|
||||
desktop_file_to_binary()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
desktop="`basename "$1"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] && [ -d "$dir/applications" ] || continue
|
||||
file="$dir/applications/$desktop"
|
||||
[ -r "$file" ] || continue
|
||||
# Remove any arguments (%F, %f, %U, %u, etc.).
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
readlink -f "$command"
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
|
@ -526,7 +630,7 @@ check_vendor_prefix()
|
|||
[ -n "$file_label" ] || file_label="filename"
|
||||
file=`basename "$1"`
|
||||
case "$file" in
|
||||
[a-zA-Z]*-*)
|
||||
[[:alpha:]]*-*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
@ -548,7 +652,7 @@ check_output_file()
|
|||
fi
|
||||
else
|
||||
DIR=`dirname "$1"`
|
||||
if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
|
||||
if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
|
||||
exit_failure_file_permission_write "no permission to create file '$1'"
|
||||
fi
|
||||
fi
|
||||
|
@ -576,7 +680,7 @@ check_common_commands()
|
|||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-desktop-menu 1.1.0 rc1"
|
||||
echo "xdg-desktop-menu 1.1.0 rc3"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
|
@ -600,12 +704,86 @@ fi
|
|||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
|
||||
else DE=""
|
||||
# see https://bugs.freedesktop.org/show_bug.cgi?id=34164
|
||||
unset GREP_OPTIONS
|
||||
|
||||
if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
|
||||
case "${XDG_CURRENT_DESKTOP}" in
|
||||
# only recently added to menu-spec, pre-spec X- still in use
|
||||
Cinnamon|X-Cinnamon)
|
||||
DE=cinnamon;
|
||||
;;
|
||||
ENLIGHTENMENT)
|
||||
DE=enlightenment;
|
||||
;;
|
||||
# GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
|
||||
GNOME*)
|
||||
DE=gnome;
|
||||
;;
|
||||
KDE)
|
||||
DE=kde;
|
||||
;;
|
||||
LXDE)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
XFCE)
|
||||
DE=xfce
|
||||
;;
|
||||
X-Generic)
|
||||
DE=generic
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# classic fallbacks
|
||||
if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
|
||||
elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to checking $DESKTOP_SESSION
|
||||
case "$DESKTOP_SESSION" in
|
||||
gnome)
|
||||
DE=gnome;
|
||||
;;
|
||||
LXDE|Lubuntu)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
xfce|xfce4|'Xfce Session')
|
||||
DE=xfce;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to uname output for other platforms
|
||||
case "$(uname 2>/dev/null)" in
|
||||
CYGWIN*)
|
||||
DE=cygwin;
|
||||
;;
|
||||
Darwin)
|
||||
DE=darwin;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"gnome" ]; then
|
||||
# gnome-default-applications-properties is only available in GNOME 2.x
|
||||
# but not in GNOME 3.x
|
||||
which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -616,7 +794,6 @@ detectDE()
|
|||
|
||||
kfmclient_fix_exit_code()
|
||||
{
|
||||
[ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
|
||||
version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
|
||||
major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
|
||||
minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
|
||||
|
@ -687,7 +864,7 @@ make_lazy_default()
|
|||
# App already listed as default
|
||||
continue;
|
||||
fi
|
||||
default_file="$1/defaults.list"
|
||||
default_file="$(readlink -f "$1/defaults.list")"
|
||||
DEBUG 1 "Updating $default_file"
|
||||
grep -v "$MIME=" $default_file > ${default_file}.new 2> /dev/null
|
||||
if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then
|
||||
|
@ -757,7 +934,7 @@ update_submenu()
|
|||
return
|
||||
fi
|
||||
|
||||
if [ $action = "install" -a -f "/etc/xdg/menus/gnome-applications.menu" ] ; then
|
||||
if [ $action = "install" ] && [ -f "/etc/xdg/menus/gnome-applications.menu" ] ; then
|
||||
# Work around for Debian Gnome
|
||||
gnome_xdg_dir=`echo "$xdg_dir" | sed -e 's^/applications-merged^/gnome-applications-merged^'`
|
||||
if [ ! -e "$gnome_xdg_dir" ] ; then
|
||||
|
@ -766,7 +943,7 @@ update_submenu()
|
|||
eval 'ln -s "applications-merged" "$gnome_xdg_dir"'$xdg_redirect_output
|
||||
fi
|
||||
fi
|
||||
if [ $action = "install" -a -f "/etc/mandrake-release" ] ; then
|
||||
if [ $action = "install" ] && [ -f "/etc/mandrake-release" ] ; then
|
||||
# Work around for Mandriva 2006
|
||||
mandrake_xdg_dir=`echo "$xdg_dir" | sed -e 's^/applications-merged^/applications-mdk-merged^'`
|
||||
if [ ! -e "$mandrake_xdg_dir" ] ; then
|
||||
|
@ -775,7 +952,7 @@ update_submenu()
|
|||
eval 'ln -s "applications-merged" "$mandrake_xdg_dir"'$xdg_redirect_output
|
||||
fi
|
||||
fi
|
||||
if [ $action = "install" -a x"$mode" = x"user" -a -d "/etc/xdg/menus/kde-applications-merged" ] ; then
|
||||
if [ $action = "install" -a x"$mode" = x"user" ] && [ -d "/etc/xdg/menus/kde-applications-merged" ] ; then
|
||||
# Work around for Fedora Core 5 + patched KDE
|
||||
kde_xdg_dir=`echo "$xdg_dir" | sed -e 's^/applications-merged^/kde-applications-merged^'`
|
||||
if [ ! -e "$kde_xdg_dir" ] ; then
|
||||
|
@ -784,7 +961,7 @@ update_submenu()
|
|||
eval 'ln -s "applications-merged" "$kde_xdg_dir"'$xdg_redirect_output
|
||||
fi
|
||||
fi
|
||||
if [ $action = "install" -a x"$mode" = x"system" -a -d "/etc/xdg/menus/kde-applications-merged" -a ! -d "/etc/xdg/menus/applications-merged" ] ; then
|
||||
if [ $action = "install" -a x"$mode" = x"system" ] && [ -d "/etc/xdg/menus/kde-applications-merged" ] && [ ! -d "/etc/xdg/menus/applications-merged" ] ; then
|
||||
# Work around for Kubuntu 6.06
|
||||
kde_xdg_dir=`echo "$xdg_dir" | sed -e 's^/applications-merged^/kde-applications-merged^'`
|
||||
DEBUG 1 "Kubuntu Workaround: Link '$xdg_dir' to 'kde-applications-merged'"
|
||||
|
@ -830,12 +1007,14 @@ BEGIN {
|
|||
done
|
||||
# Files to uninstall are listed in $tmpfile
|
||||
# Existing files are in $orig_desktop_files
|
||||
if [ ! -z "$orig_desktop_files" ]; then
|
||||
for desktop_file in $orig_desktop_files; do
|
||||
if ! grep '^'$desktop_file'$' $tmpfile > /dev/null 2> /dev/null; then
|
||||
# Keep this file, it's not in the uninstall list
|
||||
new_desktop_files="$new_desktop_files $desktop_file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
rm -f "$tmpfile"
|
||||
|
||||
|
@ -892,7 +1071,7 @@ BEGIN {
|
|||
test "${TMPDIR+set}" = set || TMPDIR=/tmp
|
||||
tmpfile=`mktemp $TMPDIR/tmp.XXXXXXXXXX`
|
||||
for menu_file in $xdg_dir/*; do
|
||||
if grep 'generated and managed by xdg-desktop-menu' $menu_file > /dev/null 2> /dev/null; then
|
||||
if grep 'generated and managed by xdg-desktop-menu' "$menu_file" > /dev/null 2> /dev/null; then
|
||||
awk '
|
||||
# List all files within <Directory> tags
|
||||
BEGIN {
|
||||
|
@ -902,7 +1081,7 @@ BEGIN {
|
|||
if (match($0,/>/)) {
|
||||
print substr($0,RSTART+1)
|
||||
}
|
||||
}' $menu_file >> $tmpfile
|
||||
}' "$menu_file" >> $tmpfile
|
||||
fi
|
||||
done
|
||||
orig_directory_files="$directory_files"
|
||||
|
|
476
comp/src/gb.desktop/xdg-utils/xdg-email
Normal file → Executable file
476
comp/src/gb.desktop/xdg-utils/xdg-email
Normal file → Executable file
|
@ -39,95 +39,111 @@ manualpage()
|
|||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-email - command line tool for sending mail using the user's preferred
|
||||
e-mail composer
|
||||
xdg-email - command line tool for sending mail using the user's
|
||||
preferred e-mail composer
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-email [--utf8] [--cc address] [--bcc address] [--subject text] [--body text
|
||||
] [--attach file] [ mailto-uri | address(es) ]
|
||||
xdg-email [--utf8] [--cc address] [--bcc address] [--subject
|
||||
text] [--body text] [--attach file] [ mailto-uri | address(es)
|
||||
]
|
||||
|
||||
xdg-email { --help | --manual | --version }
|
||||
xdg-email { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
xdg-email opens the user's preferred e-mail composer in order to send a mail to
|
||||
address(es) or mailto-uri. RFC2368 defines mailto: URIs. xdg-email limits
|
||||
support to, cc, subject and body fields in mailto-uri, all other fields are
|
||||
silently ignored. address(es) must follow the syntax of RFC822. Multiple
|
||||
addresses may be provided as separate arguments.
|
||||
xdg-email opens the user's preferred e-mail composer in order
|
||||
to send a mail to address(es) or mailto-uri. RFC2368 defines
|
||||
mailto: URIs. xdg-email limits support to, cc, subject and body
|
||||
fields in mailto-uri, all other fields are silently ignored.
|
||||
address(es) must follow the syntax of RFC822. Multiple
|
||||
addresses may be provided as separate arguments.
|
||||
|
||||
All information provided on the command line is used to prefill corresponding
|
||||
fields in the user's e-mail composer. The user will have the opportunity to
|
||||
change any of this information before actually sending the e-mail.
|
||||
All information provided on the command line is used to prefill
|
||||
corresponding fields in the user's e-mail composer. The user
|
||||
will have the opportunity to change any of this information
|
||||
before actually sending the e-mail.
|
||||
|
||||
xdg-email is for use inside a desktop session only. It is not recommended to
|
||||
use xdg-email as root.
|
||||
|
||||
See http://portland.freedesktop.org/EmailConfig for information on how the user
|
||||
can change the e-mail composer that is used.
|
||||
xdg-email is for use inside a desktop session only. It is not
|
||||
recommended to use xdg-email as root.
|
||||
|
||||
Options
|
||||
|
||||
--utf8
|
||||
Indicates that all command line options that follow are in utf8. Without
|
||||
this option, command line options are expected to be encoded according to
|
||||
locale. If the locale already specifies utf8 this option has no effect.
|
||||
This option does not affect mailto URIs that are passed on the command
|
||||
line.
|
||||
--cc address
|
||||
Specify a recipient to be copied on the e-mail.
|
||||
--bcc address
|
||||
Specify a recipient to be blindly copied on the e-mail.
|
||||
--subject text
|
||||
Specify a subject for the e-mail.
|
||||
--body text
|
||||
Specify a body for the e-mail. Since the user will be able to make changes
|
||||
before actually sending the e-mail, this can be used to provide the user
|
||||
with a template for the e-mail. text may contain linebreaks.
|
||||
--attach file
|
||||
--utf8
|
||||
Indicates that all command line options that follow are
|
||||
in utf8. Without this option, command line options are
|
||||
expected to be encoded according to locale. If the
|
||||
locale already specifies utf8 this option has no effect.
|
||||
This option does not affect mailto URIs that are passed
|
||||
on the command line.
|
||||
|
||||
Specify an attachment for the e-mail. file must point to an existing file.
|
||||
--cc address
|
||||
Specify a recipient to be copied on the e-mail.
|
||||
|
||||
Some e-mail applications require the file to remain present after xdg-email
|
||||
returns.
|
||||
--bcc address
|
||||
Specify a recipient to be blindly copied on the e-mail.
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
--manual
|
||||
Show this manualpage.
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
--subject text
|
||||
Specify a subject for the e-mail.
|
||||
|
||||
--body text
|
||||
Specify a body for the e-mail. Since the user will be
|
||||
able to make changes before actually sending the e-mail,
|
||||
this can be used to provide the user with a template for
|
||||
the e-mail. text may contain linebreaks.
|
||||
|
||||
--attach file
|
||||
Specify an attachment for the e-mail. file must point to
|
||||
an existing file.
|
||||
|
||||
Some e-mail applications require the file to remain
|
||||
present after xdg-email returns.
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
|
||||
--manual
|
||||
Show this manual page.
|
||||
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Environment Variables
|
||||
|
||||
xdg-email honours the following environment variables:
|
||||
xdg-email honours the following environment variables:
|
||||
|
||||
XDG_UTILS_DEBUG_LEVEL
|
||||
Setting this environment variable to a non-zero numerical value makes
|
||||
xdg-email do more verbose reporting on stderr. Setting a higher value
|
||||
increases the verbosity.
|
||||
XDG_UTILS_DEBUG_LEVEL
|
||||
Setting this environment variable to a non-zero
|
||||
numerical value makes xdg-email do more verbose
|
||||
reporting on stderr. Setting a higher value increases
|
||||
the verbosity.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
An exit code of 0 indicates success while a non-zero exit code
|
||||
indicates failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
2
|
||||
One of the files passed on the command line did not exist.
|
||||
3
|
||||
A required tool could not be found.
|
||||
4
|
||||
The action failed.
|
||||
5
|
||||
No permission to read one of the files passed on the command line.
|
||||
1
|
||||
Error in command line syntax.
|
||||
|
||||
Configuration
|
||||
2
|
||||
One of the files passed on the command line did not
|
||||
exist.
|
||||
|
||||
Visit http://portland.freedesktop.org/EmailConfig for information how to
|
||||
configure xdg-email to use the email client of your choice.
|
||||
3
|
||||
A required tool could not be found.
|
||||
|
||||
4
|
||||
The action failed.
|
||||
|
||||
5
|
||||
No permission to read one of the files passed on the
|
||||
command line.
|
||||
|
||||
See Also
|
||||
|
||||
xdg-open(1), xdg-mime(1), MIME applications associations
|
||||
specification, RFC 6068 - The 'mailto' URI Scheme
|
||||
|
||||
Examples
|
||||
|
||||
|
@ -139,23 +155,24 @@ xdg-email --attach /tmp/logo.png \
|
|||
'jwhite@example.com'
|
||||
|
||||
xdg-email --subject 'Your password is about to expire' \
|
||||
'jwhite@example.com' 'bastian@example.com' 'whipple@example.com'
|
||||
|
||||
'jwhite@example.com' 'bastian@example.com' 'whipple@example.co
|
||||
m'
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-email - command line tool for sending mail using the user's preferred
|
||||
e-mail composer
|
||||
xdg-email - command line tool for sending mail using the user's
|
||||
preferred e-mail composer
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-email [--utf8] [--cc address] [--bcc address] [--subject text] [--body text
|
||||
] [--attach file] [ mailto-uri | address(es) ]
|
||||
xdg-email [--utf8] [--cc address] [--bcc address] [--subject
|
||||
text] [--body text] [--attach file] [ mailto-uri | address(es)
|
||||
]
|
||||
|
||||
xdg-email { --help | --manual | --version }
|
||||
xdg-email { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
@ -174,6 +191,64 @@ DEBUG()
|
|||
echo "$@" >&2
|
||||
}
|
||||
|
||||
# This handles backslashes but not quote marks.
|
||||
first_word()
|
||||
{
|
||||
read first rest
|
||||
echo "$first"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a binary to a .desktop file
|
||||
binary_to_desktop_file()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
binary="`which "$1"`"
|
||||
binary="`readlink -f "$binary"`"
|
||||
base="`basename "$binary"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] || continue
|
||||
[ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
|
||||
for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
|
||||
[ -r "$file" ] || continue
|
||||
# Check to make sure it's worth the processing.
|
||||
grep -q "^Exec.*$base" "$file" || continue
|
||||
# Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
|
||||
grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
if [ x"`readlink -f "$command"`" = x"$binary" ]; then
|
||||
# Fix any double slashes that got added path composition
|
||||
echo "$file" | sed -e 's,//*,/,g'
|
||||
return
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a .desktop file to a binary
|
||||
## FIXME: handle vendor dir case
|
||||
desktop_file_to_binary()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
desktop="`basename "$1"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] && [ -d "$dir/applications" ] || continue
|
||||
file="$dir/applications/$desktop"
|
||||
[ -r "$file" ] || continue
|
||||
# Remove any arguments (%F, %f, %U, %u, etc.).
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
readlink -f "$command"
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
|
@ -282,7 +357,7 @@ check_vendor_prefix()
|
|||
[ -n "$file_label" ] || file_label="filename"
|
||||
file=`basename "$1"`
|
||||
case "$file" in
|
||||
[a-zA-Z]*-*)
|
||||
[[:alpha:]]*-*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
@ -304,7 +379,7 @@ check_output_file()
|
|||
fi
|
||||
else
|
||||
DIR=`dirname "$1"`
|
||||
if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
|
||||
if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
|
||||
exit_failure_file_permission_write "no permission to create file '$1'"
|
||||
fi
|
||||
fi
|
||||
|
@ -332,7 +407,7 @@ check_common_commands()
|
|||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-email 1.1.0 rc1"
|
||||
echo "xdg-email 1.1.0 rc3"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
|
@ -356,12 +431,86 @@ fi
|
|||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
|
||||
else DE=""
|
||||
# see https://bugs.freedesktop.org/show_bug.cgi?id=34164
|
||||
unset GREP_OPTIONS
|
||||
|
||||
if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
|
||||
case "${XDG_CURRENT_DESKTOP}" in
|
||||
# only recently added to menu-spec, pre-spec X- still in use
|
||||
Cinnamon|X-Cinnamon)
|
||||
DE=cinnamon;
|
||||
;;
|
||||
ENLIGHTENMENT)
|
||||
DE=enlightenment;
|
||||
;;
|
||||
# GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
|
||||
GNOME*)
|
||||
DE=gnome;
|
||||
;;
|
||||
KDE)
|
||||
DE=kde;
|
||||
;;
|
||||
LXDE)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
XFCE)
|
||||
DE=xfce
|
||||
;;
|
||||
X-Generic)
|
||||
DE=generic
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# classic fallbacks
|
||||
if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
|
||||
elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to checking $DESKTOP_SESSION
|
||||
case "$DESKTOP_SESSION" in
|
||||
gnome)
|
||||
DE=gnome;
|
||||
;;
|
||||
LXDE|Lubuntu)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
xfce|xfce4|'Xfce Session')
|
||||
DE=xfce;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to uname output for other platforms
|
||||
case "$(uname 2>/dev/null)" in
|
||||
CYGWIN*)
|
||||
DE=cygwin;
|
||||
;;
|
||||
Darwin)
|
||||
DE=darwin;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"gnome" ]; then
|
||||
# gnome-default-applications-properties is only available in GNOME 2.x
|
||||
# but not in GNOME 3.x
|
||||
which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -372,7 +521,6 @@ detectDE()
|
|||
|
||||
kfmclient_fix_exit_code()
|
||||
{
|
||||
[ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
|
||||
version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
|
||||
major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
|
||||
minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
|
||||
|
@ -396,12 +544,12 @@ run_thunderbird()
|
|||
fi
|
||||
|
||||
MAILTO=$(echo "$MAILTO" | sed 's/&/\n/g')
|
||||
TO=$(echo "$MAILTO" | grep '^to=' | sed 's/^to=//' | awk '{ printf "%s,",$0 }')
|
||||
CC=$(echo "$MAILTO" | grep '^cc=' | sed 's/^cc=//' | awk '{ printf "%s,",$0 }')
|
||||
BCC=$(echo "$MAILTO" | grep '^bcc=' | sed 's/^bcc=//' | awk '{ printf "%s,",$0 }')
|
||||
TO=$(/bin/echo -e $(echo "$MAILTO" | grep '^to=' | sed 's/^to=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }'))
|
||||
CC=$(/bin/echo -e $(echo "$MAILTO" | grep '^cc=' | sed 's/^cc=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }'))
|
||||
BCC=$(/bin/echo -e $(echo "$MAILTO" | grep '^bcc=' | sed 's/^bcc=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }'))
|
||||
SUBJECT=$(echo "$MAILTO" | grep '^subject=' | tail -n 1)
|
||||
BODY=$(echo "$MAILTO" | grep '^body=' | tail -n 1)
|
||||
ATTACH=$(echo "$MAILTO" | sed 's/^attach=/\n\nfile:\/\//g' | awk '/^file:/ { printf "%s,",$0 }' | sed 's/,$//')
|
||||
ATTACH=$(/bin/echo -e $(echo "$MAILTO" | grep '^attach=' | sed 's/^attach=//;s/%\(..\)/\\x\1/g' | awk '{ printf "%s,",$0 }' | sed 's/,$//'))
|
||||
|
||||
if [ -z "$TO" ] ; then
|
||||
NEWMAILTO=
|
||||
|
@ -437,34 +585,73 @@ run_thunderbird()
|
|||
|
||||
open_kde()
|
||||
{
|
||||
local client kde_email_profile_name
|
||||
kde_email_profile_name=`kreadconfig --file emaildefaults --group Defaults --key Profile`
|
||||
client=`kreadconfig --file emaildefaults --group PROFILE_"$kde_email_profile_name" --key EmailClient | cut -d ' ' -f 1`
|
||||
echo $client | grep thunderbird > /dev/null 2>&1
|
||||
if [ -n "$KDE_SESSION_VERSION" ] && [ "$KDE_SESSION_VERSION" -ge 5 ]; then
|
||||
local kreadconfig=kreadconfig$KDE_SESSION_VERSION
|
||||
else
|
||||
local kreadconfig=kreadconfig
|
||||
fi
|
||||
|
||||
if which $kreadconfig >/dev/null 2>&1; then
|
||||
local profile=$($kreadconfig --file emaildefaults \
|
||||
--group Defaults --key Profile)
|
||||
if [ -n "$profile" ]; then
|
||||
local client=$($kreadconfig --file emaildefaults \
|
||||
--group "PROFILE_$profile" \
|
||||
--key EmailClient \
|
||||
| cut -d ' ' -f 1)
|
||||
|
||||
if echo "$client" | grep -Eq 'thunderbird|icedove'; then
|
||||
run_thunderbird "$client" "$1"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
local command
|
||||
case "$KDE_SESSION_VERSION" in
|
||||
'') command=kmailservice ;;
|
||||
4) command=kde-open ;;
|
||||
*) command=kde-open$KDE_SESSION_VERSION ;;
|
||||
esac
|
||||
|
||||
if which $command >/dev/null 2>&1; then
|
||||
DEBUG 1 "Running $command \"$1\""
|
||||
if [ "$KDE_SESSION_VERSION" = 3 ]; then
|
||||
# KDE3 uses locale's encoding when decoding the URI,
|
||||
# so set it to UTF-8
|
||||
LC_ALL=C.UTF-8 $command "$1"
|
||||
else
|
||||
$command "$1"
|
||||
fi
|
||||
else
|
||||
DEBUG 1 "$command missing; trying generic mode instead."
|
||||
open_generic "$1"
|
||||
fi
|
||||
|
||||
if [ $? = 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
}
|
||||
|
||||
open_gnome3()
|
||||
{
|
||||
local client
|
||||
local desktop
|
||||
desktop=`xdg-mime query default "x-scheme-handler/mailto"`
|
||||
client=`desktop_file_to_binary "$desktop"`
|
||||
echo $client | grep -E 'thunderbird|icedove' > /dev/null 2>&1
|
||||
if [ $? -eq 0 ] ; then
|
||||
run_thunderbird "$client" "$1"
|
||||
fi
|
||||
|
||||
if [ -f /etc/SuSE-release ] ; then
|
||||
# Workaround for SUSE 10.0
|
||||
[ -z "$client" ] && client="kmail"
|
||||
if ! which "$client" > /dev/null 2> /dev/null; then
|
||||
DEBUG 3 "KDE has $client configured as email client which isn't installed"
|
||||
if which gnome-open > /dev/null 2> /dev/null && which evolution > /dev/null 2> /dev/null; then
|
||||
DEBUG 3 "Try gnome-open instead"
|
||||
open_gnome "$1"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
DEBUG 1 "Running kmailservice \"$1\""
|
||||
if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
|
||||
KMAILSERVICE=`kde4-config --locate kmailservice --path exe 2>/dev/null`
|
||||
if gvfs-open --help 2>/dev/null 1>&2; then
|
||||
DEBUG 1 "Running gvfs-open \"$1\""
|
||||
gvfs-open "$1"
|
||||
else
|
||||
KMAILSERVICE=`which kmailservice 2>/dev/null`
|
||||
DEBUG 1 "Running gnome-open \"$1\""
|
||||
gnome-open "$1"
|
||||
fi
|
||||
# KDE uses locale's encoding when decoding the URI, so set it to UTF-8
|
||||
LC_ALL=C.UTF-8 $KMAILSERVICE "$1"
|
||||
kfmclient_fix_exit_code $?
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
|
@ -477,7 +664,7 @@ open_gnome()
|
|||
{
|
||||
local client
|
||||
client=`gconftool-2 --get /desktop/gnome/url-handlers/mailto/command | cut -d ' ' -f 1` || ""
|
||||
echo $client | grep thunderbird > /dev/null 2>&1
|
||||
echo $client | grep -E 'thunderbird|icedove' > /dev/null 2>&1
|
||||
if [ $? -eq 0 ] ; then
|
||||
run_thunderbird "$client" "$1"
|
||||
fi
|
||||
|
@ -510,8 +697,42 @@ open_xfce()
|
|||
fi
|
||||
}
|
||||
|
||||
open_envvar()
|
||||
{
|
||||
local OLDIFS="$IFS"
|
||||
IFS=:
|
||||
for i in $MAILER; do
|
||||
IFS="$OLDIFS"
|
||||
|
||||
eval "$i" '"$1"'
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
fi
|
||||
done
|
||||
|
||||
exit_failure_operation_failed
|
||||
}
|
||||
|
||||
open_generic()
|
||||
{
|
||||
local client
|
||||
local desktop
|
||||
desktop=`xdg-mime query default "x-scheme-handler/mailto"`
|
||||
client=`desktop_file_to_binary "$desktop"`
|
||||
echo $client | grep -E 'thunderbird|icedove' > /dev/null 2>&1
|
||||
if [ $? -eq 0 ] ; then
|
||||
run_thunderbird "$client" "$1"
|
||||
fi
|
||||
|
||||
xdg-open "$1"
|
||||
local ret=$?
|
||||
|
||||
# 3 means exit_failure_operation_impossible
|
||||
if [ $ret != 3 ]; then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
IFS=":"
|
||||
for browser in $BROWSER; do
|
||||
if [ x"$browser" != x"" ]; then
|
||||
|
@ -534,7 +755,15 @@ open_generic()
|
|||
|
||||
url_encode()
|
||||
{
|
||||
result=$(echo "$1" | $utf8 | awk '
|
||||
# The shell needs the default internal field separator
|
||||
# otherwise it would search for $utf8 as a command in whole.
|
||||
IFS=" "
|
||||
str=$(echo "$1" | $utf8)
|
||||
local ORIG_LANG="$LANG"
|
||||
local ORIG_LC_ALL="$LC_ALL"
|
||||
LANG=C
|
||||
LC_ALL=C
|
||||
result=$(echo "$str" | awk '
|
||||
BEGIN {
|
||||
for ( i=1; i<=255; ++i ) ord [ sprintf ("%c", i) "" ] = i + 0
|
||||
e = ""
|
||||
|
@ -548,9 +777,7 @@ result=$(echo "$1" | $utf8 | awk '
|
|||
c = substr ($0, i, 1)
|
||||
if ( ord [c] > 127 ) {
|
||||
e = e "%" sprintf("%02X", ord [c])
|
||||
} else if ( ord[c] == 45 ) {
|
||||
e = e c
|
||||
} else if ( c ~ /[@a-zA-Z0-9.\\\/]/ ) {
|
||||
} else if ( c ~ /[@a-zA-Z0-9.\-\\\/]/ ) {
|
||||
e = e c
|
||||
} else {
|
||||
e = e "%" sprintf("%02X", ord [c])
|
||||
|
@ -561,6 +788,8 @@ result=$(echo "$1" | $utf8 | awk '
|
|||
print e
|
||||
}
|
||||
')
|
||||
LANG="$ORIG_LANG"
|
||||
LC_ALL="$ORIG_LC_ALL"
|
||||
}
|
||||
|
||||
options=
|
||||
|
@ -626,7 +855,7 @@ while [ $# -gt 0 ] ; do
|
|||
fi
|
||||
check_input_file "$1"
|
||||
file=`readlink -f "$1"` # Normalize path
|
||||
if [ -z "$file" -o ! -f "$file" ] ; then
|
||||
if [ -z "$file" ] || [ ! -f "$file" ] ; then
|
||||
exit_failure_file_missing "file '$1' does not exist"
|
||||
fi
|
||||
|
||||
|
@ -698,15 +927,23 @@ if [ x"$DE" = x"" ]; then
|
|||
DE=generic
|
||||
fi
|
||||
|
||||
if [ x"$MAILER" != x"" ]; then
|
||||
DE=envvar
|
||||
fi
|
||||
|
||||
# if BROWSER variable is not set, check some well known browsers instead
|
||||
if [ x"$BROWSER" = x"" ]; then
|
||||
BROWSER=links2:links:lynx:w3m
|
||||
BROWSER=www-browser:links2:elinks:links:lynx:w3m
|
||||
if [ -n "$DISPLAY" ]; then
|
||||
BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
|
||||
BROWSER=x-www-browser:firefox:iceweasel:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$DE" in
|
||||
envvar)
|
||||
open_envvar "${mailto}"
|
||||
;;
|
||||
|
||||
kde)
|
||||
open_kde "${mailto}"
|
||||
;;
|
||||
|
@ -715,16 +952,15 @@ case "$DE" in
|
|||
open_gnome "${mailto}"
|
||||
;;
|
||||
|
||||
# BB 01Nov13: Fix to stop default web browser being run
|
||||
lxde)
|
||||
open_gnome "${mailto}"
|
||||
gnome3|cinnamon|lxde|mate)
|
||||
open_gnome3 "${mailto}"
|
||||
;;
|
||||
|
||||
|
||||
xfce)
|
||||
open_xfce "${mailto}"
|
||||
;;
|
||||
|
||||
generic|lxde)
|
||||
generic)
|
||||
open_generic "${mailto}"
|
||||
;;
|
||||
|
||||
|
|
|
@ -1,603 +0,0 @@
|
|||
#!/bin/sh
|
||||
#---------------------------------------------
|
||||
# xdg-file-dialog
|
||||
#
|
||||
# Utility script to file selection dialogs
|
||||
# on XDG compliant systems.
|
||||
#
|
||||
# Refer to the usage() function below for usage.
|
||||
#
|
||||
# Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
|
||||
#
|
||||
# LICENSE:
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the "Software"),
|
||||
# to deal in the Software without restriction, including without limitation
|
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
# and/or sell copies of the Software, and to permit persons to whom the
|
||||
# Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included
|
||||
# in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
# OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
#---------------------------------------------
|
||||
|
||||
manualpage()
|
||||
{
|
||||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-file-dialog -- command line tool for providing file and directory
|
||||
selection dialogs
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-file-dialog openfilename [--title TITLE] [FILENAME]
|
||||
|
||||
xdg-file-dialog openfilenamelist [--title TITLE] [FILENAME]
|
||||
|
||||
xdg-file-dialog savefilename [--title TITLE] [FILENAME]
|
||||
|
||||
xdg-file-dialog directory [--title TITLE] [DIRNAME]
|
||||
|
||||
xdg-file-dialog { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
The xdg-file-dialog program can be used to let the native file selection
|
||||
dialog handle file and directory input.
|
||||
|
||||
xdg-file-dialog is for use inside a desktop session only. It is not
|
||||
recommended to use xdg-file-dialog as root.
|
||||
|
||||
Commands
|
||||
|
||||
openfilename
|
||||
Returns the filename with path for a file to read from. FILENAME
|
||||
can optionally be used to specify path and filename of a
|
||||
preselection.
|
||||
|
||||
openfilenamelist
|
||||
Returns one or more filenames with path for files to read from,
|
||||
each on a new line. FILENAME can optionally be used to specify
|
||||
path and filename of a preselection.
|
||||
|
||||
savefilename
|
||||
Returns the filename with path for file to write to. FILENAME can
|
||||
optionally be used to specify path and filename of a preselection.
|
||||
|
||||
directory
|
||||
Returns the path for an exsiting directory. DIRNAME can optionally
|
||||
be used to specify a path of a preselection.
|
||||
|
||||
Options
|
||||
|
||||
--title TITLE
|
||||
Sets the dialog's title (caption) to the specified text.
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
|
||||
--manual
|
||||
Show this manualpage.
|
||||
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
|
||||
2
|
||||
One of the files passed on the command line did not exist.
|
||||
|
||||
3
|
||||
A required tool could not be found.
|
||||
|
||||
4
|
||||
The action failed.
|
||||
|
||||
Examples
|
||||
|
||||
xdg-file-dialog savefilename /tmp/foobar.png
|
||||
|
||||
Asks for a save file name starting in directory /tmp and suggesting
|
||||
foobar.png as the filename
|
||||
|
||||
xdg-file-dialog directory --title "Select a target folder" /tmp
|
||||
|
||||
Asks for a directory name starting in directory /tmp using the text
|
||||
"Select a target folder" as the dialog's title/caption.
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-file-dialog -- command line tool for providing file and directory
|
||||
selection dialogs
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-file-dialog openfilename [--title TITLE] [FILENAME]
|
||||
|
||||
xdg-file-dialog openfilenamelist [--title TITLE] [FILENAME]
|
||||
|
||||
xdg-file-dialog savefilename [--title TITLE] [FILENAME]
|
||||
|
||||
xdg-file-dialog directory [--title TITLE] [DIRNAME]
|
||||
|
||||
xdg-file-dialog { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
||||
#@xdg-utils-common@
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Common utility functions included in all XDG wrapper scripts
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
exit_success()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "$@"
|
||||
echo
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------
|
||||
# Exit script on malformed arguments, not enough arguments
|
||||
# or missing required option.
|
||||
# prints usage information
|
||||
|
||||
exit_failure_syntax()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-file-dialog: $@" >&2
|
||||
echo "Try 'xdg-file-dialog --help' for more information." >&2
|
||||
else
|
||||
usage
|
||||
echo "Use 'man xdg-file-dialog' or 'xdg-file-dialog --manual' for additional info."
|
||||
fi
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on missing file specified on command line
|
||||
|
||||
exit_failure_file_missing()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-file-dialog: $@" >&2
|
||||
fi
|
||||
|
||||
exit 2
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on failure to locate necessary tool applications
|
||||
|
||||
exit_failure_operation_impossible()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-file-dialog: $@" >&2
|
||||
fi
|
||||
|
||||
exit 3
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on failure returned by a tool application
|
||||
|
||||
exit_failure_operation_failed()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-file-dialog: $@" >&2
|
||||
fi
|
||||
|
||||
exit 4
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------
|
||||
# Checks for shared commands, e.g. --help
|
||||
|
||||
check_common_commands()
|
||||
{
|
||||
while [ $# -gt 0 ] ; do
|
||||
parm=$1
|
||||
shift
|
||||
|
||||
case $parm in
|
||||
--help)
|
||||
usage
|
||||
echo "Use 'man xdg-file-dialog' or 'xdg-file-dialog --manual' for additional info."
|
||||
exit_success
|
||||
;;
|
||||
|
||||
--manual)
|
||||
manualpage
|
||||
exit_success
|
||||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-file-dialog 1.0beta1"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
check_common_commands "$@"
|
||||
|
||||
#--------------------------------------
|
||||
# Checks for known desktop environments
|
||||
# set variable DE to the desktop environments name, lowercase
|
||||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
fi
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
open_kde()
|
||||
{
|
||||
DIALOG=`which kdialog`
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
$DIALOG --title "$TITLE" --getopenfilename "$1" ""
|
||||
else
|
||||
$DIALOG --getopenfilename "$1" ""
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible
|
||||
fi
|
||||
}
|
||||
|
||||
open_zenity()
|
||||
{
|
||||
DIALOG=`which zenity`
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ x"$1" != x"" ]; then
|
||||
cd `dirname "$1"` 2>/dev/null
|
||||
FILENAME=`basename "$1"`
|
||||
if [ x"$FILENAME" != x"" ]; then
|
||||
FILENAME="--filename=""$FILENAME"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$FILENAME" != x"" ]; then
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
$DIALOG --title "$TITLE" --file-selection "$FILENAME"
|
||||
else
|
||||
$DIALOG --file-selection "$FILENAME"
|
||||
fi
|
||||
else
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
$DIALOG --title "$TITLE" --file-selection
|
||||
else
|
||||
$DIALOG --file-selection
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible
|
||||
fi
|
||||
}
|
||||
|
||||
open_multi_kde()
|
||||
{
|
||||
DIALOG=`which kdialog`
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
$DIALOG --title "$TITLE" --multiple --separate-output \
|
||||
--getopenfilename "$1" ""
|
||||
else
|
||||
$DIALOG --multiple --separate-output --getopenfilename "$1" ""
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible
|
||||
fi
|
||||
}
|
||||
|
||||
open_multi_zenity()
|
||||
{
|
||||
DIALOG=`which zenity`
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ x"$1" != x"" ]; then
|
||||
cd `dirname "$1"` 2>/dev/null
|
||||
FILENAME=`basename "$1"`
|
||||
if [ x"$FILENAME" != x"" ]; then
|
||||
FILENAME="--filename=""$FILENAME"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$FILENAME" != x"" ]; then
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
LIST=`$DIALOG --title "$TITLE" --multiple --file-selection "$FILENAME"`
|
||||
else
|
||||
LIST=`$DIALOG --multiple --file-selection "$FILENAME"`
|
||||
fi
|
||||
else
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
LIST=`$DIALOG --title "$TITLE" --multiple --file-selection`
|
||||
else
|
||||
LIST=`$DIALOG --multiple --file-selection`
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "$LIST" | sed s#'|'#\\n#g
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible
|
||||
fi
|
||||
}
|
||||
|
||||
save_kde()
|
||||
{
|
||||
DIALOG=`which kdialog`
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
$DIALOG --title "$TITLE" --getsavefilename "$1" ""
|
||||
else
|
||||
$DIALOG --getsavefilename "$1" ""
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible
|
||||
fi
|
||||
}
|
||||
|
||||
save_zenity()
|
||||
{
|
||||
DIALOG=`which zenity`
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ x"$1" != x"" ]; then
|
||||
cd `dirname "$1"` 2>/dev/null
|
||||
FILENAME=`basename "$1"`
|
||||
if [ x"$FILENAME" != x"" ]; then
|
||||
FILENAME="--filename=""$FILENAME"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$FILENAME" != x"" ]; then
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
$DIALOG --title "$TITLE" --save --file-selection "$FILENAME"
|
||||
else
|
||||
$DIALOG --save --file-selection "$FILENAME"
|
||||
fi
|
||||
else
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
$DIALOG --title "$TITLE" --save --file-selection
|
||||
else
|
||||
$DIALOG --save --file-selection
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible
|
||||
fi
|
||||
}
|
||||
|
||||
directory_kde()
|
||||
{
|
||||
DIALOG=`which kdialog`
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
$DIALOG --title "$TITLE" --getexistingdirectory "$1" ""
|
||||
else
|
||||
$DIALOG --getexistingdirectory "$1" ""
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible
|
||||
fi
|
||||
}
|
||||
|
||||
directory_zenity()
|
||||
{
|
||||
DIALOG=`which zenity`
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ x"$1" != x"" ]; then
|
||||
cd "$1" 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ x"$TITLE" != x"" ]; then
|
||||
$DIALOG --title "$TITLE" --directory --file-selection
|
||||
else
|
||||
$DIALOG --directory --file-selection
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible
|
||||
fi
|
||||
}
|
||||
|
||||
[ x"$1" != x"" ] || exit_failure_syntax
|
||||
|
||||
TITLE=
|
||||
action=
|
||||
filename=
|
||||
|
||||
case $1 in
|
||||
openfilename)
|
||||
action=openfilename
|
||||
;;
|
||||
|
||||
openfilenamelist)
|
||||
action=openfilenamelist
|
||||
;;
|
||||
|
||||
savefilename)
|
||||
action=savefilename
|
||||
;;
|
||||
|
||||
directory)
|
||||
action=directory
|
||||
;;
|
||||
|
||||
*)
|
||||
exit_failure_syntax "unknown command '$1'"
|
||||
;;
|
||||
esac
|
||||
|
||||
shift
|
||||
|
||||
while [ $# -gt 0 ] ; do
|
||||
parm=$1
|
||||
shift
|
||||
|
||||
case $parm in
|
||||
--title)
|
||||
if [ -z "$1" ] ; then
|
||||
exit_failure_syntax "TITLE argument missing for --title"
|
||||
fi
|
||||
TITLE="$1"
|
||||
shift
|
||||
;;
|
||||
|
||||
-*)
|
||||
exit_failure_syntax "unexpected option '$parm'"
|
||||
;;
|
||||
|
||||
*)
|
||||
if [ -n "$filename" ] ; then
|
||||
exit_failure_syntax "unexpected argument '$parm'"
|
||||
fi
|
||||
filename="$parm"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Shouldn't happen
|
||||
if [ -z "$action" ] ; then
|
||||
exit_failure_syntax "command argument missing"
|
||||
fi
|
||||
|
||||
detectDE
|
||||
|
||||
if [ "$action" = "openfilename" ]; then
|
||||
case "$DE" in
|
||||
kde)
|
||||
open_kde "$filename"
|
||||
;;
|
||||
|
||||
gnome|xfce)
|
||||
open_zenity "$filename"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit_failure_operation_impossible "no method available for opening a filename dialog"
|
||||
;;
|
||||
esac
|
||||
elif [ "$action" = "openfilenamelist" ]; then
|
||||
case "$DE" in
|
||||
kde)
|
||||
open_multi_kde "$filename"
|
||||
;;
|
||||
|
||||
gnome|xfce)
|
||||
open_multi_zenity "$filename"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit_failure_operation_impossible "no method available for opening a filename dialog"
|
||||
;;
|
||||
esac
|
||||
elif [ "$action" = "savefilename" ]; then
|
||||
case "$DE" in
|
||||
kde)
|
||||
save_kde "$filename"
|
||||
;;
|
||||
|
||||
gnome|xfce)
|
||||
save_zenity "$filename"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit_failure_operation_impossible "no method available for opening a filename dialog"
|
||||
;;
|
||||
esac
|
||||
elif [ "$action" = "directory" ]; then
|
||||
case "$DE" in
|
||||
kde)
|
||||
directory_kde "$filename"
|
||||
;;
|
||||
|
||||
gnome|xfce)
|
||||
directory_zenity "$filename"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit_failure_operation_impossible "no method available for opening a directory dialog"
|
||||
;;
|
||||
esac
|
||||
fi
|
438
comp/src/gb.desktop/xdg-utils/xdg-icon-resource
Normal file → Executable file
438
comp/src/gb.desktop/xdg-utils/xdg-icon-resource
Normal file → Executable file
|
@ -38,164 +38,199 @@ manualpage()
|
|||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-icon-resource - command line tool for (un)installing icon resources
|
||||
xdg-icon-resource - command line tool for (un)installing icon
|
||||
resources
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-icon-resource install [--noupdate] [--novendor] [--theme theme] [--context
|
||||
context] [--mode mode] --size size icon-file [icon-name]
|
||||
xdg-icon-resource install [--noupdate] [--novendor] [--theme
|
||||
theme] [--context context] [--mode mode] --size size icon-file
|
||||
[icon-name]
|
||||
|
||||
xdg-icon-resource uninstall [--noupdate] [--theme theme] [--context context]
|
||||
[--mode mode] --size size icon-name
|
||||
xdg-icon-resource uninstall [--noupdate] [--theme theme]
|
||||
[--context context] [--mode mode] --size size icon-name
|
||||
|
||||
xdg-icon-resource forceupdate [--theme theme] [--mode mode]
|
||||
xdg-icon-resource forceupdate [--theme theme] [--mode mode]
|
||||
|
||||
xdg-icon-resource { --help | --manual | --version }
|
||||
xdg-icon-resource { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
The xdg-icon-resource program can be used to install icon resources into the
|
||||
desktop icon system in order to illustrate menu entries, to depict desktop
|
||||
icons or to graphically represent file types.
|
||||
The xdg-icon-resource program can be used to install icon
|
||||
resources into the desktop icon system in order to illustrate
|
||||
menu entries, to depict desktop icons or to graphically
|
||||
represent file types.
|
||||
|
||||
The desktop icon system identifies icons by name. Depending on the required
|
||||
size, the choice of icon theme and the context in which the icon is used, the
|
||||
desktop icon system locates an appropriate icon resource to depict an icon.
|
||||
Icon resources can be XPM files or PNG files.
|
||||
The desktop icon system identifies icons by name. Depending on
|
||||
the required size, the choice of icon theme and the context in
|
||||
which the icon is used, the desktop icon system locates an
|
||||
appropriate icon resource to depict an icon. Icon resources can
|
||||
be XPM files or PNG files.
|
||||
|
||||
The desktop icon system works according to the XDG Icon Theme Specification at
|
||||
http://www.freedesktop.org/Standards/icon-theme-spec
|
||||
The desktop icon system works according to the XDG Icon Theme
|
||||
Specification at
|
||||
http://www.freedesktop.org/wiki/Specifications/icon-theme-spec
|
||||
|
||||
Commands
|
||||
|
||||
install
|
||||
Installs the icon file indicated by icon-file to the desktop icon system
|
||||
under the name icon-name. Icon names do not have an extension. If icon-name
|
||||
is not provided the name is derived from icon-file. The icon file must have
|
||||
.png or .xpm as extension. If a corresponding .icon file exists in the same
|
||||
location as icon-file it will be installed as well.
|
||||
uninstall
|
||||
Removes the icon indicated by icon-name from the desktop icon system. Note
|
||||
that icon names do not have an extension.
|
||||
forceupdate
|
||||
Force an update of the desktop icon system. This is only useful if the last
|
||||
call to xdg-icon-resource included the --noupdate option.
|
||||
install
|
||||
Installs the icon file indicated by icon-file to the
|
||||
desktop icon system under the name icon-name. Icon names
|
||||
do not have an extension. If icon-name is not provided
|
||||
the name is derived from icon-file. The icon file must
|
||||
have .png or .xpm as extension. If a corresponding .icon
|
||||
file exists in the same location as icon-file it will be
|
||||
installed as well.
|
||||
|
||||
uninstall
|
||||
Removes the icon indicated by icon-name from the desktop
|
||||
icon system. Note that icon names do not have an
|
||||
extension.
|
||||
|
||||
forceupdate
|
||||
Force an update of the desktop icon system. This is only
|
||||
useful if the last call to xdg-icon-resource included
|
||||
the --noupdate option.
|
||||
|
||||
Options
|
||||
|
||||
--noupdate
|
||||
Postpone updating the desktop icon system. If multiple icons are added in
|
||||
sequence this flag can be used to indicate that additional changes will
|
||||
follow and that it is not necassery to update the desktop icon system right
|
||||
away.
|
||||
--novendor
|
||||
--noupdate
|
||||
Postpone updating the desktop icon system. If multiple
|
||||
icons are added in sequence this flag can be used to
|
||||
indicate that additional changes will follow and that it
|
||||
is not necessary to update the desktop icon system right
|
||||
away.
|
||||
|
||||
Normally, xdg-icon-resource checks to ensure that an icon file to be
|
||||
installed in the apps context has a proper vendor prefix. This option can
|
||||
be used to disable that check.
|
||||
--novendor
|
||||
Normally, xdg-icon-resource checks to ensure that an
|
||||
icon file to be installed in the apps context has a
|
||||
proper vendor prefix. This option can be used to disable
|
||||
that check.
|
||||
|
||||
A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated
|
||||
with a dash ("-"). Companies and organizations are encouraged to use a word
|
||||
or phrase, preferably the organizations name, for which they hold a
|
||||
trademark as their vendor prefix. The purpose of the vendor prefix is to
|
||||
prevent name conflicts.
|
||||
A vendor prefix consists of alpha characters ([a-zA-Z])
|
||||
and is terminated with a dash ("-"). Companies and
|
||||
organizations are encouraged to use a word or phrase,
|
||||
preferably the organizations name, for which they hold a
|
||||
trademark as their vendor prefix. The purpose of the
|
||||
vendor prefix is to prevent name conflicts.
|
||||
|
||||
--theme theme
|
||||
Installs or removes the icon file as part of theme. If no theme is
|
||||
specified the icons will be installed as part of the default hicolor theme.
|
||||
Applications may install icons under multiple themes but should at least
|
||||
install icons for the default hicolor theme.
|
||||
--context context
|
||||
Specifies the context for the icon. Icons to be used in the application
|
||||
menu and as desktop icon should use apps as context which is the default
|
||||
context. Icons to be used as file icons should use mimetypes as context.
|
||||
Other common contexts are actions, devices, emblems, filesystems and stock.
|
||||
--size size
|
||||
Specifies the size of the icon. All icons must be square. Common sizes for
|
||||
icons in the apps context are: 16, 22, 32, 48, 64 and 128. Common sizes for
|
||||
icons in the mimetypes context are: 16, 22, 32, 48, 64 and 128
|
||||
--mode mode
|
||||
--theme theme
|
||||
Installs or removes the icon file as part of theme. If
|
||||
no theme is specified the icons will be installed as
|
||||
part of the default hicolor theme. Applications may
|
||||
install icons under multiple themes but should at least
|
||||
install icons for the default hicolor theme.
|
||||
|
||||
mode can be user or system. In user mode the file is (un)installed for the
|
||||
current user only. In system mode the file is (un)installed for all users
|
||||
on the system. Usually only root is allowed to install in system mode.
|
||||
--context context
|
||||
Specifies the context for the icon. Icons to be used in
|
||||
the application menu and as desktop icon should use apps
|
||||
as context which is the default context. Icons to be
|
||||
used as file icons should use mimetypes as context.
|
||||
Other common contexts are actions, devices, emblems,
|
||||
filesystems and stock.
|
||||
|
||||
The default is to use system mode when called by root and to use user mode
|
||||
when called by a non-root user.
|
||||
--size size
|
||||
Specifies the size of the icon. All icons must be
|
||||
square. Common sizes for icons in the apps context are:
|
||||
16, 22, 32, 48, 64 and 128. Common sizes for icons in
|
||||
the mimetypes context are: 16, 22, 32, 48, 64 and 128
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
--manual
|
||||
Show this manualpage.
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
--mode mode
|
||||
mode can be user or system. In user mode the file is
|
||||
(un)installed for the current user only. In system mode
|
||||
the file is (un)installed for all users on the system.
|
||||
Usually only root is allowed to install in system mode.
|
||||
|
||||
The default is to use system mode when called by root
|
||||
and to use user mode when called by a non-root user.
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
|
||||
--manual
|
||||
Show this manual page.
|
||||
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Environment Variables
|
||||
|
||||
xdg-icon-resource honours the following environment variables:
|
||||
xdg-icon-resource honours the following environment variables:
|
||||
|
||||
XDG_UTILS_DEBUG_LEVEL
|
||||
Setting this environment variable to a non-zero numerical value makes
|
||||
xdg-icon-resource do more verbose reporting on stderr. Setting a higher
|
||||
value increases the verbosity.
|
||||
XDG_UTILS_INSTALL_MODE
|
||||
This environment variable can be used by the user or administrator to
|
||||
override the installation mode. Valid values are user and system.
|
||||
XDG_UTILS_DEBUG_LEVEL
|
||||
Setting this environment variable to a non-zero
|
||||
numerical value makes xdg-icon-resource do more verbose
|
||||
reporting on stderr. Setting a higher value increases
|
||||
the verbosity.
|
||||
|
||||
XDG_UTILS_INSTALL_MODE
|
||||
This environment variable can be used by the user or
|
||||
administrator to override the installation mode. Valid
|
||||
values are user and system.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
An exit code of 0 indicates success while a non-zero exit code
|
||||
indicates failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
2
|
||||
One of the files passed on the command line did not exist.
|
||||
3
|
||||
A required tool could not be found.
|
||||
4
|
||||
The action failed.
|
||||
5
|
||||
No permission to read one of the files passed on the command line.
|
||||
1
|
||||
Error in command line syntax.
|
||||
|
||||
2
|
||||
One of the files passed on the command line did not
|
||||
exist.
|
||||
|
||||
3
|
||||
A required tool could not be found.
|
||||
|
||||
4
|
||||
The action failed.
|
||||
|
||||
5
|
||||
No permission to read one of the files passed on the
|
||||
command line.
|
||||
|
||||
See Also
|
||||
|
||||
xdg-desktop-icon(1), xdg-desktop-menu(1), xdg-mime(1)
|
||||
xdg-desktop-icon(1), xdg-desktop-menu(1), xdg-mime(1), Icon
|
||||
theme specification
|
||||
|
||||
Examples
|
||||
|
||||
To install an icon resource to depict a launcher for the application myfoobar,
|
||||
the company ShinyThings Inc. can use:
|
||||
|
||||
To install an icon resource to depict a launcher for the
|
||||
application myfoobar, the company ShinyThings Inc. can use:
|
||||
xdg-icon-resource install --size 64 shinythings-myfoobar.png
|
||||
|
||||
To install an icon for a new application/x-foobar file type one can use:
|
||||
|
||||
xdg-icon-resource install --context mimetypes --size 48 ./mime-foobar-48.png application-x-foobar
|
||||
xdg-icon-resource install --context mimetypes --size 64 ./mime-foobar-64.png application-x-foobar
|
||||
|
||||
This will install two icons with the name application-x-foobar but with
|
||||
different sizes.
|
||||
To install an icon for a new application/x-foobar file type one
|
||||
can use:
|
||||
xdg-icon-resource install --context mimetypes --size 48 ./mime-foobar-48
|
||||
.png application-x-foobar
|
||||
xdg-icon-resource install --context mimetypes --size 64 ./mime-foobar-64
|
||||
.png application-x-foobar
|
||||
|
||||
This will install two icons with the name application-x-foobar
|
||||
but with different sizes.
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-icon-resource - command line tool for (un)installing icon resources
|
||||
xdg-icon-resource - command line tool for (un)installing icon
|
||||
resources
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-icon-resource install [--noupdate] [--novendor] [--theme theme] [--context
|
||||
context] [--mode mode] --size size icon-file [icon-name]
|
||||
xdg-icon-resource install [--noupdate] [--novendor] [--theme
|
||||
theme] [--context context] [--mode mode] --size size icon-file
|
||||
[icon-name]
|
||||
|
||||
xdg-icon-resource uninstall [--noupdate] [--theme theme] [--context context]
|
||||
[--mode mode] --size size icon-name
|
||||
xdg-icon-resource uninstall [--noupdate] [--theme theme]
|
||||
[--context context] [--mode mode] --size size icon-name
|
||||
|
||||
xdg-icon-resource forceupdate [--theme theme] [--mode mode]
|
||||
xdg-icon-resource forceupdate [--theme theme] [--mode mode]
|
||||
|
||||
xdg-icon-resource { --help | --manual | --version }
|
||||
xdg-icon-resource { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
@ -214,6 +249,64 @@ DEBUG()
|
|||
echo "$@" >&2
|
||||
}
|
||||
|
||||
# This handles backslashes but not quote marks.
|
||||
first_word()
|
||||
{
|
||||
read first rest
|
||||
echo "$first"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a binary to a .desktop file
|
||||
binary_to_desktop_file()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
binary="`which "$1"`"
|
||||
binary="`readlink -f "$binary"`"
|
||||
base="`basename "$binary"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] || continue
|
||||
[ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
|
||||
for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
|
||||
[ -r "$file" ] || continue
|
||||
# Check to make sure it's worth the processing.
|
||||
grep -q "^Exec.*$base" "$file" || continue
|
||||
# Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
|
||||
grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
if [ x"`readlink -f "$command"`" = x"$binary" ]; then
|
||||
# Fix any double slashes that got added path composition
|
||||
echo "$file" | sed -e 's,//*,/,g'
|
||||
return
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a .desktop file to a binary
|
||||
## FIXME: handle vendor dir case
|
||||
desktop_file_to_binary()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
desktop="`basename "$1"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] && [ -d "$dir/applications" ] || continue
|
||||
file="$dir/applications/$desktop"
|
||||
[ -r "$file" ] || continue
|
||||
# Remove any arguments (%F, %f, %U, %u, etc.).
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
readlink -f "$command"
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
|
@ -322,7 +415,7 @@ check_vendor_prefix()
|
|||
[ -n "$file_label" ] || file_label="filename"
|
||||
file=`basename "$1"`
|
||||
case "$file" in
|
||||
[a-zA-Z]*-*)
|
||||
[[:alpha:]]*-*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
@ -344,7 +437,7 @@ check_output_file()
|
|||
fi
|
||||
else
|
||||
DIR=`dirname "$1"`
|
||||
if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
|
||||
if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
|
||||
exit_failure_file_permission_write "no permission to create file '$1'"
|
||||
fi
|
||||
fi
|
||||
|
@ -372,7 +465,7 @@ check_common_commands()
|
|||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-icon-resource 1.1.0 rc1"
|
||||
echo "xdg-icon-resource 1.1.0 rc3"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
|
@ -396,12 +489,86 @@ fi
|
|||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
|
||||
else DE=""
|
||||
# see https://bugs.freedesktop.org/show_bug.cgi?id=34164
|
||||
unset GREP_OPTIONS
|
||||
|
||||
if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
|
||||
case "${XDG_CURRENT_DESKTOP}" in
|
||||
# only recently added to menu-spec, pre-spec X- still in use
|
||||
Cinnamon|X-Cinnamon)
|
||||
DE=cinnamon;
|
||||
;;
|
||||
ENLIGHTENMENT)
|
||||
DE=enlightenment;
|
||||
;;
|
||||
# GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
|
||||
GNOME*)
|
||||
DE=gnome;
|
||||
;;
|
||||
KDE)
|
||||
DE=kde;
|
||||
;;
|
||||
LXDE)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
XFCE)
|
||||
DE=xfce
|
||||
;;
|
||||
X-Generic)
|
||||
DE=generic
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# classic fallbacks
|
||||
if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
|
||||
elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to checking $DESKTOP_SESSION
|
||||
case "$DESKTOP_SESSION" in
|
||||
gnome)
|
||||
DE=gnome;
|
||||
;;
|
||||
LXDE|Lubuntu)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
xfce|xfce4|'Xfce Session')
|
||||
DE=xfce;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to uname output for other platforms
|
||||
case "$(uname 2>/dev/null)" in
|
||||
CYGWIN*)
|
||||
DE=cygwin;
|
||||
;;
|
||||
Darwin)
|
||||
DE=darwin;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"gnome" ]; then
|
||||
# gnome-default-applications-properties is only available in GNOME 2.x
|
||||
# but not in GNOME 3.x
|
||||
which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -412,7 +579,6 @@ detectDE()
|
|||
|
||||
kfmclient_fix_exit_code()
|
||||
{
|
||||
[ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
|
||||
version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
|
||||
major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
|
||||
minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
|
||||
|
@ -599,7 +765,7 @@ if [ -n "$XDG_UTILS_INSTALL_MODE" ] ; then
|
|||
fi
|
||||
|
||||
if [ -z "$mode" ] ; then
|
||||
if [ `whoami` = "root" ] ; then
|
||||
if [ "`whoami`" = "root" ] ; then
|
||||
mode="system"
|
||||
else
|
||||
mode="user"
|
||||
|
@ -618,13 +784,13 @@ xdg_global_prefix=
|
|||
xdg_system_dirs="$XDG_DATA_DIRS"
|
||||
[ -n "$xdg_system_dirs" ] || xdg_system_dirs="/usr/local/share/:/usr/share/"
|
||||
for x in `echo "$xdg_system_dirs" | sed 's/:/ /g'`; do
|
||||
if [ -w $x/$xdg_dir_name ] ; then
|
||||
if [ -w "$x/$xdg_dir_name" ] ; then
|
||||
xdg_global_prefix="$x/icons"
|
||||
xdg_global_dir="$x/$xdg_dir_name"
|
||||
break
|
||||
fi
|
||||
done
|
||||
[ -w $xdg_global_dir ] || xdg_global_dir=
|
||||
[ -w "$xdg_global_dir" ] || xdg_global_dir=
|
||||
|
||||
dot_icon_dir=
|
||||
dot_base_dir=
|
||||
|
@ -648,8 +814,8 @@ if [ x"$action" = x"forceupdate" ] ; then
|
|||
fi
|
||||
update_icon_database $xdg_base_dir
|
||||
if [ -n "$dot_icon_dir" ] ; then
|
||||
if [ -d "$dot_icon_dir/" -a ! -L "$dot_icon_dir" ] ; then
|
||||
update_icon_database $dot_base_dir
|
||||
if [ -d "$dot_icon_dir/" ] && [ ! -L "$dot_icon_dir" ] ; then
|
||||
update_icon_database "$dot_base_dir"
|
||||
fi
|
||||
fi
|
||||
exit_success
|
||||
|
@ -672,7 +838,7 @@ fi
|
|||
xdg_size_name="${size}x${size}"
|
||||
|
||||
if [ x"$action" = x"install" ] ; then
|
||||
case $icon_file in
|
||||
case "$icon_file" in
|
||||
*.xpm)
|
||||
extension="xpm"
|
||||
;;
|
||||
|
@ -686,7 +852,7 @@ if [ x"$action" = x"install" ] ; then
|
|||
fi
|
||||
|
||||
if [ -n "$icon_name" ] ; then
|
||||
case $icon_name in
|
||||
case "$icon_name" in
|
||||
*.png)
|
||||
exit_failure_syntax "icon name should not include an extension"
|
||||
;;
|
||||
|
@ -730,8 +896,8 @@ need_kde_icon_path()
|
|||
fi
|
||||
done
|
||||
DEBUG 2 "kde_global_prefix: $kde_global_prefix"
|
||||
[ $needed -eq "1" ] && DEBUG 2 "need_kde_icon_path RETURN $needed (not needed)"
|
||||
[ $needed -eq "0" ] && DEBUG 2 "need_kde_icon_path RETURN $needed (needed)"
|
||||
[ $needed -eq 1 ] && DEBUG 2 "need_kde_icon_path RETURN $needed (not needed)"
|
||||
[ $needed -eq 0 ] && DEBUG 2 "need_kde_icon_path RETURN $needed (needed)"
|
||||
return $needed
|
||||
}
|
||||
|
||||
|
@ -775,7 +941,7 @@ fi
|
|||
|
||||
# Start GNOME legacy workaround section
|
||||
need_gnome_mime=
|
||||
[ $context = "mimetypes" ] && need_gnome_mime=true
|
||||
[ "$context" = "mimetypes" ] && need_gnome_mime=true
|
||||
# End GNOME legacy workaround section
|
||||
|
||||
[ -n "$icon_name" ] || icon_name=`basename "$icon_file" | sed 's/\.[a-z][a-z][a-z]$//'`
|
||||
|
@ -788,18 +954,19 @@ icon_icon_file=`echo "$icon_file" | sed 's/\.[a-z][a-z][a-z]$/.icon/'`
|
|||
icon_icon_name="$icon_name.icon"
|
||||
|
||||
DEBUG 1 "$action icon in $xdg_dir"
|
||||
[ $action = "install" -a -f $icon_icon_file ] && DEBUG 1 "install $icon_icon_name meta file in $xdg_dir"
|
||||
[ "$action" = "install" ] && [ -f "$icon_icon_file" ] && DEBUG 1 "install $icon_icon_name meta file in $xdg_dir"
|
||||
[ -n "$kde_dir" ] && DEBUG 1 "$action symlink in $kde_dir (KDE 3.x support)"
|
||||
[ -n "$need_gnome_mime" ] && DEBUG 1 "$action gnome-mime-$icon_name symlink (GNOME 2.x support)"
|
||||
[ $action = "install" -a -n "$dot_icon_dir" ] && DEBUG 1 "$action ~/.icons symlink (GNOME 2.8 support)"
|
||||
[ "$action" = "install" -a -n "$dot_icon_dir" ] && DEBUG 1 "$action ~/.icons symlink (GNOME 2.8 support)"
|
||||
|
||||
case $action in
|
||||
case "$action" in
|
||||
install)
|
||||
save_umask=`umask`
|
||||
umask $my_umask
|
||||
|
||||
for icon_dir in $xdg_dir $dot_icon_dir; do
|
||||
mkdir -p $icon_dir
|
||||
for icon_dir in "$xdg_dir" "$dot_icon_dir"; do
|
||||
[ -z "$icon_dir" ] && continue
|
||||
mkdir -p "$icon_dir"
|
||||
eval 'cp "$icon_file" "$icon_dir/$icon_name.$extension"'$xdg_redirect_output
|
||||
if [ -f "$icon_icon_file" ] ; then
|
||||
eval 'cp "$icon_icon_file" "$icon_dir/$icon_icon_name"'$xdg_redirect_output
|
||||
|
@ -809,7 +976,7 @@ case $action in
|
|||
fi
|
||||
done
|
||||
if [ -n "$kde_dir" ] ; then
|
||||
mkdir -p $kde_dir
|
||||
mkdir -p "$kde_dir"
|
||||
eval 'ln -s "$xdg_dir/$icon_name.$extension" "$kde_dir/$icon_name.$extension"'$xdg_redirect_output
|
||||
fi
|
||||
|
||||
|
@ -817,7 +984,8 @@ case $action in
|
|||
;;
|
||||
|
||||
uninstall)
|
||||
for icon_dir in $xdg_dir $dot_icon_dir; do
|
||||
for icon_dir in "$xdg_dir" "$dot_icon_dir"; do
|
||||
[ -z "$icon_dir" ] && continue
|
||||
rm -f "$icon_dir/$icon_name.xpm" "$icon_dir/$icon_name.png"
|
||||
rm -f "$icon_dir/$icon_icon_name"
|
||||
if [ -n "$need_gnome_mime" ] ; then
|
||||
|
@ -835,8 +1003,8 @@ esac
|
|||
if [ x"$update" = x"yes" ] ; then
|
||||
update_icon_database "$xdg_base_dir"
|
||||
if [ -n "$dot_icon_dir" ] ; then
|
||||
if [ -d "$dot_icon_dir/" -a ! -L "$dot_icon_dir" ] ; then
|
||||
update_icon_database $dot_base_dir
|
||||
if [ -d "$dot_icon_dir/" ] && [ ! -L "$dot_icon_dir" ] ; then
|
||||
update_icon_database "$dot_base_dir"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
|
648
comp/src/gb.desktop/xdg-utils/xdg-mime
Normal file → Executable file
648
comp/src/gb.desktop/xdg-utils/xdg-mime
Normal file → Executable file
|
@ -39,162 +39,187 @@ manualpage()
|
|||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-mime - command line tool for querying information about file type handling
|
||||
and adding descriptions for new file types
|
||||
xdg-mime - command line tool for querying information about
|
||||
file type handling and adding descriptions for new file types
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-mime query { filetype | default } ...
|
||||
xdg-mime query { filetype | default } ...
|
||||
|
||||
xdg-mime default application mimetype(s)
|
||||
xdg-mime default application mimetype(s)
|
||||
|
||||
xdg-mime install [--mode mode] [--novendor] mimetypes-file
|
||||
xdg-mime install [--mode mode] [--novendor] mimetypes-file
|
||||
|
||||
xdg-mime uninstall [--mode mode] mimetypes-file
|
||||
xdg-mime uninstall [--mode mode] mimetypes-file
|
||||
|
||||
xdg-mime { --help | --manual | --version }
|
||||
xdg-mime { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
The xdg-mime program can be used to query information about file types and to
|
||||
add descriptions for new file types.
|
||||
The xdg-mime program can be used to query information about
|
||||
file types and to add descriptions for new file types.
|
||||
|
||||
Commands
|
||||
|
||||
query
|
||||
query
|
||||
Returns information related to file types.
|
||||
|
||||
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 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:
|
||||
|
||||
The following queries are supported:
|
||||
query filetype FILE: 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.
|
||||
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.
|
||||
|
||||
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
|
||||
Ask the desktop environment to make application the
|
||||
default application for opening files of type mimetype.
|
||||
An application can be made the default for several file
|
||||
types by specifying multiple mimetypes.
|
||||
|
||||
default
|
||||
application is the desktop file id of the application
|
||||
and has the form vendor-name.desktop application must
|
||||
already be installed in the desktop menu before it can
|
||||
be made the default handler. The application's desktop
|
||||
file must list support for all the MIME types that it
|
||||
wishes to be the default handler for.
|
||||
|
||||
Ask the desktop environment to make application the default application for
|
||||
opening files of type mimetype. An application can be made the default for
|
||||
several file types by specifying multiple mimetypes.
|
||||
Requests to make an application a default handler may be
|
||||
subject to system policy or approval by the end-user.
|
||||
xdg-mime query can be used to verify whether an
|
||||
application is the actual default handler for a specific
|
||||
file type.
|
||||
|
||||
application is the desktop file id of the application and has the form
|
||||
vendor-name.desktop application must already be installed in the desktop
|
||||
menu before it can be made the default handler. The aplication's desktop
|
||||
file must list support for all the MIME types that it wishes to be the
|
||||
default handler for.
|
||||
The default option is for use inside a desktop session
|
||||
only. It is not recommended to use xdg-mime default as
|
||||
root.
|
||||
|
||||
Requests to make an application a default handler may be subject to system
|
||||
policy or approval by the end-user. xdg-mime query can be used to verify
|
||||
whether an application is the actual default handler for a specific file
|
||||
type.
|
||||
install
|
||||
Adds the file type descriptions provided in
|
||||
mimetypes-file to the desktop environment.
|
||||
mimetypes-file must be a XML file that follows the
|
||||
freedesktop.org Shared MIME-info Database specification
|
||||
and that has a mime-info element as its document root.
|
||||
For each new file type one or more icons with name
|
||||
type-subtype must be installed with the
|
||||
xdg-icon-resource command in the mimetypes context. For
|
||||
example the filetype
|
||||
application/vnd.oasis.opendocument.text requires an icon
|
||||
named application-vnd.oasis.opendocument.text to be
|
||||
installed (unless the file type recommends another icon
|
||||
name).
|
||||
|
||||
The default option is for use inside a desktop session only. It is not
|
||||
recommended to use xdg-mime default as root.
|
||||
|
||||
install
|
||||
Adds the file type descriptions provided in mimetypes-file to the desktop
|
||||
environment. mimetypes-file must be a XML file that follows the
|
||||
freedesktop.org Shared MIME-info Database specification and that has a
|
||||
mime-info element as its document root. For each new file type one or more
|
||||
icons with name type-subtype must be installed with the xdg-icon-resource
|
||||
command in the mimetypes context. For example the filetype application/
|
||||
vnd.oasis.opendocument.text requires an icon named
|
||||
application-vnd.oasis.opendocument.text to be installed (unless the file
|
||||
type recommends another icon name).
|
||||
uninstall
|
||||
Removes the file type descriptions provided in mimetypes-file and
|
||||
previously added with xdg-mime install from the desktop environment.
|
||||
mimetypes-file must be a XML file that follows the freedesktop.org Shared
|
||||
MIME-info Database specification and that has a mime-info element as its
|
||||
document root.
|
||||
uninstall
|
||||
Removes the file type descriptions provided in
|
||||
mimetypes-file and previously added with xdg-mime
|
||||
install from the desktop environment. mimetypes-file
|
||||
must be a XML file that follows the freedesktop.org
|
||||
Shared MIME-info Database specification and that has a
|
||||
mime-info element as its document root.
|
||||
|
||||
Options
|
||||
|
||||
--mode mode
|
||||
--mode mode
|
||||
mode can be user or system. In user mode the file is
|
||||
(un)installed for the current user only. In system mode
|
||||
the file is (un)installed for all users on the system.
|
||||
Usually only root is allowed to install in system mode.
|
||||
|
||||
mode can be user or system. In user mode the file is (un)installed for the
|
||||
current user only. In system mode the file is (un)installed for all users
|
||||
on the system. Usually only root is allowed to install in system mode.
|
||||
The default is to use system mode when called by root
|
||||
and to use user mode when called by a non-root user.
|
||||
|
||||
The default is to use system mode when called by root and to use user mode
|
||||
when called by a non-root user.
|
||||
--novendor
|
||||
Normally, xdg-mime checks to ensure that the
|
||||
mimetypes-file to be installed has a proper vendor
|
||||
prefix. This option can be used to disable that check.
|
||||
|
||||
--novendor
|
||||
A vendor prefix consists of alpha characters ([a-zA-Z])
|
||||
and is terminated with a dash ("-"). Companies and
|
||||
organizations are encouraged to use a word or phrase,
|
||||
preferably the organizations name, for which they hold a
|
||||
trademark as their vendor prefix. The purpose of the
|
||||
vendor prefix is to prevent name conflicts.
|
||||
|
||||
Normally, xdg-mime checks to ensure that the mimetypes-file to be installed
|
||||
has a proper vendor prefix. This option can be used to disable that check.
|
||||
--help
|
||||
Show command synopsis.
|
||||
|
||||
A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated
|
||||
with a dash ("-"). Companies and organizations are encouraged to use a word
|
||||
or phrase, preferably the organizations name, for which they hold a
|
||||
trademark as their vendor prefix. The purpose of the vendor prefix is to
|
||||
prevent name conflicts.
|
||||
--manual
|
||||
Show this manual page.
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
--manual
|
||||
Show this manualpage.
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Environment Variables
|
||||
|
||||
xdg-mime honours the following environment variables:
|
||||
xdg-mime honours the following environment variables:
|
||||
|
||||
XDG_UTILS_DEBUG_LEVEL
|
||||
Setting this environment variable to a non-zero numerical value makes
|
||||
xdg-mime do more verbose reporting on stderr. Setting a higher value
|
||||
increases the verbosity.
|
||||
XDG_UTILS_INSTALL_MODE
|
||||
This environment variable can be used by the user or administrator to
|
||||
override the installation mode. Valid values are user and system.
|
||||
XDG_UTILS_DEBUG_LEVEL
|
||||
Setting this environment variable to a non-zero
|
||||
numerical value makes xdg-mime do more verbose reporting
|
||||
on stderr. Setting a higher value increases the
|
||||
verbosity.
|
||||
|
||||
XDG_UTILS_INSTALL_MODE
|
||||
This environment variable can be used by the user or
|
||||
administrator to override the installation mode. Valid
|
||||
values are user and system.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
An exit code of 0 indicates success while a non-zero exit code
|
||||
indicates failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
2
|
||||
One of the files passed on the command line did not exist.
|
||||
3
|
||||
A required tool could not be found.
|
||||
4
|
||||
The action failed.
|
||||
5
|
||||
No permission to read one of the files passed on the command line.
|
||||
1
|
||||
Error in command line syntax.
|
||||
|
||||
2
|
||||
One of the files passed on the command line did not
|
||||
exist.
|
||||
|
||||
3
|
||||
A required tool could not be found.
|
||||
|
||||
4
|
||||
The action failed.
|
||||
|
||||
5
|
||||
No permission to read one of the files passed on the
|
||||
command line.
|
||||
|
||||
See Also
|
||||
|
||||
xdg-icon-resource(1), xdg-desktop-menu(1)
|
||||
xdg-icon-resource(1), xdg-desktop-menu(1), Shared MIME database
|
||||
specification, MIME applications associations specification
|
||||
|
||||
Examples
|
||||
|
||||
xdg-mime query filetype /tmp/foobar.png
|
||||
|
||||
Prints the MIME type of the file /tmp/foobar.png, in this case image/png
|
||||
Prints the MIME type of the file /tmp/foobar.png, in this case
|
||||
image/png
|
||||
|
||||
xdg-mime query default image/png
|
||||
|
||||
Prints the .desktop filename of the application which is registered to open PNG
|
||||
files.
|
||||
Prints the .desktop filename of the application which is
|
||||
registered to open PNG files.
|
||||
|
||||
xdg-mime install shinythings-shiny.xml
|
||||
|
||||
Adds a file type description for "shiny"-files. "shinythings-" is used as the
|
||||
vendor prefix. The file type description could look as folows.
|
||||
|
||||
Adds a file type description for "shiny"-files. "shinythings-"
|
||||
is used as the vendor prefix. The file type description could
|
||||
look as follows.
|
||||
shinythings-shiny.xml:
|
||||
|
||||
<?xml version="1.0"?>
|
||||
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
|
||||
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'
|
||||
>
|
||||
<mime-type type="text/x-shiny">
|
||||
<comment>Shiny new file type</comment>
|
||||
<glob pattern="*.shiny"/>
|
||||
|
@ -202,30 +227,30 @@ shinythings-shiny.xml:
|
|||
</mime-type>
|
||||
</mime-info>
|
||||
|
||||
An icon for this new file type must also be installed, for example with:
|
||||
|
||||
xdg-icon-resource install --context mimetypes --size 64 shiny-file-icon.png text-x-shiny
|
||||
|
||||
An icon for this new file type must also be installed, for
|
||||
example with:
|
||||
xdg-icon-resource install --context mimetypes --size 64 shiny-file-icon.
|
||||
png text-x-shiny
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-mime - command line tool for querying information about file type handling
|
||||
and adding descriptions for new file types
|
||||
xdg-mime - command line tool for querying information about
|
||||
file type handling and adding descriptions for new file types
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-mime query { filetype | default } ...
|
||||
xdg-mime query { filetype | default } ...
|
||||
|
||||
xdg-mime default application mimetype(s)
|
||||
xdg-mime default application mimetype(s)
|
||||
|
||||
xdg-mime install [--mode mode] [--novendor] mimetypes-file
|
||||
xdg-mime install [--mode mode] [--novendor] mimetypes-file
|
||||
|
||||
xdg-mime uninstall [--mode mode] mimetypes-file
|
||||
xdg-mime uninstall [--mode mode] mimetypes-file
|
||||
|
||||
xdg-mime { --help | --manual | --version }
|
||||
xdg-mime { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
@ -244,6 +269,64 @@ DEBUG()
|
|||
echo "$@" >&2
|
||||
}
|
||||
|
||||
# This handles backslashes but not quote marks.
|
||||
first_word()
|
||||
{
|
||||
read first rest
|
||||
echo "$first"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a binary to a .desktop file
|
||||
binary_to_desktop_file()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
binary="`which "$1"`"
|
||||
binary="`readlink -f "$binary"`"
|
||||
base="`basename "$binary"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] || continue
|
||||
[ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
|
||||
for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
|
||||
[ -r "$file" ] || continue
|
||||
# Check to make sure it's worth the processing.
|
||||
grep -q "^Exec.*$base" "$file" || continue
|
||||
# Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
|
||||
grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
if [ x"`readlink -f "$command"`" = x"$binary" ]; then
|
||||
# Fix any double slashes that got added path composition
|
||||
echo "$file" | sed -e 's,//*,/,g'
|
||||
return
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a .desktop file to a binary
|
||||
## FIXME: handle vendor dir case
|
||||
desktop_file_to_binary()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
desktop="`basename "$1"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] && [ -d "$dir/applications" ] || continue
|
||||
file="$dir/applications/$desktop"
|
||||
[ -r "$file" ] || continue
|
||||
# Remove any arguments (%F, %f, %U, %u, etc.).
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
readlink -f "$command"
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
|
@ -352,7 +435,7 @@ check_vendor_prefix()
|
|||
[ -n "$file_label" ] || file_label="filename"
|
||||
file=`basename "$1"`
|
||||
case "$file" in
|
||||
[a-zA-Z]*-*)
|
||||
[[:alpha:]]*-*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
@ -374,7 +457,7 @@ check_output_file()
|
|||
fi
|
||||
else
|
||||
DIR=`dirname "$1"`
|
||||
if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
|
||||
if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
|
||||
exit_failure_file_permission_write "no permission to create file '$1'"
|
||||
fi
|
||||
fi
|
||||
|
@ -402,7 +485,7 @@ check_common_commands()
|
|||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-mime 1.1.0 rc1"
|
||||
echo "xdg-mime 1.1.0 rc3"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
|
@ -426,12 +509,86 @@ fi
|
|||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
|
||||
else DE=""
|
||||
# see https://bugs.freedesktop.org/show_bug.cgi?id=34164
|
||||
unset GREP_OPTIONS
|
||||
|
||||
if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
|
||||
case "${XDG_CURRENT_DESKTOP}" in
|
||||
# only recently added to menu-spec, pre-spec X- still in use
|
||||
Cinnamon|X-Cinnamon)
|
||||
DE=cinnamon;
|
||||
;;
|
||||
ENLIGHTENMENT)
|
||||
DE=enlightenment;
|
||||
;;
|
||||
# GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
|
||||
GNOME*)
|
||||
DE=gnome;
|
||||
;;
|
||||
KDE)
|
||||
DE=kde;
|
||||
;;
|
||||
LXDE)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
XFCE)
|
||||
DE=xfce
|
||||
;;
|
||||
X-Generic)
|
||||
DE=generic
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# classic fallbacks
|
||||
if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
|
||||
elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to checking $DESKTOP_SESSION
|
||||
case "$DESKTOP_SESSION" in
|
||||
gnome)
|
||||
DE=gnome;
|
||||
;;
|
||||
LXDE|Lubuntu)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
xfce|xfce4|'Xfce Session')
|
||||
DE=xfce;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to uname output for other platforms
|
||||
case "$(uname 2>/dev/null)" in
|
||||
CYGWIN*)
|
||||
DE=cygwin;
|
||||
;;
|
||||
Darwin)
|
||||
DE=darwin;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"gnome" ]; then
|
||||
# gnome-default-applications-properties is only available in GNOME 2.x
|
||||
# but not in GNOME 3.x
|
||||
which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -442,7 +599,6 @@ detectDE()
|
|||
|
||||
kfmclient_fix_exit_code()
|
||||
{
|
||||
[ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
|
||||
version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
|
||||
major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
|
||||
minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
|
||||
|
@ -459,11 +615,7 @@ update_mime_database()
|
|||
detectDE
|
||||
if [ x"$DE" = x"kde" ] ; then
|
||||
DEBUG 1 "Running kbuildsycoca"
|
||||
if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
|
||||
eval 'kbuildsycoca4'$xdg_redirect_output
|
||||
else
|
||||
eval 'kbuildsycoca'$xdg_redirect_output
|
||||
fi
|
||||
eval 'kbuildsycoca${KDE_SESSION_VERSION}'$xdg_redirect_output
|
||||
fi
|
||||
fi
|
||||
for x in `echo "$PATH:/opt/gnome/bin" | sed 's/:/ /g'`; do
|
||||
|
@ -477,14 +629,20 @@ update_mime_database()
|
|||
|
||||
info_kde()
|
||||
{
|
||||
if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
|
||||
DEBUG 1 "Running kmimetypefinder \"$1\""
|
||||
KMIMETYPEFINDER=`which kmimetypefinder 2>/dev/null`
|
||||
$KMIMETYPEFINDER "$1" 2>/dev/null | head -n 1
|
||||
if [ -n "${KDE_SESSION_VERSION}" ]; then
|
||||
case "${KDE_SESSION_VERSION}" in
|
||||
4)
|
||||
DEBUG 1 "Running kmimetypefinder \"$1\""
|
||||
kmimetypefinder "$1" 2>/dev/null | head -n 1
|
||||
;;
|
||||
5)
|
||||
DEBUG 1 "Running kmimetypefinder${KDE_SESSION_VERSION} \"$1\""
|
||||
kmimetypefinder${KDE_SESSION_VERSION} "$1" 2>/dev/null | head -n 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
DEBUG 1 "Running kfile \"$1\""
|
||||
KFILE=`which kfile 2>/dev/null`
|
||||
$KFILE "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1
|
||||
kfile "$1" 2> /dev/null | head -n 1 | cut -d "(" -f 2 | cut -d ")" -f 1
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
|
@ -496,14 +654,12 @@ info_kde()
|
|||
|
||||
info_gnome()
|
||||
{
|
||||
file=`readlink -f "$1"` # Normalize path
|
||||
|
||||
if gvfs-info --help 2>/dev/null 1>&2; then
|
||||
DEBUG 1 "Running gvfs-info \"$file\""
|
||||
gvfs-info "$file" 2> /dev/null | grep standard::content-type | cut -d' ' -f4
|
||||
else
|
||||
DEBUG 1 "Running gnomevfs-info \"$file\""
|
||||
gnomevfs-info --slow-mime "$file" 2> /dev/null | grep "^MIME" | cut -d ":" -f 2 | sed s/"^ "//
|
||||
DEBUG 1 "Running gvfs-info \"$1\""
|
||||
gvfs-info "$1" 2> /dev/null | grep standard::content-type | cut -d' ' -f4
|
||||
elif gnomevfs-info --help 2>/dev/null 1>&2; then
|
||||
DEBUG 1 "Running gnomevfs-info \"$1\""
|
||||
gnomevfs-info --slow-mime "$1" 2> /dev/null | grep "^MIME" | cut -d ":" -f 2 | sed s/"^ "//
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
|
@ -515,8 +671,13 @@ info_gnome()
|
|||
|
||||
info_generic()
|
||||
{
|
||||
DEBUG 1 "Running file -i \"$1\""
|
||||
/usr/bin/file -i "$1" 2> /dev/null | cut -d ":" -f 2 | sed s/"^ "//
|
||||
if mimetype --version >/dev/null 2>&1; then
|
||||
DEBUG 1 "Running mimetype --brief --dereference \"$1\""
|
||||
mimetype --brief --dereference "$1"
|
||||
else
|
||||
DEBUG 1 "Running file --brief --dereference --mime-type \"$1\""
|
||||
/usr/bin/file --brief --dereference --mime-type "$1" 2> /dev/null
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
|
@ -562,9 +723,9 @@ make_default_kde()
|
|||
DEBUG 2 "make_default_kde $vendor $mimetype"
|
||||
DEBUG 1 "Updating $default_file"
|
||||
mkdir -p "$default_dir"
|
||||
[ -f $default_file ] || touch $default_file
|
||||
[ -f "$default_file" ] || touch "$default_file"
|
||||
if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
|
||||
[ -f $default_file ] || touch $default_file
|
||||
[ -f "$default_file" ] || touch "$default_file"
|
||||
awk -v application="$vendor" -v mimetype="$mimetype" '
|
||||
BEGIN {
|
||||
prefix=mimetype "="
|
||||
|
@ -621,7 +782,7 @@ make_default_kde()
|
|||
blanks--
|
||||
}
|
||||
}
|
||||
' $default_file > ${default_file}.new && mv ${default_file}.new $default_file
|
||||
' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_file"
|
||||
eval 'kbuildsycoca4'$xdg_redirect_output
|
||||
else
|
||||
awk -v application="$vendor" -v mimetype="$mimetype" '
|
||||
|
@ -648,7 +809,7 @@ make_default_kde()
|
|||
print "Preference=1"
|
||||
print "ServiceType=" mimetype
|
||||
}
|
||||
' $default_file > ${default_file}.new && mv ${default_file}.new $default_file
|
||||
' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_file"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -656,47 +817,205 @@ make_default_generic()
|
|||
{
|
||||
# $1 is vendor-name.desktop
|
||||
# $2 is mime/type
|
||||
# Add $2=$1 to XDG_DATA_HOME/applications/defaults.list
|
||||
# Add $2=$1 to XDG_DATA_HOME/applications/mimeapps.list
|
||||
xdg_user_dir="$XDG_DATA_HOME"
|
||||
[ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
|
||||
default_file="$xdg_user_dir/applications/defaults.list"
|
||||
default_file="$xdg_user_dir/applications/mimeapps.list"
|
||||
DEBUG 2 "make_default_generic $1 $2"
|
||||
DEBUG 1 "Updating $default_file"
|
||||
grep -v "$2=" $default_file > ${default_file}.new 2> /dev/null
|
||||
if ! grep "[Default Applications]" ${default_file}.new > /dev/null; then
|
||||
echo "[Default Applications]" >> ${default_file}.new
|
||||
[ -f "$default_file" ] || touch "$default_file"
|
||||
awk -v mimetype="$2" -v application="$1" '
|
||||
BEGIN {
|
||||
prefix=mimetype "="
|
||||
indefault=0
|
||||
added=0
|
||||
blanks=0
|
||||
found=0
|
||||
}
|
||||
{
|
||||
suppress=0
|
||||
if (index($0, "[Default Applications]") == 1) {
|
||||
indefault=1
|
||||
found=1
|
||||
} else if (index($0, "[") == 1) {
|
||||
if (!added && indefault) {
|
||||
print prefix application
|
||||
added=1
|
||||
}
|
||||
indefault=0
|
||||
} else if ($0 == "") {
|
||||
suppress=1
|
||||
blanks++
|
||||
} else if (indefault && !added && index($0, prefix) == 1) {
|
||||
$0=prefix application
|
||||
added=1
|
||||
}
|
||||
if (!suppress) {
|
||||
while (blanks > 0) {
|
||||
print ""
|
||||
blanks--
|
||||
}
|
||||
print $0
|
||||
}
|
||||
}
|
||||
END {
|
||||
if (!added) {
|
||||
if (!found) {
|
||||
print ""
|
||||
print "[Default Applications]"
|
||||
}
|
||||
print prefix application
|
||||
}
|
||||
while (blanks > 0) {
|
||||
print ""
|
||||
blanks--
|
||||
}
|
||||
}
|
||||
' "$default_file" > "${default_file}.new" && mv "${default_file}.new" "$default_file"
|
||||
}
|
||||
|
||||
search_desktop_file()
|
||||
{
|
||||
local MIME="$1"
|
||||
local dir="$2"
|
||||
|
||||
grep -l "$MIME;" "$dir/"*.desktop 2>/dev/null
|
||||
|
||||
for f in $dir/*/; do
|
||||
[ -d "$f" ] && search_desktop_file "$MIME" "$f"
|
||||
done
|
||||
}
|
||||
|
||||
defapp_fallback()
|
||||
{
|
||||
MIME="$1"
|
||||
|
||||
xdg_user_dir="$XDG_DATA_HOME"
|
||||
[ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
|
||||
|
||||
xdg_system_dirs="$XDG_DATA_DIRS"
|
||||
[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
|
||||
|
||||
preference=-1
|
||||
desktop_file=""
|
||||
for d in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
|
||||
for x in `search_desktop_file "$MIME" "$d/applications"`; do
|
||||
pref=0`awk -F"=" '/InitialPreference=/ {print($2)}' "$x"`
|
||||
DEBUG 2 " Checking $x"
|
||||
|
||||
if [ $pref -gt $preference ]; then
|
||||
DEBUG 2 " Select $x [ $preference => $pref ]"
|
||||
preference=$pref
|
||||
desktop_file=$x
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
if [ -n "$desktop_file" ] ; then
|
||||
echo `basename $desktop_file`
|
||||
exit_success
|
||||
fi
|
||||
echo $2=$1 >> ${default_file}.new
|
||||
mv ${default_file}.new $default_file
|
||||
}
|
||||
|
||||
check_mimeapps_list()
|
||||
{
|
||||
local mimetype="$1" dir="$2"
|
||||
local desktop oldifs="$IFS"
|
||||
|
||||
IFS=:
|
||||
for desktop in $XDG_CURRENT_DESKTOP ''; do
|
||||
IFS="$oldifs"
|
||||
if [ -n "$desktop" ]; then
|
||||
local prefix=$(echo "$desktop-" | tr '[:upper:]' '[:lower:]')
|
||||
else
|
||||
local prefix=
|
||||
fi
|
||||
local mimeapps_list="$dir/${prefix}mimeapps.list"
|
||||
if [ -f "$mimeapps_list" ] ; then
|
||||
DEBUG 2 "Checking $mimeapps_list"
|
||||
local result=$(awk -v mimetype="$mimetype" '
|
||||
BEGIN {
|
||||
prefix=mimetype "="
|
||||
indefault=0
|
||||
found=0
|
||||
}
|
||||
{
|
||||
if (index($0, "[Default Applications]") == 1) {
|
||||
indefault=1
|
||||
} else if (index($0, "[") == 1) {
|
||||
indefault=0
|
||||
} else if (!found && indefault && index($0, prefix) == 1) {
|
||||
print substr($0, length(prefix) +1, length)
|
||||
found=1
|
||||
}
|
||||
}
|
||||
' "$mimeapps_list")
|
||||
if [ -n "$result" ]; then
|
||||
echo "$result"
|
||||
exit_success
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
defapp_generic()
|
||||
{
|
||||
MIME="$1"
|
||||
xdg_config_home="$XDG_CONFIG_HOME"
|
||||
[ -n "$xdg_config_home" ] || xdg_config_home="$HOME/.config"
|
||||
xdg_config_dirs="$XDG_CONFIG_DIRS"
|
||||
[ -n "$xdg_config_dirs" ] || xdg_config_dirs="/etc/xdg"
|
||||
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 | cut -d ';' -f 1`
|
||||
if [ -n "$trader_result" ] ; then
|
||||
echo $trader_result
|
||||
exit_success
|
||||
fi
|
||||
local oldifs="$IFS" dir
|
||||
|
||||
IFS=:
|
||||
for dir in $xdg_config_home $xdg_config_dirs; do
|
||||
IFS="$oldifs"
|
||||
check_mimeapps_list "$MIME" "$dir"
|
||||
done
|
||||
|
||||
IFS=:
|
||||
for dir in $xdg_user_dir $xdg_system_dirs; do
|
||||
IFS="$oldifs"
|
||||
check_mimeapps_list "$MIME" "$dir/applications"
|
||||
done
|
||||
|
||||
for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
|
||||
for prefix in "$XDG_MENU_PREFIX" ""; do
|
||||
DEBUG 2 "Checking $x/applications/${prefix}defaults.list and $x/applications/${prefix}mimeinfo.cache"
|
||||
trader_result=`grep "$MIME=" $x/applications/${prefix}defaults.list $x/applications/${prefix}mimeinfo.cache 2> /dev/null | head -n 1 | cut -d '=' -f 2 | cut -d ';' -f 1`
|
||||
if [ -n "$trader_result" ] ; then
|
||||
echo $trader_result
|
||||
exit_success
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
defapp_fallback $MIME
|
||||
exit_success
|
||||
}
|
||||
|
||||
defapp_kde()
|
||||
{
|
||||
MIME="$1"
|
||||
if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
|
||||
KTRADER=`which ktraderclient 2> /dev/null`
|
||||
MIMETYPE="--mimetype"
|
||||
SERVICETYPE="--servicetype"
|
||||
|
||||
if [ -n "${KDE_SESSION_VERSION}" ]; then
|
||||
case "${KDE_SESSION_VERSION}" in
|
||||
4)
|
||||
KTRADER=`which ktraderclient 2> /dev/null`
|
||||
MIMETYPE="--mimetype"
|
||||
SERVICETYPE="--servicetype"
|
||||
;;
|
||||
5)
|
||||
KTRADER=`which ktraderclient${KDE_SESSION_VERSION} 2> /dev/null`
|
||||
MIMETYPE="--mimetype"
|
||||
SERVICETYPE="--servicetype"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
KTRADER=`which ktradertest 2> /dev/null`
|
||||
fi
|
||||
|
@ -752,6 +1071,7 @@ case $1 in
|
|||
;;
|
||||
esac
|
||||
check_input_file "$filename"
|
||||
filename=`readlink -f -- "$filename"`
|
||||
;;
|
||||
|
||||
default)
|
||||
|
@ -845,7 +1165,7 @@ if [ "$action" = "info" ]; then
|
|||
info_kde "$filename"
|
||||
;;
|
||||
|
||||
gnome)
|
||||
gnome*|cinnamon|lxde|mate|xfce)
|
||||
info_gnome "$filename"
|
||||
;;
|
||||
|
||||
|
|
590
comp/src/gb.desktop/xdg-utils/xdg-open
Normal file → Executable file
590
comp/src/gb.desktop/xdg-utils/xdg-open
Normal file → Executable file
|
@ -38,71 +38,85 @@ manualpage()
|
|||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-open - opens a file or URL in the user's preferred application
|
||||
xdg-open - opens a file or URL in the user's preferred
|
||||
application
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-open { file | URL }
|
||||
xdg-open { file | URL }
|
||||
|
||||
xdg-open { --help | --manual | --version }
|
||||
xdg-open { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
xdg-open opens a file or URL in the user's preferred application. If a URL is
|
||||
provided the URL will be opened in the user's preferred web browser. If a file
|
||||
is provided the file will be opened in the preferred application for files of
|
||||
that type. xdg-open supports file, ftp, http and https URLs.
|
||||
xdg-open opens a file or URL in the user's preferred
|
||||
application. If a URL is provided the URL will be opened in the
|
||||
user's preferred web browser. If a file is provided the file
|
||||
will be opened in the preferred application for files of that
|
||||
type. xdg-open supports file, ftp, http and https URLs.
|
||||
|
||||
xdg-open is for use inside a desktop session only. It is not recommended to use
|
||||
xdg-open as root.
|
||||
xdg-open is for use inside a desktop session only. It is not
|
||||
recommended to use xdg-open as root.
|
||||
|
||||
Options
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
--manual
|
||||
Show this manualpage.
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
--help
|
||||
Show command synopsis.
|
||||
|
||||
--manual
|
||||
Show this manual page.
|
||||
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
An exit code of 0 indicates success while a non-zero exit code
|
||||
indicates failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
2
|
||||
One of the files passed on the command line did not exist.
|
||||
3
|
||||
A required tool could not be found.
|
||||
4
|
||||
The action failed.
|
||||
1
|
||||
Error in command line syntax.
|
||||
|
||||
2
|
||||
One of the files passed on the command line did not
|
||||
exist.
|
||||
|
||||
3
|
||||
A required tool could not be found.
|
||||
|
||||
4
|
||||
The action failed.
|
||||
|
||||
See Also
|
||||
|
||||
xdg-mime(1), xdg-settings(1), MIME applications associations
|
||||
specification
|
||||
|
||||
Examples
|
||||
|
||||
xdg-open 'http://www.freedesktop.org/'
|
||||
|
||||
Opens the Freedesktop.org website in the user's default browser
|
||||
Opens the freedesktop.org website in the user's default
|
||||
browser.
|
||||
|
||||
xdg-open /tmp/foobar.png
|
||||
|
||||
Opens the PNG image file /tmp/foobar.png in the user's default image viewing
|
||||
application.
|
||||
|
||||
Opens the PNG image file /tmp/foobar.png in the user's default
|
||||
image viewing application.
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-open - opens a file or URL in the user's preferred application
|
||||
xdg-open - opens a file or URL in the user's preferred
|
||||
application
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-open { file | URL }
|
||||
xdg-open { file | URL }
|
||||
|
||||
xdg-open { --help | --manual | --version }
|
||||
xdg-open { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
@ -121,6 +135,64 @@ DEBUG()
|
|||
echo "$@" >&2
|
||||
}
|
||||
|
||||
# This handles backslashes but not quote marks.
|
||||
first_word()
|
||||
{
|
||||
read first rest
|
||||
echo "$first"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a binary to a .desktop file
|
||||
binary_to_desktop_file()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
binary="`which "$1"`"
|
||||
binary="`readlink -f "$binary"`"
|
||||
base="`basename "$binary"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] || continue
|
||||
[ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
|
||||
for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
|
||||
[ -r "$file" ] || continue
|
||||
# Check to make sure it's worth the processing.
|
||||
grep -q "^Exec.*$base" "$file" || continue
|
||||
# Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
|
||||
grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
if [ x"`readlink -f "$command"`" = x"$binary" ]; then
|
||||
# Fix any double slashes that got added path composition
|
||||
echo "$file" | sed -e 's,//*,/,g'
|
||||
return
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a .desktop file to a binary
|
||||
## FIXME: handle vendor dir case
|
||||
desktop_file_to_binary()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
desktop="`basename "$1"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] && [ -d "$dir/applications" ] || continue
|
||||
file="$dir/applications/$desktop"
|
||||
[ -r "$file" ] || continue
|
||||
# Remove any arguments (%F, %f, %U, %u, etc.).
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
readlink -f "$command"
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
|
@ -229,7 +301,7 @@ check_vendor_prefix()
|
|||
[ -n "$file_label" ] || file_label="filename"
|
||||
file=`basename "$1"`
|
||||
case "$file" in
|
||||
[a-zA-Z]*-*)
|
||||
[[:alpha:]]*-*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
@ -251,7 +323,7 @@ check_output_file()
|
|||
fi
|
||||
else
|
||||
DIR=`dirname "$1"`
|
||||
if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
|
||||
if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
|
||||
exit_failure_file_permission_write "no permission to create file '$1'"
|
||||
fi
|
||||
fi
|
||||
|
@ -279,7 +351,7 @@ check_common_commands()
|
|||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-open 1.1.0 rc1"
|
||||
echo "xdg-open 1.1.0 rc3"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
|
@ -303,13 +375,86 @@ fi
|
|||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
|
||||
else DE=""
|
||||
# see https://bugs.freedesktop.org/show_bug.cgi?id=34164
|
||||
unset GREP_OPTIONS
|
||||
|
||||
if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
|
||||
case "${XDG_CURRENT_DESKTOP}" in
|
||||
# only recently added to menu-spec, pre-spec X- still in use
|
||||
Cinnamon|X-Cinnamon)
|
||||
DE=cinnamon;
|
||||
;;
|
||||
ENLIGHTENMENT)
|
||||
DE=enlightenment;
|
||||
;;
|
||||
# GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
|
||||
GNOME*)
|
||||
DE=gnome;
|
||||
;;
|
||||
KDE)
|
||||
DE=kde;
|
||||
;;
|
||||
LXDE)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
XFCE)
|
||||
DE=xfce
|
||||
;;
|
||||
X-Generic)
|
||||
DE=generic
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# classic fallbacks
|
||||
if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
|
||||
elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to checking $DESKTOP_SESSION
|
||||
case "$DESKTOP_SESSION" in
|
||||
gnome)
|
||||
DE=gnome;
|
||||
;;
|
||||
LXDE|Lubuntu)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
xfce|xfce4|'Xfce Session')
|
||||
DE=xfce;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to uname output for other platforms
|
||||
case "$(uname 2>/dev/null)" in
|
||||
CYGWIN*)
|
||||
DE=cygwin;
|
||||
;;
|
||||
Darwin)
|
||||
DE=darwin;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"gnome" ]; then
|
||||
# gnome-default-applications-properties is only available in GNOME 2.x
|
||||
# but not in GNOME 3.x
|
||||
which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -320,7 +465,6 @@ detectDE()
|
|||
|
||||
kfmclient_fix_exit_code()
|
||||
{
|
||||
[ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
|
||||
version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
|
||||
major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
|
||||
minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
|
||||
|
@ -332,23 +476,124 @@ kfmclient_fix_exit_code()
|
|||
}
|
||||
|
||||
# This handles backslashes but not quote marks.
|
||||
first_word()
|
||||
last_word()
|
||||
{
|
||||
read first rest
|
||||
echo "$first"
|
||||
echo "$rest"
|
||||
}
|
||||
|
||||
# Get the value of a key in a desktop file's Desktop Entry group.
|
||||
# Example: Use get_key foo.desktop Exec
|
||||
# to get the values of the Exec= key for the Desktop Entry group.
|
||||
get_key()
|
||||
{
|
||||
local file="${1}"
|
||||
local key="${2}"
|
||||
local desktop_entry=""
|
||||
|
||||
IFS_="${IFS}"
|
||||
IFS=""
|
||||
while read line
|
||||
do
|
||||
case "$line" in
|
||||
"[Desktop Entry]")
|
||||
desktop_entry="y"
|
||||
;;
|
||||
# Reset match flag for other groups
|
||||
"["*)
|
||||
desktop_entry=""
|
||||
;;
|
||||
"${key}="*)
|
||||
# Only match Desktop Entry group
|
||||
if [ -n "${desktop_entry}" ]
|
||||
then
|
||||
echo "${line}" | cut -d= -f 2-
|
||||
fi
|
||||
esac
|
||||
done < "${file}"
|
||||
IFS="${IFS_}"
|
||||
}
|
||||
|
||||
# Returns true if argument is a file:// URL or path
|
||||
is_file_url_or_path()
|
||||
{
|
||||
if echo "$1" | grep -q '^file://' \
|
||||
|| ! echo "$1" | egrep -q '^[[:alpha:]+\.\-]+:'; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# If argument is a file URL, convert it to a (percent-decoded) path.
|
||||
# If not, leave it as it is.
|
||||
file_url_to_path()
|
||||
{
|
||||
local file="$1"
|
||||
if echo "$file" | grep -q '^file:///'; then
|
||||
file=${file#file://}
|
||||
file=${file%%#*}
|
||||
file=$(echo "$file" | sed -r 's/\?.*$//')
|
||||
local printf=printf
|
||||
if [ -x /usr/bin/printf ]; then
|
||||
printf=/usr/bin/printf
|
||||
fi
|
||||
file=$($printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x\1@g')")
|
||||
fi
|
||||
echo "$file"
|
||||
}
|
||||
|
||||
open_cygwin()
|
||||
{
|
||||
cygstart "$1"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
}
|
||||
|
||||
open_darwin()
|
||||
{
|
||||
open "$1"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
}
|
||||
|
||||
open_kde()
|
||||
{
|
||||
if kde-open -v 2>/dev/null 1>&2; then
|
||||
kde-open -noninteractive "$1"
|
||||
if [ -n "${KDE_SESSION_VERSION}" ]; then
|
||||
case "${KDE_SESSION_VERSION}" in
|
||||
4)
|
||||
kde-open "$1"
|
||||
;;
|
||||
5)
|
||||
kde-open${KDE_SESSION_VERSION} "$1"
|
||||
;;
|
||||
esac
|
||||
else
|
||||
if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
|
||||
kfmclient openURL "$1"
|
||||
else
|
||||
kfmclient exec "$1"
|
||||
kfmclient_fix_exit_code $?
|
||||
fi
|
||||
kfmclient exec "$1"
|
||||
kfmclient_fix_exit_code $?
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
}
|
||||
|
||||
open_gnome3()
|
||||
{
|
||||
if gvfs-open --help >/dev/null 2>&1; then
|
||||
gvfs-open "$1"
|
||||
else
|
||||
open_generic "$1"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
|
@ -360,10 +605,12 @@ open_kde()
|
|||
|
||||
open_gnome()
|
||||
{
|
||||
if gvfs-open --help 2>/dev/null 1>&2; then
|
||||
if gvfs-open --help >/dev/null 2>&1; then
|
||||
gvfs-open "$1"
|
||||
else
|
||||
elif gnome-open --help >/dev/null 2>&1; then
|
||||
gnome-open "$1"
|
||||
else
|
||||
open_generic "$1"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
|
@ -399,9 +646,92 @@ open_xfce()
|
|||
fi
|
||||
}
|
||||
|
||||
open_enlightenment()
|
||||
{
|
||||
enlightenment_open "$1"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
}
|
||||
|
||||
#-----------------------------------------
|
||||
# Recursively search .desktop file
|
||||
|
||||
search_desktop_file()
|
||||
{
|
||||
local default="$1"
|
||||
local dir="$2"
|
||||
local target="$3"
|
||||
|
||||
local file=""
|
||||
# look for both vendor-app.desktop, vendor/app.desktop
|
||||
if [ -r "$dir/$default" ]; then
|
||||
file="$dir/$default"
|
||||
elif [ -r "$dir/`echo $default | sed -e 's|-|/|'`" ]; then
|
||||
file="$dir/`echo $default | sed -e 's|-|/|'`"
|
||||
fi
|
||||
|
||||
if [ -r "$file" ] ; then
|
||||
command="$(get_key "${file}" "Exec" | first_word)"
|
||||
command_exec=`which $command 2>/dev/null`
|
||||
icon="$(get_key "${file}" "Icon")"
|
||||
# FIXME: Actually LC_MESSAGES should be used as described in
|
||||
# http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
|
||||
localised_name="$(get_key "${file}" "Name")"
|
||||
set -- $(get_key "${file}" "Exec" | last_word)
|
||||
# We need to replace any occurrence of "%f", "%F" and
|
||||
# the like by the target file. We examine each
|
||||
# argument and append the modified argument to the
|
||||
# end then shift.
|
||||
local args=$#
|
||||
local replaced=0
|
||||
while [ $args -gt 0 ]; do
|
||||
case $1 in
|
||||
%[c])
|
||||
replaced=1
|
||||
arg="${localised_name}"
|
||||
shift
|
||||
set -- "$@" "$arg"
|
||||
;;
|
||||
%[fFuU])
|
||||
replaced=1
|
||||
arg="$target"
|
||||
shift
|
||||
set -- "$@" "$arg"
|
||||
;;
|
||||
%[i])
|
||||
replaced=1
|
||||
shift
|
||||
set -- "$@" "--icon" "$icon"
|
||||
;;
|
||||
*)
|
||||
arg="$1"
|
||||
shift
|
||||
set -- "$@" "$arg"
|
||||
;;
|
||||
esac
|
||||
args=$(( $args - 1 ))
|
||||
done
|
||||
[ $replaced -eq 1 ] || set -- "$@" "$target"
|
||||
"$command_exec" "$@"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
fi
|
||||
fi
|
||||
|
||||
for d in $dir/*/; do
|
||||
[ -d "$d" ] && search_desktop_file "$default" "$d" "$target"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
open_generic_xdg_mime()
|
||||
{
|
||||
filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"`
|
||||
filetype="$2"
|
||||
default=`xdg-mime query default "$filetype"`
|
||||
if [ -n "$default" ] ; then
|
||||
xdg_user_dir="$XDG_DATA_HOME"
|
||||
|
@ -410,48 +740,73 @@ open_generic_xdg_mime()
|
|||
xdg_system_dirs="$XDG_DATA_DIRS"
|
||||
[ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
|
||||
|
||||
DEBUG 3 "$xdg_user_dir:$xdg_system_dirs"
|
||||
for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
|
||||
local file="$x/applications/$default"
|
||||
if [ -r "$file" ] ; then
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command_exec=`which $command 2>/dev/null`
|
||||
if [ -x "$command_exec" ] ; then
|
||||
$command_exec "$1"
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
search_desktop_file "$default" "$x/applications/" "$1"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
open_generic_xdg_file_mime()
|
||||
{
|
||||
filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"`
|
||||
open_generic_xdg_mime "$1" "$filetype"
|
||||
}
|
||||
|
||||
open_generic_xdg_x_scheme_handler()
|
||||
{
|
||||
scheme="`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'`"
|
||||
if [ -n $scheme ]; then
|
||||
filetype="x-scheme-handler/$scheme"
|
||||
open_generic_xdg_mime "$1" "$filetype"
|
||||
fi
|
||||
}
|
||||
|
||||
open_envvar()
|
||||
{
|
||||
local oldifs="$IFS"
|
||||
local browser browser_with_arg
|
||||
|
||||
IFS=":"
|
||||
for browser in $BROWSER; do
|
||||
IFS="$oldifs"
|
||||
|
||||
if [ -z "$browser" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if echo "$browser" | grep -q %s; then
|
||||
$(printf "$browser" "$1")
|
||||
else
|
||||
$browser "$1"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
open_generic()
|
||||
{
|
||||
# Paths or file:// URLs
|
||||
if (echo "$1" | grep -q '^file://' ||
|
||||
! echo "$1" | egrep -q '^[a-zA-Z+\.\-]+:'); then
|
||||
if is_file_url_or_path "$1"; then
|
||||
local file="$(file_url_to_path "$1")"
|
||||
|
||||
local file="$1"
|
||||
|
||||
# Decode URLs
|
||||
if echo "$file" | grep -q '^file:///'; then
|
||||
file=${file#file://}
|
||||
file="$(printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x\1@g')")"
|
||||
fi
|
||||
check_input_file "$file"
|
||||
|
||||
open_generic_xdg_mime "$file"
|
||||
if [ -n "$DISPLAY" ]; then
|
||||
filetype=`xdg-mime query filetype "$file" | sed "s/;.*//"`
|
||||
open_generic_xdg_mime "$file" "$filetype"
|
||||
fi
|
||||
|
||||
if [ -f /etc/debian_version ] &&
|
||||
which run-mailcap 2>/dev/null 1>&2; then
|
||||
if which run-mailcap 2>/dev/null 1>&2; then
|
||||
run-mailcap --action=view "$file"
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
fi
|
||||
fi
|
||||
|
||||
if mimeopen -v 2>/dev/null 1>&2; then
|
||||
if [ -n "$DISPLAY" ] && mimeopen -v 2>/dev/null 1>&2; then
|
||||
mimeopen -L -n "$file"
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
|
@ -459,25 +814,23 @@ open_generic()
|
|||
fi
|
||||
fi
|
||||
|
||||
IFS=":"
|
||||
for browser in $BROWSER; do
|
||||
if [ x"$browser" != x"" ]; then
|
||||
if [ -n "$BROWSER" ]; then
|
||||
open_envvar "$1"
|
||||
fi
|
||||
|
||||
browser_with_arg=`printf "$browser" "$1" 2>/dev/null`
|
||||
if [ $? -ne 0 ]; then
|
||||
browser_with_arg=$browser;
|
||||
fi
|
||||
if [ -n "$DISPLAY" ]; then
|
||||
open_generic_xdg_x_scheme_handler "$1"
|
||||
fi
|
||||
|
||||
if [ x"$browser_with_arg" = x"$browser" ]; then
|
||||
"$browser" "$1";
|
||||
else eval '$browser_with_arg'$xdg_redirect_output;
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success;
|
||||
fi
|
||||
# if BROWSER variable is not set, check some well known browsers instead
|
||||
if [ x"$BROWSER" = x"" ]; then
|
||||
BROWSER=www-browser:links2:elinks:links:lynx:w3m
|
||||
if [ -n "$DISPLAY" ]; then
|
||||
BROWSER=x-www-browser:firefox:iceweasel:seamonkey:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
open_envvar "$1"
|
||||
|
||||
exit_failure_operation_impossible "no method available for opening '$1'"
|
||||
}
|
||||
|
@ -485,18 +838,15 @@ open_generic()
|
|||
open_lxde()
|
||||
{
|
||||
# pcmanfm only knows how to handle file:// urls and filepaths, it seems.
|
||||
if (echo "$1" | grep -q '^file://' ||
|
||||
! echo "$1" | egrep -q '^[a-zA-Z+\.\-]+:')
|
||||
then
|
||||
local file="$(echo "$1" | sed 's%^file://%%')"
|
||||
if is_file_url_or_path "$1"; then
|
||||
local file="$(file_url_to_path "$1")"
|
||||
|
||||
# handle relative paths
|
||||
if ! echo "$file" | grep -q '^/'; then
|
||||
if ! echo "$file" | grep -q ^/; then
|
||||
file="$(pwd)/$file"
|
||||
fi
|
||||
|
||||
pcmanfm "$file"
|
||||
|
||||
else
|
||||
open_generic "$1"
|
||||
fi
|
||||
|
@ -539,19 +889,27 @@ if [ x"$DE" = x"" ]; then
|
|||
DE=generic
|
||||
fi
|
||||
|
||||
# if BROWSER variable is not set, check some well known browsers instead
|
||||
if [ x"$BROWSER" = x"" ]; then
|
||||
BROWSER=links2:links:lynx:w3m
|
||||
if [ -n "$DISPLAY" ]; then
|
||||
BROWSER=firefox:mozilla:epiphany:konqueror:chromium-browser:google-chrome:$BROWSER
|
||||
fi
|
||||
fi
|
||||
DEBUG 2 "Selected DE $DE"
|
||||
|
||||
# sanitize BROWSER (avoid caling ourselves in particular)
|
||||
case "${BROWSER}" in
|
||||
*:"xdg-open"|"xdg-open":*)
|
||||
BROWSER=$(echo $BROWSER | sed -e 's|:xdg-open||g' -e 's|xdg-open:||g')
|
||||
;;
|
||||
"xdg-open")
|
||||
BROWSER=
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$DE" in
|
||||
kde)
|
||||
open_kde "$url"
|
||||
;;
|
||||
|
||||
gnome3|cinnamon)
|
||||
open_gnome3 "$url"
|
||||
;;
|
||||
|
||||
gnome)
|
||||
open_gnome "$url"
|
||||
;;
|
||||
|
@ -568,6 +926,18 @@ case "$DE" in
|
|||
open_lxde "$url"
|
||||
;;
|
||||
|
||||
enlightenment)
|
||||
open_enlightenment "$url"
|
||||
;;
|
||||
|
||||
cygwin)
|
||||
open_cygwin "$url"
|
||||
;;
|
||||
|
||||
darwin)
|
||||
open_darwin "$url"
|
||||
;;
|
||||
|
||||
generic)
|
||||
open_generic "$url"
|
||||
;;
|
||||
|
|
537
comp/src/gb.desktop/xdg-utils/xdg-screensaver
Normal file → Executable file
537
comp/src/gb.desktop/xdg-utils/xdg-screensaver
Normal file → Executable file
|
@ -35,102 +35,116 @@ manualpage()
|
|||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-screensaver - command line tool for controlling the screensaver
|
||||
xdg-screensaver - command line tool for controlling the
|
||||
screensaver
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-screensaver suspend WindowID
|
||||
xdg-screensaver suspend WindowID
|
||||
|
||||
xdg-screensaver resume WindowID
|
||||
xdg-screensaver resume WindowID
|
||||
|
||||
xdg-screensaver { activate | lock | reset | status }
|
||||
xdg-screensaver { activate | lock | reset | status }
|
||||
|
||||
xdg-screensaver { --help | --manual | --version }
|
||||
xdg-screensaver { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
xdg-screensaver provides commands to control the screensaver.
|
||||
xdg-screensaver provides commands to control the screensaver.
|
||||
|
||||
xdg-screensaver is for use inside a desktop session only. It is not recommended
|
||||
to use xdg-screensaver as root.
|
||||
xdg-screensaver is for use inside a desktop session only. It is
|
||||
not recommended to use xdg-screensaver as root.
|
||||
|
||||
Commands
|
||||
|
||||
suspend WindowID
|
||||
suspend WindowID
|
||||
Suspends the screensaver and monitor power management.
|
||||
WindowID must be the X Window ID of an existing window
|
||||
of the calling application. The window must remain in
|
||||
existence for the duration of the suspension.
|
||||
|
||||
Suspends the screensaver and monitor power management. WindowID must be the
|
||||
X Window ID of an existing window of the calling application. The window
|
||||
must remain in existance for the duration of the suspension.
|
||||
WindowID can be represented as either a decimal number
|
||||
or as a hexadecimal number consisting of the prefix 0x
|
||||
followed by one or more hexadecimal digits.
|
||||
|
||||
WindowID can be represented as either a decimal number or as a hexadecimal
|
||||
number consisting of the prefix 0x followed by one or more hexadecimal
|
||||
digits.
|
||||
The screensaver can be suspended in relation to multiple
|
||||
windows at the same time. In that case screensaver
|
||||
operation is only restored once the screensaver has been
|
||||
resumed in relation to each of the windows
|
||||
|
||||
The screensaver can be suspended in relation to multiple windows at the
|
||||
same time. In that case screensaver operation is only restored once the
|
||||
screensaver has been resumed in relation to each of the windows
|
||||
resume WindowID
|
||||
Resume the screensaver and monitor power management
|
||||
after being suspended. WindowID must be the same X
|
||||
Window ID that was passed to a previous call of
|
||||
xdg-screensaver suspend
|
||||
|
||||
resume WindowID
|
||||
Resume the screensaver and monitor power management after being suspended.
|
||||
WindowID must be the same X Window ID that was passed to a previous call of
|
||||
xdg-screensaver suspend
|
||||
activate
|
||||
Turns the screensaver on immediately. This may result in the screen getting
|
||||
locked, depending on existing system policies.
|
||||
lock
|
||||
Lock the screen immediately.
|
||||
reset
|
||||
Turns the screensaver off immediately. If the screen was locked the user
|
||||
may be asked to authenticate first.
|
||||
status
|
||||
Prints enabled to stdout if the screensaver is enabled to turn on after a
|
||||
period of inactivity and prints disabled if the screensaver is not enabled.
|
||||
activate
|
||||
Turns the screensaver on immediately. This may result in
|
||||
the screen getting locked, depending on existing system
|
||||
policies.
|
||||
|
||||
lock
|
||||
Lock the screen immediately.
|
||||
|
||||
reset
|
||||
Turns the screensaver off immediately. If the screen was
|
||||
locked the user may be asked to authenticate first.
|
||||
|
||||
status
|
||||
Prints enabled to stdout if the screensaver is enabled
|
||||
to turn on after a period of inactivity and prints
|
||||
disabled if the screensaver is not enabled.
|
||||
|
||||
Options
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
--manual
|
||||
Show this manualpage.
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
--help
|
||||
Show command synopsis.
|
||||
|
||||
--manual
|
||||
Show this manual page.
|
||||
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
An exit code of 0 indicates success while a non-zero exit code
|
||||
indicates failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
3
|
||||
A required tool could not be found.
|
||||
4
|
||||
The action failed.
|
||||
1
|
||||
Error in command line syntax.
|
||||
|
||||
3
|
||||
A required tool could not be found.
|
||||
|
||||
4
|
||||
The action failed.
|
||||
|
||||
Examples
|
||||
|
||||
xdg-screensaver suspend 0x1c00007
|
||||
|
||||
Causes the screensaver to be disabled till xdg-screensaver resume 0x1c00007 is
|
||||
called. 0x1c00007 must be the X Window ID of an existing window.
|
||||
|
||||
Causes the screensaver to be disabled till xdg-screensaver
|
||||
resume 0x1c00007 is called. 0x1c00007 must be the X Window ID
|
||||
of an existing window.
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-screensaver - command line tool for controlling the screensaver
|
||||
xdg-screensaver - command line tool for controlling the
|
||||
screensaver
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-screensaver suspend WindowID
|
||||
xdg-screensaver suspend WindowID
|
||||
|
||||
xdg-screensaver resume WindowID
|
||||
xdg-screensaver resume WindowID
|
||||
|
||||
xdg-screensaver { activate | lock | reset | status }
|
||||
xdg-screensaver { activate | lock | reset | status }
|
||||
|
||||
xdg-screensaver { --help | --manual | --version }
|
||||
xdg-screensaver { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
@ -149,6 +163,64 @@ DEBUG()
|
|||
echo "$@" >&2
|
||||
}
|
||||
|
||||
# This handles backslashes but not quote marks.
|
||||
first_word()
|
||||
{
|
||||
read first rest
|
||||
echo "$first"
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a binary to a .desktop file
|
||||
binary_to_desktop_file()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
binary="`which "$1"`"
|
||||
binary="`readlink -f "$binary"`"
|
||||
base="`basename "$binary"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] || continue
|
||||
[ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
|
||||
for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
|
||||
[ -r "$file" ] || continue
|
||||
# Check to make sure it's worth the processing.
|
||||
grep -q "^Exec.*$base" "$file" || continue
|
||||
# Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
|
||||
grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
if [ x"`readlink -f "$command"`" = x"$binary" ]; then
|
||||
# Fix any double slashes that got added path composition
|
||||
echo "$file" | sed -e 's,//*,/,g'
|
||||
return
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# map a .desktop file to a binary
|
||||
## FIXME: handle vendor dir case
|
||||
desktop_file_to_binary()
|
||||
{
|
||||
search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
|
||||
desktop="`basename "$1"`"
|
||||
IFS=:
|
||||
for dir in $search; do
|
||||
unset IFS
|
||||
[ "$dir" ] && [ -d "$dir/applications" ] || continue
|
||||
file="$dir/applications/$desktop"
|
||||
[ -r "$file" ] || continue
|
||||
# Remove any arguments (%F, %f, %U, %u, etc.).
|
||||
command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
|
||||
command="`which "$command"`"
|
||||
readlink -f "$command"
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
|
@ -257,7 +329,7 @@ check_vendor_prefix()
|
|||
[ -n "$file_label" ] || file_label="filename"
|
||||
file=`basename "$1"`
|
||||
case "$file" in
|
||||
[a-zA-Z]*-*)
|
||||
[[:alpha:]]*-*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
@ -279,7 +351,7 @@ check_output_file()
|
|||
fi
|
||||
else
|
||||
DIR=`dirname "$1"`
|
||||
if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
|
||||
if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
|
||||
exit_failure_file_permission_write "no permission to create file '$1'"
|
||||
fi
|
||||
fi
|
||||
|
@ -307,7 +379,7 @@ check_common_commands()
|
|||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-screensaver 1.1.0 rc1"
|
||||
echo "xdg-screensaver 1.1.0 rc3"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
|
@ -331,12 +403,86 @@ fi
|
|||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
|
||||
else DE=""
|
||||
# see https://bugs.freedesktop.org/show_bug.cgi?id=34164
|
||||
unset GREP_OPTIONS
|
||||
|
||||
if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
|
||||
case "${XDG_CURRENT_DESKTOP}" in
|
||||
# only recently added to menu-spec, pre-spec X- still in use
|
||||
Cinnamon|X-Cinnamon)
|
||||
DE=cinnamon;
|
||||
;;
|
||||
ENLIGHTENMENT)
|
||||
DE=enlightenment;
|
||||
;;
|
||||
# GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
|
||||
GNOME*)
|
||||
DE=gnome;
|
||||
;;
|
||||
KDE)
|
||||
DE=kde;
|
||||
;;
|
||||
LXDE)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
XFCE)
|
||||
DE=xfce
|
||||
;;
|
||||
X-Generic)
|
||||
DE=generic
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# classic fallbacks
|
||||
if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
|
||||
elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to checking $DESKTOP_SESSION
|
||||
case "$DESKTOP_SESSION" in
|
||||
gnome)
|
||||
DE=gnome;
|
||||
;;
|
||||
LXDE|Lubuntu)
|
||||
DE=lxde;
|
||||
;;
|
||||
MATE)
|
||||
DE=mate;
|
||||
;;
|
||||
xfce|xfce4|'Xfce Session')
|
||||
DE=xfce;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# fallback to uname output for other platforms
|
||||
case "$(uname 2>/dev/null)" in
|
||||
CYGWIN*)
|
||||
DE=cygwin;
|
||||
;;
|
||||
Darwin)
|
||||
DE=darwin;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ x"$DE" = x"gnome" ]; then
|
||||
# gnome-default-applications-properties is only available in GNOME 2.x
|
||||
# but not in GNOME 3.x
|
||||
which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -347,7 +493,6 @@ detectDE()
|
|||
|
||||
kfmclient_fix_exit_code()
|
||||
{
|
||||
[ x"$KDE_SESSION_VERSION" = x"4" ] && return 0;
|
||||
version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
|
||||
major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
|
||||
minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
|
||||
|
@ -412,33 +557,46 @@ perform_action()
|
|||
fi
|
||||
if [ "$1" = "reset" ] ; then
|
||||
if xset -q | grep 'DPMS is Enabled' > /dev/null 2> /dev/null; then
|
||||
xset -dpms
|
||||
xset +dpms
|
||||
xset dpms force on
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$DE" in
|
||||
kde)
|
||||
if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
|
||||
screensaver_freedesktop "$1"
|
||||
if [ -n "${KDE_SESSION_VERSION}" ]; then
|
||||
screensaver_freedesktop "$1"
|
||||
else
|
||||
screensaver_kde "$1"
|
||||
screensaver_kde3 "$1"
|
||||
fi
|
||||
;;
|
||||
|
||||
gnome_screensaver)
|
||||
screensaver_gnome_screensaver "$1"
|
||||
;;
|
||||
|
||||
mate_screensaver)
|
||||
screensaver_mate_screensaver "$1"
|
||||
;;
|
||||
|
||||
xscreensaver)
|
||||
screensaver_xscreensaver "$1"
|
||||
;;
|
||||
|
||||
'')
|
||||
screensaver_xserver "$1"
|
||||
xautolock_screensaver)
|
||||
xautolock_screensaver "$1"
|
||||
;;
|
||||
|
||||
xfce)
|
||||
[ -n "$DISPLAY" ] && screensaver_xserver "$1"
|
||||
;;
|
||||
|
||||
''|generic)
|
||||
[ -n "$DISPLAY" ] && screensaver_xserver "$1"
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$1" = "suspend" ] ; then
|
||||
if [ -n "$DISPLAY" -a "$1" = "suspend" ] ; then
|
||||
# Save DPMS state
|
||||
if xset -q | grep 'DPMS is Enabled' > /dev/null 2> /dev/null; then
|
||||
test "${TMPDIR+set}" = set || TMPDIR=/tmp
|
||||
|
@ -541,7 +699,7 @@ track_window()
|
|||
echo "$window_id:$xprop_pid" >> $tmpfile
|
||||
$MV "$tmpfile" "$screensaver_file"
|
||||
unlockfile
|
||||
# Wait for xprop to edit, it means that the window disappeared
|
||||
# Wait for xprop to exit, it means that the window disappeared
|
||||
wait $xprop_pid
|
||||
# Clean up the administration and resume the screensaver
|
||||
cleanup_suspend
|
||||
|
@ -625,13 +783,13 @@ screensaver_freedesktop()
|
|||
org.freedesktop.ScreenSaver.GetActive \
|
||||
| grep boolean | cut -d ' ' -f 5`
|
||||
result=$?
|
||||
if [ x"$status" = "xtrue" ]; then
|
||||
if [ x"$status" = "xtrue" -o x"$status" = "xfalse" ]; then
|
||||
echo "enabled"
|
||||
elif [ x"$status" = "xfalse" ]; then
|
||||
echo "disabled"
|
||||
else
|
||||
elif [ x"$result" != "x0" ]; then
|
||||
echo "ERROR: dbus org.freedesktop.ScreenSaver.GetActive returned '$status'" >&2
|
||||
return 1
|
||||
else
|
||||
echo "disabled"
|
||||
fi
|
||||
;;
|
||||
|
||||
|
@ -642,7 +800,7 @@ screensaver_freedesktop()
|
|||
esac
|
||||
}
|
||||
|
||||
screensaver_kde()
|
||||
screensaver_kde3()
|
||||
{
|
||||
case "$1" in
|
||||
suspend)
|
||||
|
@ -763,15 +921,57 @@ screensaver_suspend_loop()
|
|||
|
||||
screensaver_gnome_screensaver()
|
||||
{
|
||||
# TODO
|
||||
# There seems to be a DBUS interface for gnome-screensaver
|
||||
# See http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/2006-April/042579.html and
|
||||
# http://cvs.gnome.org/viewcvs/gnome-screensaver/src/gs-listener-dbus.c?rev=1.36&view=log
|
||||
# A problem seems to be that Inhibit is tied to the lifetime of the DBUS appname and
|
||||
# this can not be used from a script
|
||||
# DBUS interface for gnome-screensaver
|
||||
# http://people.gnome.org/~mccann/gnome-screensaver/docs/gnome-screensaver.html
|
||||
case "$1" in
|
||||
suspend)
|
||||
screensaver_suspend_loop gnome-screensaver-command --poke
|
||||
perl -e '
|
||||
use strict;
|
||||
use warnings;
|
||||
use IO::File;
|
||||
use Net::DBus;
|
||||
use X11::Protocol;
|
||||
|
||||
my ($window_id, $screensaver_file) = @ARGV;
|
||||
|
||||
# Find window name to pass to session manager.
|
||||
my $x = X11::Protocol->new();
|
||||
my $named_window_id = hex($window_id);
|
||||
my $window_name;
|
||||
while (1) {
|
||||
($window_name) = $x->GetProperty($named_window_id, $x->atom("WM_NAME"),
|
||||
$x->atom("STRING"), 0, 1000, 0);
|
||||
last if defined($window_name) && $window_name ne "";
|
||||
(undef, $named_window_id) = $x->QueryTree($named_window_id);
|
||||
if (!defined($named_window_id)) {
|
||||
$window_name = "?";
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
# Inhibit idle detection (flags = 8) with window name and ID.
|
||||
# We have no reason so just send the window name again.
|
||||
my $bus = Net::DBus->session();
|
||||
my $sm_svc = $bus->get_service("org.gnome.SessionManager");
|
||||
my $sm = $sm_svc->get_object("/org/gnome/SessionManager",
|
||||
"org.gnome.SessionManager");
|
||||
$sm->Inhibit($window_name, hex($window_id), $window_name, 8);
|
||||
|
||||
# Wait until removed from the status file.
|
||||
while (1) {
|
||||
sleep(10);
|
||||
my $status = new IO::File($screensaver_file, "r")
|
||||
or exit 0;
|
||||
my $found;
|
||||
while (<$status>) {
|
||||
if (/^$window_id:/) {
|
||||
$found = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
exit 0 unless $found;
|
||||
}
|
||||
' $window_id $screensaver_file &
|
||||
result=0
|
||||
;;
|
||||
|
||||
|
@ -781,29 +981,129 @@ screensaver_gnome_screensaver()
|
|||
;;
|
||||
|
||||
activate)
|
||||
gnome-screensaver-command --activate > /dev/null 2> /dev/null
|
||||
dbus-send --session \
|
||||
--dest=org.gnome.ScreenSaver \
|
||||
--type=method_call \
|
||||
/org/gnome/ScreenSaver \
|
||||
org.gnome.ScreenSaver.SetActive \
|
||||
boolean:true \
|
||||
2> /dev/null
|
||||
result=$?
|
||||
;;
|
||||
|
||||
lock)
|
||||
gnome-screensaver-command --lock > /dev/null 2> /dev/null
|
||||
dbus-send --session \
|
||||
--dest=org.gnome.ScreenSaver \
|
||||
--type=method_call \
|
||||
/org/gnome/ScreenSaver \
|
||||
org.gnome.ScreenSaver.Lock \
|
||||
2> /dev/null
|
||||
result=$?
|
||||
;;
|
||||
|
||||
reset)
|
||||
# Turns the screensaver off right now
|
||||
gnome-screensaver-command --deactivate > /dev/null 2> /dev/null
|
||||
dbus-send --session \
|
||||
--dest=org.gnome.ScreenSaver \
|
||||
--type=method_call \
|
||||
/org/gnome/ScreenSaver \
|
||||
org.gnome.ScreenSaver.SimulateUserActivity \
|
||||
2> /dev/null
|
||||
result=$?
|
||||
;;
|
||||
|
||||
status)
|
||||
result=0
|
||||
if [ -f "$screensaver_file" ] ; then
|
||||
echo "disabled"
|
||||
elif gnome-screensaver-command --query > /dev/null 2> /dev/null; then
|
||||
status=`dbus-send --session \
|
||||
--dest=org.gnome.ScreenSaver \
|
||||
--type=method_call \
|
||||
--print-reply \
|
||||
--reply-timeout=2000 \
|
||||
/org/gnome/ScreenSaver \
|
||||
org.gnome.ScreenSaver.GetActive \
|
||||
| grep boolean | cut -d ' ' -f 5`
|
||||
result=$?
|
||||
if [ x"$status" = "xtrue" -o x"$status" = "xfalse" ]; then
|
||||
echo "enabled"
|
||||
elif [ x"$result" != "x0" ]; then
|
||||
echo "ERROR: dbus org.gnome.ScreenSaver.GetActive returned '$status'" >&2
|
||||
return 1
|
||||
else
|
||||
echo "disabled"
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "ERROR: Unknown command '$1" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
screensaver_mate_screensaver()
|
||||
{
|
||||
# DBUS interface for mate-screensaver
|
||||
# This is same as gnome's for now but may change in the future as MATE
|
||||
# does not follow gnome's developement necessarily.
|
||||
case "$1" in
|
||||
suspend)
|
||||
screensaver_suspend_loop \
|
||||
dbus-send --session \
|
||||
--dest=org.mate.ScreenSaver \
|
||||
--type=method_call \
|
||||
/org/mate/ScreenSaver \
|
||||
org.mate.ScreenSaver.SimulateUserActivity \
|
||||
2> /dev/null
|
||||
result=$?
|
||||
;;
|
||||
|
||||
resume)
|
||||
# Automatic resume when $screensaver_file disappears
|
||||
result=0
|
||||
;;
|
||||
|
||||
activate)
|
||||
dbus-send --session \
|
||||
--dest=org.mate.ScreenSaver \
|
||||
--type=method_call \
|
||||
/org/mate/ScreenSaver \
|
||||
org.mate.ScreenSaver.SetActive \
|
||||
boolean:true \
|
||||
2> /dev/null
|
||||
result=$?
|
||||
;;
|
||||
|
||||
lock)
|
||||
mate-screensaver-command --lock > /dev/null 2> /dev/null
|
||||
result=$?
|
||||
;;
|
||||
|
||||
reset)
|
||||
# Turns the screensaver off right now
|
||||
dbus-send --session \
|
||||
--dest=org.mate.ScreenSaver \
|
||||
--type=method_call \
|
||||
/org/mate/ScreenSaver \
|
||||
org.mate.ScreenSaver.SimulateUserActivity \
|
||||
2> /dev/null
|
||||
result=$?
|
||||
;;
|
||||
|
||||
status)
|
||||
status=`dbus-send --session \
|
||||
--dest=org.mate.ScreenSaver \
|
||||
--type=method_call \
|
||||
--print-reply \
|
||||
--reply-timeout=2000 \
|
||||
/org/mate/ScreenSaver \
|
||||
org.mate.ScreenSaver.GetActive \
|
||||
| grep boolean | cut -d ' ' -f 5`
|
||||
result=$?
|
||||
if [ x"$status" = "xtrue" -o x"$status" = "xfalse" ]; then
|
||||
echo "enabled"
|
||||
elif [ x"$result" != "x0" ]; then
|
||||
echo "ERROR: dbus org.mate.ScreenSaver.GetActive returned '$status'" >&2
|
||||
return 1
|
||||
else
|
||||
# Something is wrong
|
||||
echo "disabled"
|
||||
fi
|
||||
;;
|
||||
|
@ -860,6 +1160,51 @@ screensaver_xscreensaver()
|
|||
esac
|
||||
}
|
||||
|
||||
xautolock_screensaver()
|
||||
{
|
||||
case "$1" in
|
||||
suspend)
|
||||
xset s off && xautolock -disable > /dev/null
|
||||
result=$?
|
||||
;;
|
||||
|
||||
resume)
|
||||
xset s default && xautolock -enable > /dev/null
|
||||
result=$?
|
||||
;;
|
||||
|
||||
activate)
|
||||
xautolock -enable
|
||||
result=$?
|
||||
;;
|
||||
|
||||
lock)
|
||||
xautolock -locknow
|
||||
result=$?
|
||||
;;
|
||||
|
||||
reset)
|
||||
xautolock -restart
|
||||
result=$?
|
||||
;;
|
||||
|
||||
status)
|
||||
xautolock -unlocknow >/dev/null
|
||||
result=$?
|
||||
if [ $result -eq 0 ]; then
|
||||
echo "enabled"
|
||||
else
|
||||
echo "disabled"
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "ERROR: Unknown command '$1" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
[ x"$1" != x"" ] || exit_failure_syntax
|
||||
|
||||
action=
|
||||
|
@ -917,7 +1262,11 @@ detectDE
|
|||
# Consider "xscreensaver" a separate DE
|
||||
xscreensaver-command -version 2> /dev/null | grep XScreenSaver > /dev/null && DE="xscreensaver"
|
||||
# Consider "gnome-screensaver" a separate DE
|
||||
gnome-screensaver-command -q > /dev/null 2>&1 && DE="gnome_screensaver"
|
||||
dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.ScreenSaver > /dev/null 2>&1 && DE="gnome_screensaver"
|
||||
# Consider "mate-screensaver" a separate DE
|
||||
dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.mate.ScreenSaver > /dev/null 2>&1 && DE="mate_screensaver"
|
||||
# Consider "xautolock" a separate DE
|
||||
xautolock -enable > /dev/null 2>&1 && DE="xautolock_screensaver"
|
||||
|
||||
if [ "$action" = "resume" ] ; then
|
||||
do_resume
|
||||
|
|
824
comp/src/gb.desktop/xdg-utils/xdg-settings
Normal file → Executable file
824
comp/src/gb.desktop/xdg-utils/xdg-settings
Normal file → Executable file
File diff suppressed because it is too large
Load diff
|
@ -1,438 +0,0 @@
|
|||
#!/bin/sh
|
||||
#---------------------------------------------
|
||||
# xdg-su
|
||||
#
|
||||
# Utility script to run a command as an alternate user, generally
|
||||
# the root user, with a graphical prompt for the root
|
||||
# password if needed
|
||||
#
|
||||
# Refer to the usage() function below for usage.
|
||||
#
|
||||
# Copyright 2006, Jeremy White <jwhite@codeweavers.com>
|
||||
# Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
|
||||
#
|
||||
# LICENSE:
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the "Software"),
|
||||
# to deal in the Software without restriction, including without limitation
|
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
# and/or sell copies of the Software, and to permit persons to whom the
|
||||
# Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included
|
||||
# in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
# OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
#---------------------------------------------
|
||||
|
||||
manualpage()
|
||||
{
|
||||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-su - run a GUI program as root after prompting for the root password
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-su [-u user] -c command
|
||||
|
||||
xdg-su { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
xdg-su provides a graphical dialog that prompts the user for a password to run
|
||||
command as user or as root if no user was specified.
|
||||
|
||||
xdg-su is for use inside a desktop session only.
|
||||
|
||||
xdg-su discards any stdout and stderr output from command.
|
||||
|
||||
Options
|
||||
|
||||
-u user
|
||||
run command as user. The default is to run as root.
|
||||
--help
|
||||
Show command synopsis.
|
||||
--manual
|
||||
Show this manualpage.
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
2
|
||||
One of the files passed on the command line did not exist.
|
||||
3
|
||||
A required tool could not be found.
|
||||
4
|
||||
The action failed.
|
||||
|
||||
See Also
|
||||
|
||||
su(1)
|
||||
|
||||
Examples
|
||||
|
||||
xdg-su -u root -c "/opt/shinythings/bin/install-GUI --install fast"
|
||||
|
||||
Runs the /opt/shinythings/bin/install-GUI command with root permissions.
|
||||
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-su - run a GUI program as root after prompting for the root password
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-su [-u user] -c command
|
||||
|
||||
xdg-su { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
||||
#@xdg-utils-common@
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Common utility functions included in all XDG wrapper scripts
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
DEBUG()
|
||||
{
|
||||
[ ${XDG_UTILS_DEBUG_LEVEL-0} -lt $1 ] && return 0;
|
||||
shift
|
||||
echo "$@" >&2
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
exit_success()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "$@"
|
||||
echo
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------
|
||||
# Exit script on malformed arguments, not enough arguments
|
||||
# or missing required option.
|
||||
# prints usage information
|
||||
|
||||
exit_failure_syntax()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-su: $@" >&2
|
||||
echo "Try 'xdg-su --help' for more information." >&2
|
||||
else
|
||||
usage
|
||||
echo "Use 'man xdg-su' or 'xdg-su --manual' for additional info."
|
||||
fi
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on missing file specified on command line
|
||||
|
||||
exit_failure_file_missing()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-su: $@" >&2
|
||||
fi
|
||||
|
||||
exit 2
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on failure to locate necessary tool applications
|
||||
|
||||
exit_failure_operation_impossible()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-su: $@" >&2
|
||||
fi
|
||||
|
||||
exit 3
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on failure returned by a tool application
|
||||
|
||||
exit_failure_operation_failed()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-su: $@" >&2
|
||||
fi
|
||||
|
||||
exit 4
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Exit script on insufficient permission to read a specified file
|
||||
|
||||
exit_failure_file_permission_read()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-su: $@" >&2
|
||||
fi
|
||||
|
||||
exit 5
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Exit script on insufficient permission to read a specified file
|
||||
|
||||
exit_failure_file_permission_write()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-su: $@" >&2
|
||||
fi
|
||||
|
||||
exit 6
|
||||
}
|
||||
|
||||
check_input_file()
|
||||
{
|
||||
if [ ! -e "$1" ]; then
|
||||
exit_failure_file_missing "file '$1' does not exist"
|
||||
fi
|
||||
if [ ! -r "$1" ]; then
|
||||
exit_failure_file_permission_read "no permission to read file '$1'"
|
||||
fi
|
||||
}
|
||||
|
||||
check_vendor_prefix()
|
||||
{
|
||||
file=`basename "$1"`
|
||||
case "$file" in
|
||||
[a-zA-Z]*-*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "xdg-su: filename '$file' does not have a proper vendor prefix" >&2
|
||||
echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
|
||||
echo 'with a dash ("-"). An example filename is '"'example-$file'" >&2
|
||||
echo "Use --novendor to override or 'xdg-su --manual' for additional info." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_output_file()
|
||||
{
|
||||
# if the file exists, check if it is writeable
|
||||
# if it does not exists, check if we are allowed to write on the directory
|
||||
if [ -e "$1" ]; then
|
||||
if [ ! -w "$1" ]; then
|
||||
exit_failure_file_permission_write "no permission to write to file '$1'"
|
||||
fi
|
||||
else
|
||||
DIR=`dirname "$1"`
|
||||
if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
|
||||
exit_failure_file_permission_write "no permission to create file '$1'"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#----------------------------------------
|
||||
# Checks for shared commands, e.g. --help
|
||||
|
||||
check_common_commands()
|
||||
{
|
||||
while [ $# -gt 0 ] ; do
|
||||
parm="$1"
|
||||
shift
|
||||
|
||||
case "$parm" in
|
||||
--help)
|
||||
usage
|
||||
echo "Use 'man xdg-su' or 'xdg-su --manual' for additional info."
|
||||
exit_success
|
||||
;;
|
||||
|
||||
--manual)
|
||||
manualpage
|
||||
exit_success
|
||||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-su 1.0beta2"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
check_common_commands "$@"
|
||||
if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
|
||||
# Be silent
|
||||
xdg_redirect_output=" > /dev/null 2> /dev/null"
|
||||
else
|
||||
# All output to stderr
|
||||
xdg_redirect_output=" >&2"
|
||||
fi
|
||||
|
||||
#--------------------------------------
|
||||
# Checks for known desktop environments
|
||||
# set variable DE to the desktop environments name, lowercase
|
||||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
fi
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
su_kde()
|
||||
{
|
||||
if [ x"$KDE_SESSION_VERSION" = x"4" ]; then
|
||||
KDESU=`kde4-config --locate kdesu --path exe 2>/dev/null`
|
||||
else
|
||||
KDESU=`which kdesu 2>/dev/null`
|
||||
fi
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ -z "$user" ] ; then
|
||||
$KDESU -c "$cmd"
|
||||
else
|
||||
$KDESU -u "$user" -c "$cmd"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
su_generic
|
||||
fi
|
||||
}
|
||||
|
||||
su_gnome()
|
||||
{
|
||||
GSU=`which gnomesu 2>/dev/null`
|
||||
if [ $? -ne 0 ] ; then
|
||||
GSU=`which xsu 2>/dev/null`
|
||||
fi
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ -z "$user" ] ; then
|
||||
$GSU -c "$cmd"
|
||||
else
|
||||
$GSU -u "$user" -c "$cmd"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
su_generic
|
||||
fi
|
||||
}
|
||||
|
||||
su_generic()
|
||||
{
|
||||
if [ -z "$user" ] ; then
|
||||
xterm -geom 60x5 -T "xdg-su: $cmd" -e su -c "$cmd"
|
||||
else
|
||||
xterm -geom 60x5 -T "xdg-su: $cmd" -e su -c "$cmd" "$user"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
}
|
||||
|
||||
[ x"$1" != x"" ] || exit_failure_syntax
|
||||
|
||||
user=
|
||||
cmd=
|
||||
while [ $# -gt 0 ] ; do
|
||||
parm="$1"
|
||||
shift
|
||||
|
||||
case "$parm" in
|
||||
-u)
|
||||
if [ -z "$1" ] ; then
|
||||
exit_failure_syntax "user argument missing for -u"
|
||||
fi
|
||||
user="$1"
|
||||
shift
|
||||
;;
|
||||
|
||||
-c)
|
||||
if [ -z "$1" ] ; then
|
||||
exit_failure_syntax "command argument missing for -c"
|
||||
fi
|
||||
cmd="$1"
|
||||
shift
|
||||
;;
|
||||
|
||||
-*)
|
||||
exit_failure_syntax "unexpected option '$parm'"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit_failure_syntax "unexpected argument '$parm'"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "${cmd}" ] ; then
|
||||
exit_failure_syntax "command missing"
|
||||
fi
|
||||
|
||||
detectDE
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
XSU=`which xsu 2>/dev/null`
|
||||
if [ $? -eq 0 ] ; then
|
||||
DE=generic
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$DE" in
|
||||
kde)
|
||||
su_kde
|
||||
;;
|
||||
|
||||
gnome)
|
||||
su_gnome
|
||||
;;
|
||||
|
||||
generic)
|
||||
su_generic
|
||||
;;
|
||||
|
||||
*)
|
||||
[ x"$user" = x"" ] && user=root
|
||||
exit_failure_operation_impossible "no graphical method available for invoking '$cmd' as '$user'"
|
||||
;;
|
||||
esac
|
|
@ -1,484 +0,0 @@
|
|||
#!/bin/sh
|
||||
#---------------------------------------------
|
||||
# xdg-terminal
|
||||
#
|
||||
# Utility script to open the registered terminal emulator
|
||||
#
|
||||
# Refer to the usage() function below for usage.
|
||||
#
|
||||
# Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
|
||||
# Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
|
||||
# Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
|
||||
#
|
||||
# LICENSE:
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a
|
||||
# copy of this software and associated documentation files (the "Software"),
|
||||
# to deal in the Software without restriction, including without limitation
|
||||
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
# and/or sell copies of the Software, and to permit persons to whom the
|
||||
# Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included
|
||||
# in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
# OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
#---------------------------------------------
|
||||
|
||||
manualpage()
|
||||
{
|
||||
cat << _MANUALPAGE
|
||||
Name
|
||||
|
||||
xdg-terminal - opens the user's preferred terminal emulator application
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-terminal [command]
|
||||
|
||||
xdg-terminal { --help | --manual | --version }
|
||||
|
||||
Description
|
||||
|
||||
xdg-terminal opens the user's preferred terminal emulator application. If a
|
||||
command is provided the command will be executed by the shell within the newly
|
||||
opened terminal window.
|
||||
|
||||
xdg-terminal is for use inside a desktop session only. It is not recommended to
|
||||
use xdg-terminal as root.
|
||||
|
||||
Options
|
||||
|
||||
--help
|
||||
Show command synopsis.
|
||||
--manual
|
||||
Show this manualpage.
|
||||
--version
|
||||
Show the xdg-utils version information.
|
||||
|
||||
Exit Codes
|
||||
|
||||
An exit code of 0 indicates success while a non-zero exit code indicates
|
||||
failure. The following failure codes can be returned:
|
||||
|
||||
1
|
||||
Error in command line syntax.
|
||||
3
|
||||
A required tool could not be found.
|
||||
4
|
||||
The action failed.
|
||||
|
||||
Examples
|
||||
|
||||
xdg-terminal
|
||||
|
||||
Opens the user's default terminal emulator, just starting an interactive shell.
|
||||
|
||||
xdg-terminal top
|
||||
|
||||
Opens the user's default terminal emulator and lets it run the top executable.
|
||||
|
||||
_MANUALPAGE
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << _USAGE
|
||||
xdg-terminal - opens the user's preferred terminal emulator application
|
||||
|
||||
Synopsis
|
||||
|
||||
xdg-terminal [command]
|
||||
|
||||
xdg-terminal { --help | --manual | --version }
|
||||
|
||||
_USAGE
|
||||
}
|
||||
|
||||
#@xdg-utils-common@
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Common utility functions included in all XDG wrapper scripts
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
DEBUG()
|
||||
{
|
||||
[ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
|
||||
[ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
|
||||
shift
|
||||
echo "$@" >&2
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on successfully completing the desired operation
|
||||
|
||||
exit_success()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "$@"
|
||||
echo
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
#-----------------------------------------
|
||||
# Exit script on malformed arguments, not enough arguments
|
||||
# or missing required option.
|
||||
# prints usage information
|
||||
|
||||
exit_failure_syntax()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-terminal: $@" >&2
|
||||
echo "Try 'xdg-terminal --help' for more information." >&2
|
||||
else
|
||||
usage
|
||||
echo "Use 'man xdg-terminal' or 'xdg-terminal --manual' for additional info."
|
||||
fi
|
||||
|
||||
exit 1
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on missing file specified on command line
|
||||
|
||||
exit_failure_file_missing()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-terminal: $@" >&2
|
||||
fi
|
||||
|
||||
exit 2
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on failure to locate necessary tool applications
|
||||
|
||||
exit_failure_operation_impossible()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-terminal: $@" >&2
|
||||
fi
|
||||
|
||||
exit 3
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------
|
||||
# Exit script on failure returned by a tool application
|
||||
|
||||
exit_failure_operation_failed()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-terminal: $@" >&2
|
||||
fi
|
||||
|
||||
exit 4
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Exit script on insufficient permission to read a specified file
|
||||
|
||||
exit_failure_file_permission_read()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-terminal: $@" >&2
|
||||
fi
|
||||
|
||||
exit 5
|
||||
}
|
||||
|
||||
#------------------------------------------------------------
|
||||
# Exit script on insufficient permission to write a specified file
|
||||
|
||||
exit_failure_file_permission_write()
|
||||
{
|
||||
if [ $# -gt 0 ]; then
|
||||
echo "xdg-terminal: $@" >&2
|
||||
fi
|
||||
|
||||
exit 6
|
||||
}
|
||||
|
||||
check_input_file()
|
||||
{
|
||||
if [ ! -e "$1" ]; then
|
||||
exit_failure_file_missing "file '$1' does not exist"
|
||||
fi
|
||||
if [ ! -r "$1" ]; then
|
||||
exit_failure_file_permission_read "no permission to read file '$1'"
|
||||
fi
|
||||
}
|
||||
|
||||
check_vendor_prefix()
|
||||
{
|
||||
file_label="$2"
|
||||
[ -n "$file_label" ] || file_label="filename"
|
||||
file=`basename "$1"`
|
||||
case "$file" in
|
||||
[a-zA-Z]*-*)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "xdg-terminal: $file_label '$file' does not have a proper vendor prefix" >&2
|
||||
echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
|
||||
echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2
|
||||
echo "Use --novendor to override or 'xdg-terminal --manual' for additional info." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_output_file()
|
||||
{
|
||||
# if the file exists, check if it is writeable
|
||||
# if it does not exists, check if we are allowed to write on the directory
|
||||
if [ -e "$1" ]; then
|
||||
if [ ! -w "$1" ]; then
|
||||
exit_failure_file_permission_write "no permission to write to file '$1'"
|
||||
fi
|
||||
else
|
||||
DIR=`dirname "$1"`
|
||||
if [ ! -w "$DIR" -o ! -x "$DIR" ]; then
|
||||
exit_failure_file_permission_write "no permission to create file '$1'"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
#----------------------------------------
|
||||
# Checks for shared commands, e.g. --help
|
||||
|
||||
check_common_commands()
|
||||
{
|
||||
while [ $# -gt 0 ] ; do
|
||||
parm="$1"
|
||||
shift
|
||||
|
||||
case "$parm" in
|
||||
--help)
|
||||
usage
|
||||
echo "Use 'man xdg-terminal' or 'xdg-terminal --manual' for additional info."
|
||||
exit_success
|
||||
;;
|
||||
|
||||
--manual)
|
||||
manualpage
|
||||
exit_success
|
||||
;;
|
||||
|
||||
--version)
|
||||
echo "xdg-terminal 1.0.2"
|
||||
exit_success
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
check_common_commands "$@"
|
||||
|
||||
[ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
|
||||
if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
|
||||
# Be silent
|
||||
xdg_redirect_output=" > /dev/null 2> /dev/null"
|
||||
else
|
||||
# All output to stderr
|
||||
xdg_redirect_output=" >&2"
|
||||
fi
|
||||
|
||||
#--------------------------------------
|
||||
# Checks for known desktop environments
|
||||
# set variable DE to the desktop environments name, lowercase
|
||||
|
||||
detectDE()
|
||||
{
|
||||
if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
|
||||
elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
|
||||
elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
|
||||
elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
|
||||
elif [ x"$DESKTOP_SESSION" == x"LXDE" ]; then DE=lxde;
|
||||
else DE=""
|
||||
fi
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
|
||||
# It also always returns 1 in KDE 3.4 and earlier
|
||||
# Simply return 0 in such case
|
||||
|
||||
kfmclient_fix_exit_code()
|
||||
{
|
||||
version=`kde${KDE_SESSION_VERSION}-config --version 2>/dev/null | grep '^KDE'`
|
||||
major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
|
||||
minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
|
||||
release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
|
||||
test "$major" -gt 3 && return $1
|
||||
test "$minor" -gt 5 && return $1
|
||||
test "$release" -gt 4 && return $1
|
||||
return 0
|
||||
}
|
||||
|
||||
terminal_kde()
|
||||
{
|
||||
terminal=`kreadconfig --file kdeglobals --group General --key TerminalApplication --default konsole`
|
||||
|
||||
terminal_exec=`which $terminal 2>/dev/null`
|
||||
|
||||
if [ -x "$terminal_exec" ]; then
|
||||
if [ x"$1" == x"" ]; then
|
||||
$terminal_exec
|
||||
else
|
||||
$terminal_exec -e "$1"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible "configured terminal program '$terminal' not found or not executable"
|
||||
fi
|
||||
}
|
||||
|
||||
terminal_gnome()
|
||||
{
|
||||
term_exec_key="/desktop/gnome/applications/terminal/exec"
|
||||
term_exec_arg_key="/desktop/gnome/applications/terminal/exec_arg"
|
||||
|
||||
term_exec=`gconftool-2 --get ${term_exec_key}`
|
||||
term_exec_arg=`gconftool-2 --get ${term_exec_arg_key}`
|
||||
|
||||
terminal_exec=`which $term_exec 2>/dev/null`
|
||||
|
||||
if [ -x "$terminal_exec" ]; then
|
||||
if [ x"$1" == x"" ]; then
|
||||
$terminal_exec
|
||||
else
|
||||
if [ x"$term_exec_arg" == x"" ]; then
|
||||
$terminal_exec "$1"
|
||||
else
|
||||
$terminal_exec "$term_exec_arg" "$1"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible "configured terminal program '$term_exec' not found or not executable"
|
||||
fi
|
||||
}
|
||||
|
||||
terminal_xfce()
|
||||
{
|
||||
if [ x"$1" == x"" ]; then
|
||||
exo-open --launch TerminalEmulator
|
||||
else
|
||||
exo-open --launch TerminalEmulator "$1"
|
||||
fi
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
}
|
||||
|
||||
terminal_generic()
|
||||
{
|
||||
# if $TERM is not set, try xterm
|
||||
if [ x"$TERM" == x"" ]; then
|
||||
TERM=xterm
|
||||
fi
|
||||
|
||||
terminal_exec=`which $TERM >/dev/null 2>/dev/null`
|
||||
|
||||
if [ -x "$terminal_exec" ]; then
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_success
|
||||
else
|
||||
exit_failure_operation_failed
|
||||
fi
|
||||
else
|
||||
exit_failure_operation_impossible "configured terminal program '$TERM' not found or not executable"
|
||||
fi
|
||||
}
|
||||
|
||||
terminal_lxde()
|
||||
{
|
||||
if which lxterminal &>/dev/null; then
|
||||
if [ x"$1" == x"" ]; then
|
||||
lxterminal
|
||||
else
|
||||
lxterminal -e "$1"
|
||||
fi
|
||||
else
|
||||
terminal_generic "$1"
|
||||
fi
|
||||
}
|
||||
|
||||
#[ x"$1" != x"" ] || exit_failure_syntax
|
||||
|
||||
command=
|
||||
while [ $# -gt 0 ] ; do
|
||||
parm="$1"
|
||||
shift
|
||||
|
||||
case "$parm" in
|
||||
-*)
|
||||
exit_failure_syntax "unexpected option '$parm'"
|
||||
;;
|
||||
|
||||
*)
|
||||
if [ -n "$command" ] ; then
|
||||
exit_failure_syntax "unexpected argument '$parm'"
|
||||
fi
|
||||
command="$parm"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
detectDE
|
||||
|
||||
if [ x"$DE" = x"" ]; then
|
||||
# if TERM variable is not set, try xterm
|
||||
if [ x"$TERM" = x"" ]; then
|
||||
TERM=xterm
|
||||
fi
|
||||
DE=generic
|
||||
fi
|
||||
|
||||
case "$DE" in
|
||||
kde)
|
||||
terminal_kde "$command"
|
||||
;;
|
||||
|
||||
gnome)
|
||||
terminal_gnome "$command"
|
||||
;;
|
||||
|
||||
xfce)
|
||||
terminal_xfce "$command"
|
||||
;;
|
||||
|
||||
lxde)
|
||||
terminal_lxde "$command"
|
||||
;;
|
||||
|
||||
generic)
|
||||
terminal_generic "$command"
|
||||
;;
|
||||
|
||||
*)
|
||||
exit_failure_operation_impossible "no terminal emulator available"
|
||||
;;
|
||||
esac
|
Loading…
Reference in a new issue