pekwm_themeset.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. #
  3. # Copyright © 2003-2009 the pekwm development team
  4. #
  5. # Add this to your menu to use this script:
  6. #
  7. # SubMenu = "Themes" {
  8. # Entry { Actions = "Dynamic /path/to/this/file /path/to/themedir" }
  9. # }
  10. #
  11. # Check usage
  12. if test -z "${1}"; then
  13. echo "usage: $0 /path/to/themedir (theme)";
  14. exit 1
  15. fi
  16. if test -z "${2}"; then
  17. theme_dir="${1}"
  18. echo "Dynamic {"
  19. # Check that theme directory exists, if it does not exist create a
  20. # dummy entry that says the dir does not exist.
  21. if test -d "${theme_dir}"; then
  22. ( cd ${theme_dir};
  23. for theme_name in *; do
  24. # Themes must be directories. This test also prevents * globbing
  25. # problems if theme_dir is empty.
  26. if test -d "${theme_name}"; then
  27. theme_path="${theme_dir}/${theme_name}"
  28. echo "Entry = \"${theme_name}\" { Actions = \"Exec ${0} ${1} ${theme_path}\" }"
  29. fi
  30. done )
  31. else
  32. echo "Entry = \"No such directory ${theme_dir}\" { Actions = \"None\" }"
  33. fi
  34. echo "}"
  35. else
  36. # Check for configuration file, if the environment is not set the
  37. # script is not being run from pekwm, then exit with failure.
  38. if test -f "${PEKWM_CONFIG_FILE}"; then
  39. theme="$(echo "${2}" | /usr/bin/sed -e "s@^${HOME}@~@" | /usr/bin/sed -e 's/\//\\\//g')"
  40. # Get temporary file, not all platforms have mktemp though
  41. if test -x "/bin/mktemp"; then
  42. tmp_file=$(mktemp -t pekwm_themeset.XXXXXX) || exit 1;
  43. else
  44. tmp_file="/tmp/pekwm_themeset.${USER}"
  45. fi
  46. # Change theme
  47. # Literal tab-character, whitespace and double quote
  48. tab=" "
  49. wspc="\\([ $tab]*\\)"
  50. qq='\"'
  51. text='[Tt][Hh][Ee][Mm][Ee]'
  52. /usr/bin/sed -e "s/^\([^#]*\)$text$wspc=$wspc$qq[^$qq]*$qq/\1Theme\2=\3$qq${theme}$qq/" "${PEKWM_CONFIG_FILE}" > "${tmp_file}"
  53. mv "${tmp_file}" "${PEKWM_CONFIG_FILE}"
  54. # Reload pekwm
  55. kill -HUP $(xprop -root _NET_WM_PID | awk '/_NET_WM_PID/ { print $3 }')
  56. else
  57. exit 1
  58. fi
  59. fi
  60. exit 0