xdg-settings 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  1. #!/bin/sh
  2. #---------------------------------------------
  3. # xdg-settings
  4. #
  5. # Utility script to get various settings from the desktop environment.
  6. #
  7. # Refer to the usage() function below for usage.
  8. #
  9. # Copyright 2009, Google Inc.
  10. #
  11. # LICENSE:
  12. #
  13. # Permission is hereby granted, free of charge, to any person obtaining a
  14. # copy of this software and associated documentation files (the "Software"),
  15. # to deal in the Software without restriction, including without limitation
  16. # the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17. # and/or sell copies of the Software, and to permit persons to whom the
  18. # Software is furnished to do so, subject to the following conditions:
  19. #
  20. # The above copyright notice and this permission notice shall be included
  21. # in all copies or substantial portions of the Software.
  22. #
  23. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  24. # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  25. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  26. # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  27. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  28. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  29. # OTHER DEALINGS IN THE SOFTWARE.
  30. #
  31. #---------------------------------------------
  32. manualpage()
  33. {
  34. cat << _MANUALPAGE
  35. Name
  36. xdg-settings -- get various settings from the desktop
  37. environment
  38. Synopsis
  39. xdg-settings { get | check | set } {property} [subproperty]
  40. [value]
  41. xdg-settings { --help | --list | --manual | --version }
  42. Description
  43. xdg-settings gets various settings from the desktop
  44. environment. For instance, desktop environments often provide
  45. proxy configuration and default web browser settings. Using
  46. xdg-settings these parameters can be extracted for use by
  47. applications that do not use the desktop environment's
  48. libraries (which would use the settings natively).
  49. xdg-settings is for use inside a desktop session only. It is
  50. not recommended to use xdg-settings as root.
  51. Options
  52. --help
  53. Show command synopsis.
  54. --list
  55. List all properties xdg-settings knows about.
  56. --manual
  57. Show this manual page.
  58. --version
  59. Show the xdg-utils version information.
  60. Properties
  61. When using xdg-settings to get, check or set a desktop setting,
  62. properties and possibly sub-properties are used to specify the
  63. setting to be changed.
  64. Some properties (such as default-web-browser) fully describe
  65. the setting to be changed. Other properties (such as
  66. default-url-scheme-handler) require more information (in this
  67. case the actual scheme to set the default handler for) which
  68. must be provided in a sub-property.
  69. Exit Codes
  70. An exit code of 0 indicates success while a non-zero exit code
  71. indicates failure. The following failure codes can be returned:
  72. 1
  73. Error in command line syntax.
  74. 2
  75. One of the files passed on the command line did not
  76. exist.
  77. 3
  78. A required tool could not be found.
  79. 4
  80. The action failed.
  81. See Also
  82. xdg-mime(1), xdg-open(1), MIME applications associations
  83. specification
  84. Examples
  85. Get the desktop file name of the current default web browser
  86. xdg-settings get default-web-browser
  87. Check whether the default web browser is firefox.desktop, which
  88. can be false even if "get default-web-browser" says that is the
  89. current value (if only some of the underlying settings actually
  90. reflect that value)
  91. xdg-settings check default-web-browser firefox.desktop
  92. Set the default web browser to google-chrome.desktop
  93. xdg-settings set default-web-browser google-chrome.desktop
  94. Set the default mailto URL scheme handler to be
  95. evolution.desktop
  96. xdg-settings set default-url-scheme-handler mailto evolution.des
  97. ktop
  98. _MANUALPAGE
  99. }
  100. usage()
  101. {
  102. cat << _USAGE
  103. xdg-settings -- get various settings from the desktop
  104. environment
  105. Synopsis
  106. xdg-settings { get | check | set } {property} [subproperty]
  107. [value]
  108. xdg-settings { --help | --list | --manual | --version }
  109. _USAGE
  110. }
  111. #@xdg-utils-common@
  112. #----------------------------------------------------------------------------
  113. # Common utility functions included in all XDG wrapper scripts
  114. #----------------------------------------------------------------------------
  115. DEBUG()
  116. {
  117. [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && return 0;
  118. [ ${XDG_UTILS_DEBUG_LEVEL} -lt $1 ] && return 0;
  119. shift
  120. echo "$@" >&2
  121. }
  122. # This handles backslashes but not quote marks.
  123. first_word()
  124. {
  125. read first rest
  126. echo "$first"
  127. }
  128. #-------------------------------------------------------------
  129. # map a binary to a .desktop file
  130. binary_to_desktop_file()
  131. {
  132. search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
  133. binary="`which "$1"`"
  134. binary="`readlink -f "$binary"`"
  135. base="`basename "$binary"`"
  136. IFS=:
  137. for dir in $search; do
  138. unset IFS
  139. [ "$dir" ] || continue
  140. [ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
  141. for file in "$dir"/applications/*.desktop "$dir"/applications/*/*.desktop "$dir"/applnk/*.desktop "$dir"/applnk/*/*.desktop; do
  142. [ -r "$file" ] || continue
  143. # Check to make sure it's worth the processing.
  144. grep -q "^Exec.*$base" "$file" || continue
  145. # Make sure it's a visible desktop file (e.g. not "preferred-web-browser.desktop").
  146. grep -Eq "^(NoDisplay|Hidden)=true" "$file" && continue
  147. command="`grep -E "^Exec(\[[^]=]*])?=" "$file" | cut -d= -f 2- | first_word`"
  148. command="`which "$command"`"
  149. if [ x"`readlink -f "$command"`" = x"$binary" ]; then
  150. # Fix any double slashes that got added path composition
  151. echo "$file" | sed -e 's,//*,/,g'
  152. return
  153. fi
  154. done
  155. done
  156. }
  157. #-------------------------------------------------------------
  158. # map a .desktop file to a binary
  159. desktop_file_to_binary()
  160. {
  161. search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
  162. desktop="`basename "$1"`"
  163. IFS=:
  164. for dir in $search; do
  165. unset IFS
  166. [ "$dir" ] && [ -d "$dir/applications" ] || [ -d "$dir/applnk" ] || continue
  167. # Check if desktop file contains -
  168. if [ "${desktop#*-}" != "$desktop" ]; then
  169. vendor=${desktop%-*}
  170. app=${desktop#*-}
  171. if [ -r $dir/applications/$vendor/$app ]; then
  172. file_path=$dir/applications/$vendor/$app
  173. elif [ -r $dir/applnk/$vendor/$app ]; then
  174. file_path=$dir/applnk/$vendor/$app
  175. fi
  176. fi
  177. if test -z "$file_path" ; then
  178. for indir in "$dir"/applications/ "$dir"/applications/*/ "$dir"/applnk/ "$dir"/applnk/*/; do
  179. file="$indir/$desktop"
  180. if [ -r "$file" ]; then
  181. file_path=$file
  182. break
  183. fi
  184. done
  185. fi
  186. if [ -r "$file_path" ]; then
  187. # Remove any arguments (%F, %f, %U, %u, etc.).
  188. command="`grep -E "^Exec(\[[^]=]*])?=" "$file_path" | cut -d= -f 2- | first_word`"
  189. command="`which "$command"`"
  190. readlink -f "$command"
  191. return
  192. fi
  193. done
  194. }
  195. #-------------------------------------------------------------
  196. # Exit script on successfully completing the desired operation
  197. exit_success()
  198. {
  199. if [ $# -gt 0 ]; then
  200. echo "$@"
  201. echo
  202. fi
  203. exit 0
  204. }
  205. #-----------------------------------------
  206. # Exit script on malformed arguments, not enough arguments
  207. # or missing required option.
  208. # prints usage information
  209. exit_failure_syntax()
  210. {
  211. if [ $# -gt 0 ]; then
  212. echo "xdg-settings: $@" >&2
  213. echo "Try 'xdg-settings --help' for more information." >&2
  214. else
  215. usage
  216. echo "Use 'man xdg-settings' or 'xdg-settings --manual' for additional info."
  217. fi
  218. exit 1
  219. }
  220. #-------------------------------------------------------------
  221. # Exit script on missing file specified on command line
  222. exit_failure_file_missing()
  223. {
  224. if [ $# -gt 0 ]; then
  225. echo "xdg-settings: $@" >&2
  226. fi
  227. exit 2
  228. }
  229. #-------------------------------------------------------------
  230. # Exit script on failure to locate necessary tool applications
  231. exit_failure_operation_impossible()
  232. {
  233. if [ $# -gt 0 ]; then
  234. echo "xdg-settings: $@" >&2
  235. fi
  236. exit 3
  237. }
  238. #-------------------------------------------------------------
  239. # Exit script on failure returned by a tool application
  240. exit_failure_operation_failed()
  241. {
  242. if [ $# -gt 0 ]; then
  243. echo "xdg-settings: $@" >&2
  244. fi
  245. exit 4
  246. }
  247. #------------------------------------------------------------
  248. # Exit script on insufficient permission to read a specified file
  249. exit_failure_file_permission_read()
  250. {
  251. if [ $# -gt 0 ]; then
  252. echo "xdg-settings: $@" >&2
  253. fi
  254. exit 5
  255. }
  256. #------------------------------------------------------------
  257. # Exit script on insufficient permission to write a specified file
  258. exit_failure_file_permission_write()
  259. {
  260. if [ $# -gt 0 ]; then
  261. echo "xdg-settings: $@" >&2
  262. fi
  263. exit 6
  264. }
  265. check_input_file()
  266. {
  267. if [ ! -e "$1" ]; then
  268. exit_failure_file_missing "file '$1' does not exist"
  269. fi
  270. if [ ! -r "$1" ]; then
  271. exit_failure_file_permission_read "no permission to read file '$1'"
  272. fi
  273. }
  274. check_vendor_prefix()
  275. {
  276. file_label="$2"
  277. [ -n "$file_label" ] || file_label="filename"
  278. file=`basename "$1"`
  279. case "$file" in
  280. [[:alpha:]]*-*)
  281. return
  282. ;;
  283. esac
  284. echo "xdg-settings: $file_label '$file' does not have a proper vendor prefix" >&2
  285. echo 'A vendor prefix consists of alpha characters ([a-zA-Z]) and is terminated' >&2
  286. echo 'with a dash ("-"). An example '"$file_label"' is '"'example-$file'" >&2
  287. echo "Use --novendor to override or 'xdg-settings --manual' for additional info." >&2
  288. exit 1
  289. }
  290. check_output_file()
  291. {
  292. # if the file exists, check if it is writeable
  293. # if it does not exists, check if we are allowed to write on the directory
  294. if [ -e "$1" ]; then
  295. if [ ! -w "$1" ]; then
  296. exit_failure_file_permission_write "no permission to write to file '$1'"
  297. fi
  298. else
  299. DIR=`dirname "$1"`
  300. if [ ! -w "$DIR" ] || [ ! -x "$DIR" ]; then
  301. exit_failure_file_permission_write "no permission to create file '$1'"
  302. fi
  303. fi
  304. }
  305. #----------------------------------------
  306. # Checks for shared commands, e.g. --help
  307. check_common_commands()
  308. {
  309. while [ $# -gt 0 ] ; do
  310. parm="$1"
  311. shift
  312. case "$parm" in
  313. --help)
  314. usage
  315. echo "Use 'man xdg-settings' or 'xdg-settings --manual' for additional info."
  316. exit_success
  317. ;;
  318. --manual)
  319. manualpage
  320. exit_success
  321. ;;
  322. --version)
  323. echo "xdg-settings 1.1.3"
  324. exit_success
  325. ;;
  326. esac
  327. done
  328. }
  329. check_common_commands "$@"
  330. [ -z "${XDG_UTILS_DEBUG_LEVEL}" ] && unset XDG_UTILS_DEBUG_LEVEL;
  331. if [ ${XDG_UTILS_DEBUG_LEVEL-0} -lt 1 ]; then
  332. # Be silent
  333. xdg_redirect_output=" > /dev/null 2> /dev/null"
  334. else
  335. # All output to stderr
  336. xdg_redirect_output=" >&2"
  337. fi
  338. #--------------------------------------
  339. # Checks for known desktop environments
  340. # set variable DE to the desktop environments name, lowercase
  341. detectDE()
  342. {
  343. # see https://bugs.freedesktop.org/show_bug.cgi?id=34164
  344. unset GREP_OPTIONS
  345. if [ -n "${XDG_CURRENT_DESKTOP}" ]; then
  346. case "${XDG_CURRENT_DESKTOP}" in
  347. # only recently added to menu-spec, pre-spec X- still in use
  348. Cinnamon|X-Cinnamon)
  349. DE=cinnamon;
  350. ;;
  351. ENLIGHTENMENT)
  352. DE=enlightenment;
  353. ;;
  354. # GNOME, GNOME-Classic:GNOME, or GNOME-Flashback:GNOME
  355. GNOME*)
  356. DE=gnome;
  357. ;;
  358. KDE)
  359. DE=kde;
  360. ;;
  361. # Deepin Desktop Environments
  362. DEEPIN|Deepin|deepin)
  363. DE=dde;
  364. ;;
  365. LXDE)
  366. DE=lxde;
  367. ;;
  368. LXQt)
  369. DE=lxqt;
  370. ;;
  371. MATE)
  372. DE=mate;
  373. ;;
  374. XFCE)
  375. DE=xfce
  376. ;;
  377. X-Generic)
  378. DE=generic
  379. ;;
  380. esac
  381. fi
  382. if [ x"$DE" = x"" ]; then
  383. # classic fallbacks
  384. if [ x"$KDE_FULL_SESSION" != x"" ]; then DE=kde;
  385. elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
  386. elif [ x"$MATE_DESKTOP_SESSION_ID" != x"" ]; then DE=mate;
  387. 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;
  388. elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then DE=xfce;
  389. elif xprop -root 2> /dev/null | grep -i '^xfce_desktop_window' >/dev/null 2>&1; then DE=xfce
  390. elif echo $DESKTOP | grep -q '^Enlightenment'; then DE=enlightenment;
  391. elif [ x"$LXQT_SESSION_CONFIG" != x"" ]; then DE=lxqt;
  392. fi
  393. fi
  394. if [ x"$DE" = x"" ]; then
  395. # fallback to checking $DESKTOP_SESSION
  396. case "$DESKTOP_SESSION" in
  397. gnome)
  398. DE=gnome;
  399. ;;
  400. LXDE|Lubuntu)
  401. DE=lxde;
  402. ;;
  403. MATE)
  404. DE=mate;
  405. ;;
  406. xfce|xfce4|'Xfce Session')
  407. DE=xfce;
  408. ;;
  409. esac
  410. fi
  411. if [ x"$DE" = x"" ]; then
  412. # fallback to uname output for other platforms
  413. case "$(uname 2>/dev/null)" in
  414. CYGWIN*)
  415. DE=cygwin;
  416. ;;
  417. Darwin)
  418. DE=darwin;
  419. ;;
  420. esac
  421. fi
  422. if [ x"$DE" = x"gnome" ]; then
  423. # gnome-default-applications-properties is only available in GNOME 2.x
  424. # but not in GNOME 3.x
  425. which gnome-default-applications-properties > /dev/null 2>&1 || DE="gnome3"
  426. fi
  427. if [ -f "$XDG_RUNTIME_DIR/flatpak-info" ]; then
  428. DE="flatpak"
  429. fi
  430. }
  431. #----------------------------------------------------------------------------
  432. # kfmclient exec/openURL can give bogus exit value in KDE <= 3.5.4
  433. # It also always returns 1 in KDE 3.4 and earlier
  434. # Simply return 0 in such case
  435. kfmclient_fix_exit_code()
  436. {
  437. version=`LC_ALL=C.UTF-8 kde-config --version 2>/dev/null | grep '^KDE'`
  438. major=`echo $version | sed 's/KDE.*: \([0-9]\).*/\1/'`
  439. minor=`echo $version | sed 's/KDE.*: [0-9]*\.\([0-9]\).*/\1/'`
  440. release=`echo $version | sed 's/KDE.*: [0-9]*\.[0-9]*\.\([0-9]\).*/\1/'`
  441. test "$major" -gt 3 && return $1
  442. test "$minor" -gt 5 && return $1
  443. test "$release" -gt 4 && return $1
  444. return 0
  445. }
  446. #----------------------------------------------------------------------------
  447. # Returns true if there is a graphical display attached.
  448. has_display()
  449. {
  450. if [ -n "$DISPLAY" ] || [ -n "$WAYLAND_DISPLAY" ]; then
  451. return 0
  452. else
  453. return 1
  454. fi
  455. }
  456. check_desktop_filename()
  457. {
  458. case "$1" in
  459. */*)
  460. exit_failure_syntax "invalid application name"
  461. ;;
  462. *.desktop)
  463. return
  464. ;;
  465. *)
  466. exit_failure_syntax "invalid application name"
  467. ;;
  468. esac
  469. }
  470. # {{{ default browser
  471. # {{{ utility functions
  472. # In order to remove an application from the automatically-generated list of
  473. # applications for handling a given MIME type, the desktop environment may copy
  474. # the global .desktop file into the user's .local directory, and remove that
  475. # MIME type from its list. In that case, we must restore the MIME type to the
  476. # application's list of MIME types before we can set it as the default for that
  477. # MIME type. (We can't just delete the local version, since the user may have
  478. # made other changes to it as well. So, tweak the existing file.)
  479. # This function is hard-coded for text/html but it could be adapted if needed.
  480. fix_local_desktop_file()
  481. {
  482. if test -z "$2" ; then
  483. MIME="text/html"
  484. else
  485. MIME="$2"
  486. fi
  487. apps="${XDG_DATA_HOME:-$HOME/.local/share}/applications"
  488. # No local desktop file?
  489. [ ! -f "$apps/$1" ] && return
  490. MIMETYPES="`grep "^MimeType=" "$apps/$1" | cut -d= -f 2-`"
  491. case "$MIMETYPES" in
  492. $MIME\;*|*\;$MIME\;*|*\;$MIME\;|*\;$MIME)
  493. # Already has the mime-type? Great!
  494. return 0
  495. ;;
  496. esac
  497. # Add the mime-type to the list
  498. temp="`mktemp "$apps/$1.XXXXXX"`" || return
  499. grep -v "^MimeType=" "$apps/$1" >> "$temp"
  500. echo "MimeType=$MIME;$MIMETYPES" >> "$temp"
  501. oldlines="`wc -l < "$apps/$1"`"
  502. newlines="`wc -l < "$temp"`"
  503. # The new file should have at least as many lines as the old.
  504. if [ $oldlines -le $newlines ]; then
  505. mv "$temp" "$apps/$1"
  506. # This can take a little bit to get noticed.
  507. sleep 4
  508. else
  509. rm -f "$temp"
  510. return 1
  511. fi
  512. }
  513. # }}} utility functions
  514. # {{{ MIME utilities
  515. xdg_mime_fixup()
  516. {
  517. # xdg-mime may use ktradertest, which will fork off a copy of kdeinit if
  518. # one does not already exist. It will exit after about 15 seconds if no
  519. # further processes need it around. But since it does not close its stdout,
  520. # the shell (via grep) will wait around for kdeinit to exit. If we start a
  521. # copy here, that copy will be used in xdg-mime and we will avoid waiting.
  522. if [ "$DE" = kde -a -z "$XDG_MIME_FIXED" ]; then
  523. ktradertest text/html Application > /dev/null 2>&1
  524. # Only do this once, as we only need it once.
  525. XDG_MIME_FIXED=yes
  526. fi
  527. }
  528. get_browser_mime()
  529. {
  530. if test -z "$1" ; then
  531. MIME="text/html"
  532. else
  533. MIME="$1"
  534. fi
  535. xdg_mime_fixup
  536. xdg-mime query default "$MIME"
  537. }
  538. set_browser_mime()
  539. {
  540. xdg_mime_fixup
  541. if test -z "$2" ; then
  542. MIME="text/html"
  543. else
  544. MIME="$2"
  545. fi
  546. orig="`get_browser_mime $MIME`"
  547. # Fixing the local desktop file can actually change the default browser all
  548. # by itself, so we fix it only after querying to find the current default.
  549. fix_local_desktop_file "$1" "$MIME" || return
  550. mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}/applications"
  551. xdg-mime default "$1" "$MIME" || return
  552. if [ x"`get_browser_mime`" != x"$1" ]; then
  553. # Put back the original value
  554. xdg-mime default "$orig" "$MIME"
  555. exit_failure_operation_failed
  556. fi
  557. }
  558. # }}} MIME utilities
  559. # {{{ KDE utilities
  560. # Reads the KDE configuration setting, compensating for a bug in some versions of kreadconfig.
  561. read_kde_config()
  562. {
  563. configfile="$1"
  564. configsection="$2"
  565. configkey="$3"
  566. if [ x"${KDE_SESSION_VERSION}" = x"5" ]; then
  567. application="`kreadconfig5 --file $configfile --group $configsection --key $configkey`"
  568. else
  569. application="`kreadconfig --file $configfile --group $configsection --key $configkey`"
  570. fi
  571. if [ x"$application" != x ]; then
  572. echo "$application"
  573. else
  574. if [ x"${KDE_SESSION_VERSION}" = x"4" ]; then
  575. # kreadconfig in KDE 4 may not notice Key[$*]=... localized settings, so
  576. # check by hand if it didn't find anything (oddly kwriteconfig works
  577. # fine though).
  578. configfile_dir=`kde${KDE_SESSION_VERSION}-config --path config | cut -d ':' -f 1`
  579. configfile_path="$configfile_dir/$configfile"
  580. [ ! -f "$configfile_path" ] && return
  581. # This will only take the first value if there is more than one.
  582. grep "^$configkey"'\[$[^]=]*\]=' "$configfile_path" | head -n 1 | cut -d= -f 2-
  583. fi
  584. fi
  585. }
  586. # }}} KDE utilities
  587. # {{{ KDE
  588. # Resolves the KDE browser setting to a binary: if prefixed with !, simply removes it;
  589. # otherwise, uses desktop_file_to_binary to get the binary out of the desktop file.
  590. resolve_kde_browser()
  591. {
  592. [ -z "$browser" ] && return
  593. case "$browser" in
  594. !*)
  595. echo "${browser#!}"
  596. ;;
  597. *)
  598. desktop_file_to_binary "$browser"
  599. ;;
  600. esac
  601. }
  602. # Does the opposite of resolve_kde_browser: if prefixed with !, tries to find a desktop
  603. # file corresponding to the binary, otherwise just returns the desktop file name.
  604. resolve_kde_browser_desktop()
  605. {
  606. [ -z "$browser" ] && return
  607. case "$browser" in
  608. !*)
  609. desktop="`binary_to_desktop_file "${browser#!}"`"
  610. basename "$desktop"
  611. ;;
  612. *)
  613. echo "$browser"
  614. ;;
  615. esac
  616. }
  617. read_kde_browser()
  618. {
  619. read_kde_config kdeglobals General BrowserApplication
  620. }
  621. get_browser_kde()
  622. {
  623. browser="`read_kde_browser`"
  624. if [ x"$browser" = x ]; then
  625. # No explicit default browser; KDE will use the MIME type text/html.
  626. get_browser_mime
  627. else
  628. resolve_kde_browser_desktop
  629. fi
  630. }
  631. check_browser_kde()
  632. {
  633. check="`desktop_file_to_binary "$1"`"
  634. if [ -z "$check" ]; then
  635. echo no
  636. exit_success
  637. fi
  638. browser="`read_kde_browser`"
  639. binary="`resolve_kde_browser`"
  640. # The browser may contain a relative entry to the binary starting with !
  641. if [ x"!" == x"${browser:0:1}" ]; then
  642. # get the full path
  643. browser="`binary_to_desktop_file ${browser:1}`"
  644. binary="`desktop_file_to_binary $browser`"
  645. fi
  646. # Because KDE will use the handler for MIME type text/html if this value
  647. # is empty, we allow either the empty string or a match to $check here.
  648. if [ x"$binary" != x -a x"$binary" != x"$check" ]; then
  649. echo no
  650. exit_success
  651. fi
  652. browser="`get_browser_mime`"
  653. binary="`desktop_file_to_binary "$browser"`"
  654. if [ x"$binary" != x"$check" ]; then
  655. echo no
  656. exit_success
  657. fi
  658. echo yes
  659. exit_success
  660. }
  661. set_browser_kde()
  662. {
  663. set_browser_mime "$1" || return
  664. if [ x"${KDE_SESSION_VERSION}" = x"5" ]; then
  665. kwriteconfig5 --file kdeglobals --group General --key BrowserApplication "$1"
  666. else
  667. kwriteconfig --file kdeglobals --group General --key BrowserApplication "$1"
  668. fi
  669. }
  670. # }}} KDE
  671. # {{{ GNOME
  672. get_browser_gnome()
  673. {
  674. binary="`gconftool-2 --get /desktop/gnome/applications/browser/exec | first_word`"
  675. if [ x"$binary" = x ]; then
  676. # No default browser; GNOME might use the MIME type text/html.
  677. get_browser_mime
  678. else
  679. # gconftool gives the binary (maybe with %s etc. afterward),
  680. # but we want the desktop file name, not the binary. So, we
  681. # have to find the desktop file to which it corresponds.
  682. desktop="`binary_to_desktop_file "$binary"`"
  683. basename "$desktop"
  684. fi
  685. }
  686. check_browser_gnome()
  687. {
  688. check="`desktop_file_to_binary "$1"`"
  689. if [ -z "$check" ]; then
  690. echo no
  691. exit_success
  692. fi
  693. binary="`gconftool-2 --get /desktop/gnome/applications/browser/exec | first_word`"
  694. if [ x"$binary" != x"$check" ]; then
  695. echo no
  696. exit_success
  697. fi
  698. # Check HTTP and HTTPS, but not about: and unknown:.
  699. for protocol in http https; do
  700. binary="`gconftool-2 --get /desktop/gnome/url-handlers/$protocol/command | first_word`"
  701. if [ x"$binary" != x"$check" ]; then
  702. echo no
  703. exit_success
  704. fi
  705. done
  706. browser="`get_browser_mime`"
  707. binary="`desktop_file_to_binary "$browser"`"
  708. if [ x"$binary" != x"$check" ]; then
  709. echo no
  710. exit_success
  711. fi
  712. echo yes
  713. exit_success
  714. }
  715. set_browser_gnome()
  716. {
  717. binary="`desktop_file_to_binary "$1"`"
  718. [ "$binary" ] || exit_failure_file_missing
  719. set_browser_mime "$1" || return
  720. # Set the default browser.
  721. gconftool-2 --type string --set /desktop/gnome/applications/browser/exec "$binary"
  722. gconftool-2 --type bool --set /desktop/gnome/applications/browser/needs_term false
  723. gconftool-2 --type bool --set /desktop/gnome/applications/browser/nremote true
  724. # Set the handler for HTTP and HTTPS.
  725. for protocol in http https; do
  726. gconftool-2 --type string --set /desktop/gnome/url-handlers/$protocol/command "$binary %s"
  727. gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/needs_terminal false
  728. gconftool-2 --type bool --set /desktop/gnome/url-handlers/$protocol/enabled true
  729. done
  730. # Set the handler for about: and unknown URL types.
  731. for protocol in about unknown; do
  732. gconftool-2 --type string --set /desktop/gnome/url-handlers/$protocol/command "$binary %s"
  733. done
  734. }
  735. # }}} GNOME
  736. # {{{ GNOME 3.x
  737. get_browser_gnome3()
  738. {
  739. get_browser_mime "x-scheme-handler/http"
  740. }
  741. check_browser_gnome3()
  742. {
  743. desktop="$1"
  744. check="`desktop_file_to_binary "$1"`"
  745. if [ -z "$check" ]; then
  746. echo no
  747. exit_success
  748. fi
  749. # Check HTTP and HTTPS, but not about: and unknown:.
  750. for protocol in http https; do
  751. browser="`get_browser_mime "x-scheme-handler/$protocol"`"
  752. if [ x"$browser" != x"$desktop" ]; then
  753. echo no
  754. exit_success
  755. fi
  756. done
  757. echo yes
  758. exit_success
  759. }
  760. set_browser_gnome3()
  761. {
  762. binary="`desktop_file_to_binary "$1"`"
  763. [ "$binary" ] || exit_failure_file_missing
  764. set_browser_mime "$1" || return
  765. # Set the default browser.
  766. for protocol in http https about unknown; do
  767. set_browser_mime "$1" "x-scheme-handler/$protocol" || return
  768. done
  769. }
  770. # }}} GNOME 3.x
  771. # {{{ xfce
  772. get_browser_xfce()
  773. {
  774. search="${XDG_CONFIG_HOME:-$HOME/.config}:${XDG_CONFIG_DIRS:-/etc/xdg}"
  775. IFS=:
  776. for dir in $search; do
  777. unset IFS
  778. [ "$dir" ] && [ -d "$dir/xfce4" ] || continue
  779. file="$dir/xfce4/helpers.rc"
  780. [ -r "$file" ] || continue
  781. grep -q "^WebBrowser=" "$file" || continue
  782. desktop="`grep "^WebBrowser=" "$file" | cut -d= -f 2-`"
  783. echo "$desktop.desktop"
  784. return
  785. done
  786. exit_failure_operation_failed
  787. }
  788. check_browser_xfce()
  789. {
  790. browser="`get_browser_xfce`"
  791. if [ x"$browser" != x"$1" ]; then
  792. echo no
  793. exit_success
  794. fi
  795. echo yes
  796. exit_success
  797. }
  798. check_xfce_desktop_file()
  799. {
  800. # Annoyingly, xfce wants its .desktop files in a separate directory instead
  801. # of the standard locations, and requires a few custom tweaks to them:
  802. # "Type" must be "X-XFCE-Helper"
  803. # "X-XFCE-Category" must be "WebBrowser" (for web browsers, anyway)
  804. # "X-XFCE-Commands" and "X-XFCE-CommandsWithParameter" must be set
  805. search="${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}"
  806. IFS=:
  807. for dir in $search; do
  808. unset IFS
  809. [ "$dir" ] && [ -d "$dir/xfce4/helpers" ] || continue
  810. file="$dir/xfce4/helpers/$1"
  811. # We have the file, no need to create it.
  812. [ -r "$file" ] && return
  813. done
  814. IFS=:
  815. for dir in $search; do
  816. unset IFS
  817. [ "$dir" ] && [ -d "$dir/applications" ] || continue
  818. file="$dir/applications/$1"
  819. if [ -r "$file" ]; then
  820. # Found a file to convert.
  821. target="${XDG_DATA_HOME:-$HOME/.local/share}/xfce4/helpers"
  822. mkdir -p "$target"
  823. # Copy file up to first "Exec=" line.
  824. sed -e 's/^Type=.*/Type=X-XFCE-Helper/' -e '/^Exec[=[]/,$d' "$file" > "$target/$1"
  825. echo "X-XFCE-Category=WebBrowser" >> "$target/$1"
  826. # Change %F, %f, %U, and %u to "%s".
  827. command=$(grep -E '^Exec(\[[^]=]*])?=' "$file" | cut -d= -f 2- | sed -e 's/%[FfUu]/"%s"/g' | head -1)
  828. echo "X-XFCE-Commands=`echo "$command" | first_word`" >> "$target/$1"
  829. echo "X-XFCE-CommandsWithParameter=$command" >> "$target/$1"
  830. # Copy rest of file (from first "Exec=" line to end-of-file).
  831. sed -n -e 's/^Type=.*/Type=X-XFCE-Helper/' -e '/^Exec[=[]/,$p' "$file" >> "$target/$1"
  832. return
  833. fi
  834. done
  835. return 1
  836. }
  837. set_browser_xfce()
  838. {
  839. check_xfce_desktop_file "$1" || exit_failure_operation_failed
  840. helper_dir="${XDG_CONFIG_HOME:-$HOME/.config}/xfce4"
  841. if [ ! -d "$helper_dir" ]; then
  842. mkdir -p "$helper_dir" || exit_failure_operation_failed
  843. fi
  844. helpers_rc="$helper_dir/helpers.rc"
  845. # Create the file if it does not exist to avoid special cases below.
  846. if [ ! -r "$helpers_rc" ]; then
  847. touch "$helpers_rc" || exit_failure_operation_failed
  848. fi
  849. temp="`mktemp "$helpers_rc.XXXXXX"`" || return
  850. grep -v "^WebBrowser=" "$helpers_rc" >> "$temp"
  851. echo "WebBrowser=${1%.desktop}" >> "$temp"
  852. oldlines="`wc -l < "$helpers_rc"`"
  853. newlines="`wc -l < "$temp"`"
  854. # The new file should have at least as many lines as the old.
  855. if [ $oldlines -le $newlines ]; then
  856. mv "$temp" "$helpers_rc"
  857. else
  858. rm -f "$temp"
  859. return 1
  860. fi
  861. }
  862. # }}} xfce
  863. # {{{ generic
  864. get_browser_generic()
  865. {
  866. if [ -n "$BROWSER" ]; then
  867. local browser=$(binary_to_desktop_file "${BROWSER%%:*}")
  868. if [ -n "$browser" ]; then
  869. echo "$(basename "$browser")"
  870. return 0
  871. fi
  872. fi
  873. if get_browser_mime x-scheme-handler/http; then
  874. return 0
  875. fi
  876. # Debian and derivatives have x-www-browser
  877. local browser=$(binary_to_desktop_file x-www-browser)
  878. if [ -n "$browser" ]; then
  879. echo "$(basename "$browser")"
  880. return 0
  881. fi
  882. return 4
  883. }
  884. check_browser_generic()
  885. {
  886. local desktop="$1"
  887. # Check HTTP
  888. if [ "$desktop" != "$(get_browser_generic)" ]; then
  889. echo no
  890. exit_success
  891. fi
  892. # Check text/html
  893. if [ "$desktop" != "$(get_browser_mime)" ]; then
  894. echo no
  895. exit_success
  896. fi
  897. # Check HTTPS
  898. if [ "$desktop" != "$(get_url_scheme_handler_generic https)" ]; then
  899. echo no
  900. exit_success
  901. fi
  902. echo yes
  903. exit_success
  904. }
  905. set_browser_generic()
  906. {
  907. if [ -n "$BROWSER" ]; then
  908. exit_failure_operation_failed \
  909. "\$BROWSER is set and can't be changed with xdg-settings"
  910. fi
  911. binary=$(desktop_file_to_binary "$1")
  912. [ -n "$binary" ] || exit_failure_file_missing
  913. set_browser_mime "$1" text/html || return
  914. for protocol in http https about unknown; do
  915. set_browser_mime "$1" "x-scheme-handler/$protocol" || return
  916. done
  917. }
  918. # }}} generic
  919. # }}} default browser
  920. # {{{ default url scheme handler
  921. exit_unimplemented_default_handler()
  922. {
  923. exit_failure_operation_impossible "default-url-scheme-handler not implemented for $DE"
  924. }
  925. # {{{ KDE
  926. # Recent versions of KDE support default scheme handler applications using the
  927. # mime type of x-scheme-handler/scheme. Older versions will not support this
  928. # but do have support for setting a default mail handler. There is also a
  929. # system in KDE where .protocol files can be used, however this is not
  930. # supported by this script. When reading a scheme handler we will use the
  931. # default mail handler for the mailto scheme, otherwise we will use the mime
  932. # type x-scheme-handler/scheme.
  933. get_url_scheme_handler_kde()
  934. {
  935. if [ "$1" = "mailto" ]; then
  936. handler="`read_kde_config emaildefaults PROFILE_Default EmailClient | first_word`"
  937. echo "handler is $handler"
  938. if [ x"$handler" != x ]; then
  939. binary_to_desktop_file "$handler"
  940. else
  941. get_browser_mime "x-scheme-handler/$1"
  942. fi
  943. else
  944. get_browser_mime "x-scheme-handler/$1"
  945. fi
  946. }
  947. check_url_scheme_handler_kde()
  948. {
  949. check="`desktop_file_to_binary "$2"`"
  950. if [ -z "$check" ]; then
  951. echo no
  952. exit_success
  953. fi
  954. if [ x"$1" = "mailto" ]; then
  955. binary="`read_kde_config emaildefaults PROFILE_Default EmailClient`"
  956. # The field may contain a relative entry to the binary starting with !
  957. if [ x"!" == x"${binary:0:1}" ]; then
  958. # get the full path
  959. desktop_file="`binary_to_desktop_file ${binary:1}`"
  960. binary="`desktop_file_to_binary $desktop_file`"
  961. fi
  962. if [ x"$binary" != x"$check" ]; then
  963. echo no
  964. exit_success
  965. fi
  966. else
  967. handler="`get_browser_mime x-scheme-handler/$1`"
  968. binary="`desktop_file_to_binary "$handler"`"
  969. if [ x"$binary" != x"$check" ]; then
  970. echo no
  971. exit_success
  972. fi
  973. fi
  974. echo yes
  975. exit_success
  976. }
  977. set_url_scheme_handler_kde()
  978. {
  979. set_browser_mime "$2" "x-scheme-handler/$1" || return
  980. if [ "$1" = "mailto" ]; then
  981. binary="`desktop_file_to_binary "$2"`"
  982. if [ x"${KDE_SESSION_VERSION}" = x"5" ]; then
  983. kwriteconfig5 --file emaildefaults --group PROFILE_Default --key EmailClient "$binary"
  984. else
  985. kwriteconfig --file emaildefaults --group PROFILE_Default --key EmailClient "$binary"
  986. fi
  987. fi
  988. }
  989. # }}} KDE
  990. # {{{ GNOME
  991. get_url_scheme_handler_gnome()
  992. {
  993. binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_word`"
  994. if [ x"$binary" != x"" ]; then
  995. # gconftool gives the binary (maybe with %s etc. afterward),
  996. # but we want the desktop file name, not the binary. So, we
  997. # have to find the desktop file to which it corresponds.
  998. desktop="`binary_to_desktop_file "$binary"`"
  999. basename "$desktop"
  1000. fi
  1001. }
  1002. check_url_scheme_handler_gnome()
  1003. {
  1004. check="`desktop_file_to_binary "$2"`"
  1005. if [ -z "$check" ]; then
  1006. echo no
  1007. exit_success
  1008. fi
  1009. binary="`gconftool-2 --get /desktop/gnome/url-handlers/$1/command | first_word`"
  1010. if [ x"$binary" != x"$check" ]; then
  1011. echo no
  1012. exit_success
  1013. fi
  1014. echo yes
  1015. exit_success
  1016. }
  1017. set_url_scheme_handler_gnome()
  1018. {
  1019. binary="`desktop_file_to_binary "$2"`"
  1020. [ "$binary" ] || exit_failure_file_missing
  1021. gconftool-2 --type string --set /desktop/gnome/url-handlers/$1/command "$binary %s"
  1022. gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/needs_terminal false
  1023. gconftool-2 --type bool --set /desktop/gnome/url-handlers/$1/enabled true
  1024. }
  1025. # }}} GNOME
  1026. # {{{ GNOME 3.x
  1027. get_url_scheme_handler_gnome3()
  1028. {
  1029. get_browser_mime "x-scheme-handler/$1"
  1030. }
  1031. check_url_scheme_handler_gnome3()
  1032. {
  1033. desktop="$2"
  1034. check="`desktop_file_to_binary "$2"`"
  1035. if [ -z "$check" ]; then
  1036. echo no
  1037. exit_success
  1038. fi
  1039. browser="`get_browser_mime "x-scheme-handler/$1"`"
  1040. if [ x"$browser" != x"$desktop" ]; then
  1041. echo no
  1042. exit_success
  1043. fi
  1044. echo yes
  1045. exit_success
  1046. }
  1047. set_url_scheme_handler_gnome3()
  1048. {
  1049. binary="`desktop_file_to_binary "$2"`"
  1050. [ "$binary" ] || exit_failure_file_missing
  1051. set_browser_mime "$2" || return
  1052. # Set the default browser.
  1053. set_browser_mime "$2" "x-scheme-handler/$1" || return
  1054. }
  1055. # }}} GNOME 3.x
  1056. # {{{ xfce
  1057. get_url_scheme_handler_xfce()
  1058. {
  1059. exit_unimplemented_default_handler "$1"
  1060. }
  1061. check_url_scheme_handler_xfce()
  1062. {
  1063. exit_unimplemented_default_handler "$1"
  1064. }
  1065. set_url_scheme_handler_xfce()
  1066. {
  1067. exit_unimplemented_default_handler "$1"
  1068. }
  1069. # }}} xfce
  1070. # {{{ generic
  1071. get_url_scheme_handler_generic()
  1072. {
  1073. if [ -n "$BROWSER" ] && ([ "$1" = http ] || [ "$1" = https ]); then
  1074. get_browser_generic
  1075. else
  1076. get_browser_mime "x-scheme-handler/$1"
  1077. fi
  1078. }
  1079. check_url_scheme_handler_generic()
  1080. {
  1081. local scheme="$1" desktop="$2"
  1082. if [ -z "$(desktop_file_to_binary "$desktop")" ]; then
  1083. echo no
  1084. exit_success
  1085. fi
  1086. local browser=$(get_url_scheme_handler_generic "$scheme")
  1087. if [ "$browser" != "$desktop" ]; then
  1088. echo no
  1089. exit_success
  1090. fi
  1091. echo yes
  1092. exit_success
  1093. }
  1094. set_url_scheme_handler_generic()
  1095. {
  1096. local scheme="$1" desktop="$2"
  1097. if [ -n "$BROWSER" ] && \
  1098. ([ "$scheme" = http ] || [ "$scheme" = https ]); then
  1099. exit_failure_operation_failed \
  1100. "\$BROWSER is set and can't be changed with xdg-settings"
  1101. fi
  1102. if [ -z "$(desktop_file_to_binary "$desktop")" ]; then
  1103. exit_failure_file_missing
  1104. fi
  1105. set_browser_mime "$desktop" "x-scheme-handler/$scheme"
  1106. }
  1107. # }}} generic
  1108. # }}} default protocol handler
  1109. dispatch_specific()
  1110. {
  1111. local handler=$1; shift
  1112. # The PROP comments in this function are used to generate the output of
  1113. # the --list option. The formatting is important. Make sure to line up the
  1114. # property descriptions with spaces so that it will look nice.
  1115. if [ x"$op" = x"get" ]; then
  1116. case "$parm" in
  1117. default-web-browser) # PROP: Default web browser
  1118. get_browser_$handler
  1119. ;;
  1120. default-url-scheme-handler) # PROP: Default handler for URL scheme
  1121. get_url_scheme_handler_$handler "$1"
  1122. ;;
  1123. *)
  1124. exit_failure_syntax
  1125. ;;
  1126. esac
  1127. elif [ x"$op" = x"check" ]; then
  1128. case "$parm" in
  1129. default-web-browser)
  1130. check_desktop_filename "$1"
  1131. check_browser_$handler "$1"
  1132. ;;
  1133. default-url-scheme-handler)
  1134. check_desktop_filename "$2"
  1135. check_url_scheme_handler_$handler "$1" "$2"
  1136. ;;
  1137. *)
  1138. exit_failure_syntax
  1139. ;;
  1140. esac
  1141. else # set
  1142. case "$parm" in
  1143. default-web-browser)
  1144. [ $# -eq 1 ] || exit_failure_syntax "unexpected/missing argument"
  1145. check_desktop_filename "$1"
  1146. set_browser_$handler "$1"
  1147. ;;
  1148. default-url-scheme-handler)
  1149. [ $# -eq 2 ] || exit_failure_syntax "unexpected/missing argument"
  1150. check_desktop_filename "$2"
  1151. set_url_scheme_handler_$handler "$1" "$2"
  1152. ;;
  1153. *)
  1154. exit_failure_syntax
  1155. ;;
  1156. esac
  1157. fi
  1158. if [ $? -eq 0 ]; then
  1159. exit_success
  1160. else
  1161. exit_failure_operation_failed
  1162. fi
  1163. }
  1164. if [ x"$1" = x"--list" ]; then
  1165. echo "Known properties:"
  1166. # Extract the property names from dispatch_specific() above.
  1167. grep "^[ ]*[^)]*) # PROP:" "$0" | sed -e 's/^[ ]*\([^)]*\)) # PROP: \(.*\)$/ \1 \2/' | sort
  1168. exit_success
  1169. fi
  1170. [ x"$1" != x ] || exit_failure_syntax "no operation given"
  1171. [ x"$2" != x ] || exit_failure_syntax "no parameter name given"
  1172. [ x"$1" = x"get" -o x"$3" != x ] || exit_failure_syntax "no parameter value given"
  1173. op="$1"
  1174. parm="$2"
  1175. shift 2
  1176. if [ x"$op" != x"get" -a x"$op" != x"check" -a x"$op" != x"set" ]; then
  1177. exit_failure_syntax "invalid operation"
  1178. fi
  1179. detectDE
  1180. if [ -z "$DE" ]; then
  1181. DE=generic
  1182. fi
  1183. case "$DE" in
  1184. kde)
  1185. dispatch_specific kde "$@"
  1186. ;;
  1187. gnome)
  1188. dispatch_specific gnome "$@"
  1189. ;;
  1190. gnome3|cinnamon|lxde|mate)
  1191. dispatch_specific gnome3 "$@"
  1192. ;;
  1193. xfce)
  1194. dispatch_specific xfce "$@"
  1195. ;;
  1196. generic|lxqt|enlightenment)
  1197. dispatch_specific generic "$@"
  1198. ;;
  1199. *)
  1200. exit_failure_operation_impossible "unknown desktop environment"
  1201. ;;
  1202. esac