Advertisement
Guest User

Untitled

a guest
Aug 25th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.61 KB | None | 0 0
  1. #!/bin/sh
  2. #---------------------------------------------
  3. # xdg-open
  4. #
  5. # Utility script to open a URL in the registered default application.
  6. #
  7. # Refer to the usage() function below for usage.
  8. #
  9. # Copyright 2009-2010, Fathi Boudra <fabo@freedesktop.org>
  10. # Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
  11. # Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
  12. # Copyright 2006, Jeremy White <jwhite@codeweavers.com>
  13. #
  14. # LICENSE:
  15. #
  16. # Permission is hereby granted, free of charge, to any person obtaining a
  17. # copy of this software and associated documentation files (the "Software"),
  18. # to deal in the Software without restriction, including without limitation
  19. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  20. # and/or sell copies of the Software, and to permit persons to whom the
  21. # Software is furnished to do so, subject to the following conditions:
  22. #
  23. # The above copyright notice and this permission notice shall be included
  24. # in all copies or substantial portions of the Software.
  25. #
  26. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  27. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  28. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  29. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  30. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  31. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  32. # OTHER DEALINGS IN THE SOFTWARE.
  33. #
  34. #---------------------------------------------
  35.  
  36. manualpage()
  37. {
  38. cat << _MANUALPAGE
  39. Name
  40.  
  41. xdg-open -- opens a file or URL in the user's preferred
  42. application
  43.  
  44. Synopsis
  45.  
  46. xdg-open { file | URL }
  47.  
  48. xdg-open { --help | --manual | --version }
  49.  
  50. Description
  51.  
  52. xdg-open opens a file or URL in the user's preferred
  53. application. If a URL is provided the URL will be opened in the
  54. user's preferred web browser. If a file is provided the file
  55. will be opened in the preferred application for files of that
  56. type. xdg-open supports file, ftp, http and https URLs.
  57.  
  58. xdg-open is for use inside a desktop session only. It is not
  59. recommended to use xdg-open as root.
  60.  
  61. Options
  62.  
  63. --help
  64. Show command synopsis.
  65.  
  66. --manual
  67. Show this manual page.
  68.  
  69. --version
  70. Show the xdg-utils version information.
  71.  
  72. Exit Codes
  73.  
  74. An exit code of 0 indicates success while a non-zero exit code
  75. indicates failure. The following failure codes can be returned:
  76.  
  77. 1
  78. Error in command line syntax.
  79.  
  80. 2
  81. One of the files passed on the command line did not
  82. exist.
  83.  
  84. 3
  85. A required tool could not be found.
  86.  
  87. 4
  88. The action failed.
  89.  
  90. See Also
  91.  
  92. xdg-mime(1), xdg-settings(1), MIME applications associations
  93. specification
  94.  
  95. Examples
  96.  
  97. xdg-open 'http://www.freedesktop.org/'
  98.  
  99. Opens the freedesktop.org website in the user's default
  100. browser.
  101.  
  102. xdg-open /tmp/foobar.png
  103.  
  104. Opens the PNG image file /tmp/foobar.png in the user's default
  105. image viewing application.
  106. _MANUALPAGE
  107. }
  108.  
  109. usage()
  110. {
  111. cat << _USAGE
  112. xdg-open -- opens a file or URL in the user's preferred
  113. application
  114.  
  115. Synopsis
  116.  
  117. xdg-open { file | URL }
  118.  
  119. xdg-open { --help | --manual | --version }
  120.  
  121. _USAGE
  122. }
  123.  
  124. #@xdg-utils-common@
  125.  
  126. #----------------------------------------------------------------------------
  127. # Common utility functions included in all XDG wrapper scripts
  128. #----------------------------------------------------------------------------
  129.  
  130. DEBUG()
  131. {
  132. [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
  133. [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
  134. shift
  135. echo "$@" >&2
  136. }
  137.  
  138. # This handles backslashes but not quote marks.
  139. first_word()
  140. {
  141. read first rest
  142. echo "$first"
  143. }
  144.  
  145. #-------------------------------------------------------------
  146. # map a binary to a .desktop file
  147. binary_to_desktop_file()
  148. {
  149. search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
  150. binary="`which "$1"`"
  151. binary="`readlink -f "$binary"`"
  152. base="`basename "$binary"`"
  153. IFS=:
  154. for dir in $search; do
  155. unset IFS
  156. [ "$dir" ] || continue
  157. [ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
  158. for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
  159. [ -r "$file" ] || continue
  160. # Check to make sure it's worth the processing.
  161. grep -q "^Exec.*$base" "$file" || continue
  162. # Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
  163. grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
  164. command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
  165. command="`which "$command"`"
  166. if [ x"`readlink -f "$command"`" = x"$binary" ]; then
  167. # Fix any double slashes that got added path composition
  168. echo "$file" | sed -e 's,//*,/,g'
  169. return
  170. fi
  171. done
  172. done
  173. }
  174.  
  175. #-------------------------------------------------------------
  176. # map a .desktop file to a binary
  177. ## FIXME: handle vendor dir case
  178. desktop_file_to_binary()
  179. {
  180. search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
  181. desktop="`basename "$1"`"
  182. IFS=:
  183. for dir in $search; do
  184. unset IFS
  185. [ "$dir" ] && [ -d "$dir/applications" ] || continue
  186. file="$dir/applications/$desktop"
  187. [ -r "$file" ] || continue
  188. # Remove any arguments (%F, %f, %U, %u, etc.).
  189. command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
  190. command="`which "$command"`"
  191. readlink -f "$command"
  192. return
  193. done
  194. }
  195.  
  196. #-------------------------------------------------------------
  197. # Exit script on successfully completing the desired operation
  198.  
  199. exit_success()
  200. {
  201. if [ $# -gt 0 ]; then
  202. echo "$@"
  203. echo
  204. fi
  205.  
  206. exit 0
  207. }
  208.  
  209.  
  210. #-----------------------------------------
  211. # Exit script on malformed arguments, not enough arguments
  212. # or missing required option.
  213. # prints usage information
  214.  
  215. exit_failure_syntax()
  216. {
  217. if [ $# -gt 0 ]; then
  218. echo "xdg-open: $@" >&2
  219. echo "Try 'xdg-open --help' for more information." >&2
  220. else
  221. usage
  222. echo "Use 'man xdg-open' or 'xdg-open --manual' for additional info."
  223. fi
  224.  
  225. exit 1
  226. }
  227.  
  228. #-------------------------------------------------------------
  229. # Exit script on missing file specified on command line
  230.  
  231. exit_failure_file_missing()
  232. {
  233. if [ $# -gt 0 ]; then
  234. echo "xdg-open: $@" >&2
  235. fi
  236.  
  237. exit 2
  238. }
  239.  
  240. #-------------------------------------------------------------
  241. # Exit script on failure to locate necessary tool applications
  242.  
  243. exit_failure_operation_impossible()
  244. {
  245. if [ $# -gt 0 ]; then
  246. echo "xdg-open: $@" >&2
  247. fi
  248.  
  249. exit 3
  250. }
  251.  
  252. #-------------------------------------------------------------
  253. # Exit script on failure returned by a tool application
  254.  
  255. exit_failure_operation_failed()
  256. {
  257. if [ $# -gt 0 ]; then
  258. echo "xdg-open: $@" >&2
  259. fi
  260.  
  261. exit 4
  262. }
  263.  
  264. #------------------------------------------------------------
  265. # Exit script on insufficient permission to read a specified file
  266.  
  267. exit_failure_file_permission_read()
  268. {
  269. if [ $# -gt 0 ]; then
  270. echo "xdg-open: $@" >&2
  271. fi
  272.  
  273. exit 5
  274. }
  275.  
  276. #------------------------------------------------------------
  277. # Exit script on insufficient permission to write a specified file
  278.  
  279. exit_failure_file_permission_write()
  280. {
  281. if [ $# -gt 0 ]; then
  282. echo "xdg-open: $@" >&2
  283. fi
  284.  
  285. exit 6
  286. }
  287.  
  288. check_input_file()
  289. {
  290. if [ ! -e "$1" ]; then
  291. exit_failure_file_missing "file '$1' does not exist"
  292. fi
  293. if [ ! -r "$1" ]; then
  294. exit_failure_file_permission_read "no permission to read file '$1'"
  295. fi
  296. }
  297.  
  298. check_vendor_prefix()
  299. {
  300. file_label="$2"
  301. [ -n "$file_label" ] || file_label="filename"
  302. file=`basename "$1"`
  303. case "$file" in
  304. [[:alpha:]]*-*)
  305. return
  306. ;;
  307. esac
  308.  
  309. echo "xdg-open: $file_label '$file' does not have a proper vendor prefix" >&2
  310. echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
  311. echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2
  312. echo "Use --novendor to override or 'xdg-open --manual' for additional info." >&2
  313. exit 1
  314. }
  315.  
  316. check_output_file()
  317. {
  318. # if the file exists, check if it is writeable
  319. # if it does not exists, check if we are allowed to write on the directory
  320. if [ -e "$1" ]; then
  321. if [ ! -w "$1" ]; then
  322. exit_failure_file_permission_write "no permission to write to file '$1'"
  323. fi
  324. else
  325. DIR=`dirname "$1"`
  326. if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
  327. exit_failure_file_permission_write "no permission to create file '$1'"
  328. fi
  329. fi
  330. }
  331.  
  332. #----------------------------------------
  333. # Checks for shared commands, e.g. --help
  334.  
  335. check_common_commands()
  336. {
  337. while [ $# -gt 0 ] ; do
  338. parm="$1"
  339. shift
  340.  
  341. case "$parm" in
  342. --help)
  343. usage
  344. echo "Use 'man xdg-open' or 'xdg-open --manual' for additional info."
  345. exit_success
  346. ;;
  347.  
  348. --manual)
  349. manualpage
  350. exit_success
  351. ;;
  352.  
  353. --version)
  354. echo "xdg-open 1.1.0 rc3"
  355. exit_success
  356. ;;
  357. esac
  358. done
  359. }
  360.  
  361. check_common_commands "$@"
  362. + check_common_commands http://ya.ru
  363. + '[' 1 -gt 0 ']'
  364. + parm=http://ya.ru
  365. + shift
  366. + case "$parm" in
  367. + '[' 0 -gt 0 ']'
  368.  
  369. [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
  370. + '[' -z '' ']'
  371. + unset XDG_UTILS_DEBUG_LEVEL
  372. if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
  373. # Be silent
  374. xdg_redirect_output=" > /dev/null 2> /dev/null"
  375. else
  376. # All output to stderr
  377. xdg_redirect_output=" >&2"
  378. fi
  379. + '[' 0 -lt 1 ']'
  380. + xdg_redirect_output=' > /dev/null 2> /dev/null'
  381.  
  382. #--------------------------------------
  383. # Checks for known desktop environments
  384. # set variable DE to the desktop environments name, lowercase
  385.  
  386. detectDE()
  387. {
  388. # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
  389. unset GREP_OPTIONS
  390.  
  391. if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
  392. case "${XDG_CURRENT_DESKTOP}" in
  393. # only recently added to menu-spec, pre-spec X- still in use
  394. Cinnamon|X-Cinnamon)
  395. DE=cinnamon;
  396. ;;
  397. ENLIGHTENMENT)
  398. DE=enlightenment;
  399. ;;
  400. # GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
  401. GNOME*)
  402. DE=gnome;
  403. ;;
  404. KDE)
  405. DE=kde;
  406. ;;
  407. LXDE)
  408. DE=lxde;
  409. ;;
  410. MATE)
  411. DE=mate;
  412. ;;
  413. XFCE)
  414. DE=xfce
  415. ;;
  416. X-Generic)
  417. DE=generic
  418. ;;
  419. esac
  420. fi
  421.  
  422. if [ x"$DE" = x"" ]; then
  423. # classic fallbacks
  424. if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
  425. elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
  426. elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
  427. 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;
  428. elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
  429. elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
  430. elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
  431. fi
  432. fi
  433.  
  434. if [ x"$DE" = x"" ]; then
  435. # fallback to checking $DESKTOP_SESSION
  436. case "$DESKTOP_SESSION" in
  437. gnome)
  438. DE=gnome;
  439. ;;
  440. LXDE|Lubuntu)
  441. DE=lxde;
  442. ;;
  443. MATE)
  444. DE=mate;
  445. ;;
  446. xfce|xfce4|'Xfce Session')
  447. DE=xfce;
  448. ;;
  449. esac
  450. fi
  451.  
  452. if [ x"$DE" = x"" ]; then
  453. # fallback to uname output for other platforms
  454. case "$(uname 2>/dev/null)" in
  455. CYGWIN*)
  456. DE=cygwin;
  457. ;;
  458. Darwin)
  459. DE=darwin;
  460. ;;
  461. esac
  462. fi
  463.  
  464. if [ x"$DE" = x"gnome" ]; then
  465. # gnome-default-applications-properties is only available in GNOME 2.x
  466. # but not in GNOME 3.x
  467. which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
  468. fi
  469. }
  470.  
  471. #----------------------------------------------------------------------------
  472. # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
  473. # It also always returns 1 in KDE 3.4 and earlier
  474. # Simply return 0 in such case
  475.  
  476. kfmclient_fix_exit_code()
  477. {
  478. version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
  479. major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
  480. minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
  481. release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
  482. test "$major" -gt 3 && return $1
  483. test "$minor" -gt 5 && return $1
  484. test "$release" -gt 4 && return $1
  485. return 0
  486. }
  487.  
  488. # This handles backslashes but not quote marks.
  489. last_word()
  490. {
  491. read first rest
  492. echo "$rest"
  493. }
  494.  
  495. # Get the value of a key in a desktop file's Desktop Entry group.
  496. # Example: Use get_key foo.desktop Exec
  497. # to get the values of the Exec= key for the Desktop Entry group.
  498. get_key()
  499. {
  500. local file="${1}"
  501. local key="${2}"
  502. local desktop_entry=""
  503.  
  504. IFS_="${IFS}"
  505. IFS=""
  506. while read line
  507. do
  508. case "$line" in
  509. "[Desktop Entry]")
  510. desktop_entry="y"
  511. ;;
  512. # Reset match flag for other groups
  513. "["*)
  514. desktop_entry=""
  515. ;;
  516. "${key}="*)
  517. # Only match Desktop Entry group
  518. if [ -n "${desktop_entry}" ]
  519. then
  520. echo "${line}" | cut -d= -f 2-
  521. fi
  522. esac
  523. done < "${file}"
  524. IFS="${IFS_}"
  525. }
  526.  
  527. # Returns true if argument is a file:// URL or path
  528. is_file_url_or_path()
  529. {
  530. if echo "$1" | grep -q '^file://' \
  531. || ! echo "$1" | egrep -q '^[[:alpha:]+\.\-]+:'; then
  532. return 0
  533. else
  534. return 1
  535. fi
  536. }
  537.  
  538. # If argument is a file URL, convert it to a (percent-decoded) path.
  539. # If not, leave it as it is.
  540. file_url_to_path()
  541. {
  542. local file="$1"
  543. if echo "$file" | grep -q '^file:///'; then
  544. file=${file#file://}
  545. file=${file%%#*}
  546. file=$(echo "$file" | sed -r 's/\?.*$//')
  547. local printf=printf
  548. if [ -x /usr/bin/printf ]; then
  549. printf=/usr/bin/printf
  550. fi
  551. file=$($printf "$(echo "$file" | sed -e 's@%\([a-f0-9A-F]\{2\}\)@\\x\1@g')")
  552. fi
  553. echo "$file"
  554. }
  555.  
  556. open_cygwin()
  557. {
  558. cygstart "$1"
  559.  
  560. if [ $? -eq 0 ]; then
  561. exit_success
  562. else
  563. exit_failure_operation_failed
  564. fi
  565. }
  566.  
  567. open_darwin()
  568. {
  569. open "$1"
  570.  
  571. if [ $? -eq 0 ]; then
  572. exit_success
  573. else
  574. exit_failure_operation_failed
  575. fi
  576. }
  577.  
  578. open_kde()
  579. {
  580. if [ -n "${KDE_SESSION_VERSION}" ]; then
  581. case "${KDE_SESSION_VERSION}" in
  582. 4)
  583. kde-open "$1"
  584. ;;
  585. 5)
  586. kde-open${KDE_SESSION_VERSION} "$1"
  587. ;;
  588. esac
  589. else
  590. kfmclient exec "$1"
  591. kfmclient_fix_exit_code $?
  592. fi
  593.  
  594. if [ $? -eq 0 ]; then
  595. exit_success
  596. else
  597. exit_failure_operation_failed
  598. fi
  599. }
  600.  
  601. open_gnome3()
  602. {
  603. if gvfs-open --help >/dev/null 2>&1; then
  604. gvfs-open "$1"
  605. else
  606. open_generic "$1"
  607. fi
  608.  
  609. if [ $? -eq 0 ]; then
  610. exit_success
  611. else
  612. exit_failure_operation_failed
  613. fi
  614. }
  615.  
  616. open_gnome()
  617. {
  618. if gvfs-open --help >/dev/null 2>&1; then
  619. gvfs-open "$1"
  620. elif gnome-open --help >/dev/null 2>&1; then
  621. gnome-open "$1"
  622. else
  623. open_generic "$1"
  624. fi
  625.  
  626. if [ $? -eq 0 ]; then
  627. exit_success
  628. else
  629. exit_failure_operation_failed
  630. fi
  631. }
  632.  
  633. open_mate()
  634. {
  635. if gvfs-open --help 2>/dev/null 1>&2; then
  636. gvfs-open "$1"
  637. else
  638. mate-open "$1"
  639. fi
  640.  
  641. if [ $? -eq 0 ]; then
  642. exit_success
  643. else
  644. exit_failure_operation_failed
  645. fi
  646. }
  647.  
  648. open_xfce()
  649. {
  650. exo-open "$1"
  651.  
  652. if [ $? -eq 0 ]; then
  653. exit_success
  654. else
  655. exit_failure_operation_failed
  656. fi
  657. }
  658.  
  659. open_enlightenment()
  660. {
  661. enlightenment_open "$1"
  662.  
  663. if [ $? -eq 0 ]; then
  664. exit_success
  665. else
  666. exit_failure_operation_failed
  667. fi
  668. }
  669.  
  670. #-----------------------------------------
  671. # Recursively search .desktop file
  672.  
  673. search_desktop_file()
  674. {
  675. local default="$1"
  676. local dir="$2"
  677. local target="$3"
  678.  
  679. local file=""
  680. # look for both vendor-app.desktop, vendor/app.desktop
  681. if [ -r "$dir/$default" ]; then
  682. file="$dir/$default"
  683. elif [ -r "$dir/`echo $default | sed -e 's|-|/|'`" ]; then
  684. file="$dir/`echo $default | sed -e 's|-|/|'`"
  685. fi
  686.  
  687. if [ -r "$file" ] ; then
  688. command="$(get_key "${file}" "Exec" | first_word)"
  689. command_exec=`which $command 2>/dev/null`
  690. icon="$(get_key "${file}" "Icon")"
  691. # FIXME: Actually LC_MESSAGES should be used as described in
  692. # http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s04.html
  693. localised_name="$(get_key "${file}" "Name")"
  694. set -- $(get_key "${file}" "Exec" | last_word)
  695. # We need to replace any occurrence of "%f", "%F" and
  696. # the like by the target file. We examine each
  697. # argument and append the modified argument to the
  698. # end then shift.
  699. local args=$#
  700. local replaced=0
  701. while [ $args -gt 0 ]; do
  702. case $1 in
  703. %[c])
  704. replaced=1
  705. arg="${localised_name}"
  706. shift
  707. set -- "$@" "$arg"
  708. ;;
  709. %[fFuU])
  710. replaced=1
  711. arg="$target"
  712. shift
  713. set -- "$@" "$arg"
  714. ;;
  715. %[i])
  716. replaced=1
  717. shift
  718. set -- "$@" "--icon" "$icon"
  719. ;;
  720. *)
  721. arg="$1"
  722. shift
  723. set -- "$@" "$arg"
  724. ;;
  725. esac
  726. args=$(( $args - 1 ))
  727. done
  728. [ $replaced -eq 1 ] || set -- "$@" "$target"
  729. "$command_exec" "$@"
  730.  
  731. if [ $? -eq 0 ]; then
  732. exit_success
  733. fi
  734. fi
  735.  
  736. for d in $dir/*/; do
  737. [ -d "$d" ] && search_desktop_file "$default" "$d" "$target"
  738. done
  739. }
  740.  
  741.  
  742. open_generic_xdg_mime()
  743. {
  744. filetype="$2"
  745. default=`xdg-mime query default "$filetype"`
  746. if [ -n "$default" ] ; then
  747. xdg_user_dir="$XDG_DATA_HOME"
  748. [ -n "$xdg_user_dir" ] || xdg_user_dir="$HOME/.local/share"
  749.  
  750. xdg_system_dirs="$XDG_DATA_DIRS"
  751. [ -n "$xdg_system_dirs" ] || xdg_system_dirs=/usr/local/share/:/usr/share/
  752.  
  753. DEBUG 3 "$xdg_user_dir:$xdg_system_dirs"
  754. for x in `echo "$xdg_user_dir:$xdg_system_dirs" | sed 's/:/ /g'`; do
  755. search_desktop_file "$default" "$x/applications/" "$1"
  756. done
  757. fi
  758. }
  759.  
  760. open_generic_xdg_file_mime()
  761. {
  762. filetype=`xdg-mime query filetype "$1" | sed "s/;.*//"`
  763. open_generic_xdg_mime "$1" "$filetype"
  764. }
  765.  
  766. open_generic_xdg_x_scheme_handler()
  767. {
  768. scheme="`echo $1 | sed -n 's/\(^[[:alnum:]+\.-]*\):.*$/\1/p'`"
  769. if [ -n $scheme ]; then
  770. filetype="x-scheme-handler/$scheme"
  771. open_generic_xdg_mime "$1" "$filetype"
  772. fi
  773. }
  774.  
  775. open_envvar()
  776. {
  777. local oldifs="$IFS"
  778. local browser browser_with_arg
  779.  
  780. IFS=":"
  781. for browser in $BROWSER; do
  782. IFS="$oldifs"
  783.  
  784. if [ -z "$browser" ]; then
  785. continue
  786. fi
  787.  
  788. if echo "$browser" | grep -q %s; then
  789. $(printf "$browser" "$1")
  790. else
  791. $browser "$1"
  792. fi
  793.  
  794. if [ $? -eq 0 ]; then
  795. exit_success
  796. fi
  797. done
  798. }
  799.  
  800. open_generic()
  801. {
  802. if is_file_url_or_path "$1"; then
  803. local file="$(file_url_to_path "$1")"
  804.  
  805. check_input_file "$file"
  806.  
  807. if [ -n "$DISPLAY" ]; then
  808. filetype=`xdg-mime query filetype "$file" | sed "s/;.*//"`
  809. open_generic_xdg_mime "$file" "$filetype"
  810. fi
  811.  
  812. if which run-mailcap 2>/dev/null 1>&2; then
  813. run-mailcap --action=view "$file"
  814. if [ $? -eq 0 ]; then
  815. exit_success
  816. fi
  817. fi
  818.  
  819. if [ -n "$DISPLAY" ] && mimeopen -v 2>/dev/null 1>&2; then
  820. mimeopen -L -n "$file"
  821. if [ $? -eq 0 ]; then
  822. exit_success
  823. fi
  824. fi
  825. fi
  826.  
  827. if [ -n "$BROWSER" ]; then
  828. open_envvar "$1"
  829. fi
  830.  
  831. if [ -n "$DISPLAY" ]; then
  832. open_generic_xdg_x_scheme_handler "$1"
  833. fi
  834.  
  835. # if BROWSER variable is not set, check some well known browsers instead
  836. if [ x"$BROWSER" = x"" ]; then
  837. BROWSER=www-browser:links2:elinks:links:lynx:w3m
  838. if [ -n "$DISPLAY" ]; then
  839. BROWSER=x-www-browser:firefox:iceweasel:seamonkey:mozilla:epiphany:konqueror:chromium:google-chrome:$BROWSER
  840. fi
  841. fi
  842.  
  843. open_envvar "$1"
  844.  
  845. exit_failure_operation_impossible "no method available for opening '$1'"
  846. }
  847.  
  848. open_lxde()
  849. {
  850. # pcmanfm only knows how to handle file:// urls and filepaths, it seems.
  851. if is_file_url_or_path "$1"; then
  852. local file="$(file_url_to_path "$1")"
  853.  
  854. # handle relative paths
  855. if ! echo "$file" | grep -q ^/; then
  856. file="$(pwd)/$file"
  857. fi
  858.  
  859. pcmanfm "$file"
  860. else
  861. open_generic "$1"
  862. fi
  863.  
  864. if [ $? -eq 0 ]; then
  865. exit_success
  866. else
  867. exit_failure_operation_failed
  868. fi
  869. }
  870.  
  871. [ x"$1" != x"" ] || exit_failure_syntax
  872. + '[' xhttp://ya.ru '!=' x ']'
  873.  
  874. url=
  875. + url=
  876. while [ $# -gt 0 ] ; do
  877. parm="$1"
  878. shift
  879.  
  880. case "$parm" in
  881. -*)
  882. exit_failure_syntax "unexpected option '$parm'"
  883. ;;
  884.  
  885. *)
  886. if [ -n "$url" ] ; then
  887. exit_failure_syntax "unexpected argument '$parm'"
  888. fi
  889. url="$parm"
  890. ;;
  891. esac
  892. done
  893. + '[' 1 -gt 0 ']'
  894. + parm=http://ya.ru
  895. + shift
  896. + case "$parm" in
  897. + '[' -n '' ']'
  898. + url=http://ya.ru
  899. + '[' 0 -gt 0 ']'
  900.  
  901. if [ -z "${url}" ] ; then
  902. exit_failure_syntax "file or URL argument missing"
  903. fi
  904. + '[' -z http://ya.ru ']'
  905.  
  906. detectDE
  907. + detectDE
  908. + unset GREP_OPTIONS
  909. + '[' -n LXDE ']'
  910. + case "${XDG_CURRENT_DESKTOP}" in
  911. + DE=lxde
  912. + '[' xlxde = x ']'
  913. + '[' xlxde = x ']'
  914. + '[' xlxde = x ']'
  915. + '[' xlxde = xgnome ']'
  916.  
  917. if [ x"$DE" = x"" ]; then
  918. DE=generic
  919. fi
  920. + '[' xlxde = x ']'
  921.  
  922. DEBUG 2 "Selected DE $DE"
  923. + DEBUG 2 'Selected DE lxde'
  924. + '[' -z '' ']'
  925. + return 0
  926.  
  927. # sanitize BROWSER (avoid caling ourselves in particular)
  928. case "${BROWSER}" in
  929. *:"xdg-open"|"xdg-open":*)
  930. BROWSER=$(echo $BROWSER | sed -e 's|:xdg-open||g' -e 's|xdg-open:||g')
  931. ;;
  932. "xdg-open")
  933. BROWSER=
  934. ;;
  935. esac
  936. + case "${BROWSER}" in
  937.  
  938. case "$DE" in
  939. kde)
  940. open_kde "$url"
  941. ;;
  942.  
  943. gnome3|cinnamon)
  944. open_gnome3 "$url"
  945. ;;
  946.  
  947. gnome)
  948. open_gnome "$url"
  949. ;;
  950.  
  951. mate)
  952. open_mate "$url"
  953. ;;
  954.  
  955. xfce)
  956. open_xfce "$url"
  957. ;;
  958.  
  959. lxde)
  960. open_lxde "$url"
  961. ;;
  962.  
  963. enlightenment)
  964. open_enlightenment "$url"
  965. ;;
  966.  
  967. cygwin)
  968. open_cygwin "$url"
  969. ;;
  970.  
  971. darwin)
  972. open_darwin "$url"
  973. ;;
  974.  
  975. generic)
  976. open_generic "$url"
  977. ;;
  978.  
  979. *)
  980. exit_failure_operation_impossible "no method available for opening '$url'"
  981. ;;
  982. esac
  983. + case "$DE" in
  984. + open_lxde http://ya.ru
  985. + is_file_url_or_path http://ya.ru
  986. + echo http://ya.ru
  987. + grep -q '^file://'
  988. + egrep -q '^[[:alpha:]+\.\-]+:'
  989. + echo http://ya.ru
  990. + return 1
  991. + open_generic http://ya.ru
  992. + is_file_url_or_path http://ya.ru
  993. + echo http://ya.ru
  994. + grep -q '^file://'
  995. + echo http://ya.ru
  996. + egrep -q '^[[:alpha:]+\.\-]+:'
  997. + return 1
  998. + '[' -n /usr/bin/xdg-open ']'
  999. + open_envvar http://ya.ru
  1000. + local 'oldifs=
  1001. '
  1002. + local browser browser_with_arg
  1003. + IFS=:
  1004. + for browser in '$BROWSER'
  1005. + IFS='
  1006. '
  1007. + '[' -z /usr/bin/xdg-open ']'
  1008. + grep -q %s
  1009. + echo /usr/bin/xdg-open
  1010. + /usr/bin/xdg-open http://ya.ru
  1011. ^C
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement