makeappicons.sh 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. #!/usr/bin/env bash
  2. #
  3. # Copy icon files from the Material Design icon set.
  4. #
  5. # Copyright (C) 2020 Wolfram Rösler
  6. # Copyright (C) 2020 KeePassXC team <https://keepassxc.org/>
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation, either version 2 or (at your option)
  11. # version 3 of the License.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # How to use: (assuming you check out stuff in ~/src)
  22. #
  23. # 0. Make sure to have a clean working tree
  24. #
  25. # 1. Download the Material Design icon set:
  26. # $ cd ~/src
  27. # $ git clone https://github.com/Templarian/MaterialDesign.git
  28. #
  29. # 2. Go to the icon source directory:
  30. # $ cd ~/src/keepassxc/share/icons
  31. #
  32. # 3. Create the icons:
  33. # $ bash ../../utils/makeicons.sh ~/src/MaterialDesign
  34. #
  35. # 4. Re-build and run KeePassXC:
  36. # $ cd ~/keepassxc/build
  37. # $ make keepassxc && src/keepassxc
  38. #
  39. # Material icons: https://materialdesignicons.com/
  40. NC='\033[0m'
  41. RED='\033[0;31m'
  42. YELLOW='\033[0;33m'
  43. if [[ $# != 1 ]]; then
  44. echo "Usage: $0 MATERIAL"
  45. echo "MATERIAL is the directory containing the material icons repository"
  46. echo "(git clone https://github.com/Templarian/MaterialDesign.git)".
  47. exit
  48. fi
  49. MATERIAL=$1
  50. if [[ ! -d $MATERIAL ]]; then
  51. echo -e "${RED}Material Icons directory does not exist: ${MATERIAL}${NC}"
  52. exit 1
  53. fi
  54. # Check destination dir
  55. DSTDIR=share/icons/application
  56. if [[ ! -d $DSTDIR ]]; then
  57. echo -e "${RED}Please invoke this script from the KeePassXC source root directory.${NC}"
  58. exit 1
  59. fi
  60. # Map KeePassXC icon names to Material icon names.
  61. # $1 is the name of the icon file in the KeePassXC source (without
  62. # path and without extension, e. g. "document-new").
  63. # Writes the name of the Material icon (without path and without
  64. # extension, e. g. "folder-plus") to stdout.
  65. # If the icon name is unknown, outputs nothing.
  66. map() {
  67. case $1 in
  68. application-exit) echo exit-run ;;
  69. auto-type) echo keyboard-variant ;;
  70. bugreport) echo bug-outline ;;
  71. chronometer) echo clock-outline ;;
  72. clipboard-text) echo clipboard-text-outline ;;
  73. configure) echo cog-outline ;;
  74. database-change-key) echo key ;;
  75. database-close) echo close ;;
  76. database-lock) echo lock-outline ;;
  77. database-merge) echo merge ;;
  78. dialog-close) echo close ;;
  79. dialog-error) echo alert-circle-outline ;;
  80. dialog-information) echo information-outline ;;
  81. dialog-ok) echo checkbox-marked-circle ;;
  82. dialog-warning) echo alert-outline ;;
  83. document-close) echo close ;;
  84. document-edit) echo pencil ;;
  85. document-export) echo export ;;
  86. document-import) echo import ;;
  87. document-new) echo plus ;;
  88. document-open) echo folder-open-outline ;;
  89. document-open-recent) echo folder-clock-outline ;;
  90. document-properties) echo file-edit-outline ;;
  91. document-save) echo content-save-outline ;;
  92. document-save-as) echo content-save-all-outline ;;
  93. document-save-copy) echo content-save-move-outline ;;
  94. donate) echo gift-outline ;;
  95. edit-clear-locationbar-ltr) echo backspace-reverse-outline ;;
  96. edit-clear-locationbar-rtl) echo backspace-outline ;;
  97. entry-clone) echo plus-circle-multiple-outline ;;
  98. entry-delete) echo close-circle-outline ;;
  99. entry-edit) echo pencil-circle-outline ;;
  100. entry-new) echo plus-circle-outline ;;
  101. favicon-download) echo download ;;
  102. getting-started) echo lightbulb-on-outline ;;
  103. group-delete) echo folder-remove-outline ;;
  104. group-edit) echo folder-edit-outline ;;
  105. group-empty-trash) echo trash-can-outline ;;
  106. group-new) echo folder-plus-outline ;;
  107. health) echo heart-pulse ;;
  108. help-about) echo information-outline ;;
  109. internet-web-browser) echo web ;;
  110. keyboard-shortcuts) echo apple-keyboard-command ;;
  111. key-enter) echo keyboard-variant ;;
  112. message-close) echo close ;;
  113. move-down) echo chevron-double-down ;;
  114. move-up) echo chevron-double-up ;;
  115. object-locked) echo lock-outline ;;
  116. object-unlocked) echo lock-open-variant-outline ;;
  117. paperclip) echo paperclip ;;
  118. password-copy) echo key-arrow-right ;;
  119. password-generate) echo dice-3-outline ;;
  120. password-generator) echo dice-3-outline ;;
  121. password-show-off) echo eye-off-outline ;;
  122. password-show-on) echo eye-outline ;;
  123. preferences-desktop-icons) echo emoticon-happy-outline ;;
  124. preferences-other) echo file-document-edit-outline ;;
  125. preferences-system-network-sharing) echo lan ;;
  126. refresh) echo refresh ;;
  127. reports) echo lightbulb-on-outline ;;
  128. reports-exclude) echo lightbulb-off-outline ;;
  129. security-high) echo shield-outline ;;
  130. sort-alphabetical-ascending) echo sort-alphabetical-ascending ;;
  131. sort-alphabetical-descending) echo sort-alphabetical-descending ;;
  132. statistics) echo chart-line ;;
  133. system-help) echo help ;;
  134. system-search) echo magnify ;;
  135. system-software-update) echo cloud-download-outline ;;
  136. url-copy) echo earth-arrow-right ;;
  137. user-guide) echo book-open-outline ;;
  138. username-copy) echo account-arrow-right-outline ;;
  139. utilities-terminal) echo console-line ;;
  140. view-history) echo timer-sand-empty ;;
  141. web) echo web ;;
  142. esac
  143. }
  144. # Now do the actual work
  145. find "$DSTDIR" -type f -name "*.svg" | while read -r DST; do
  146. # Find the icon name (base name without extender)
  147. NAME=$(basename "$DST" .svg)
  148. # Find the base name of the svg file for this icon
  149. MAT=$(map "$NAME")
  150. if [[ -z $MAT ]]; then
  151. echo -e "${YELLOW}Warning: No MaterialDesign mapping for ${NAME}${NC}"
  152. continue
  153. fi
  154. # So the source file is:
  155. SRC="$MATERIAL/svg/$MAT.svg"
  156. if [[ ! -f $SRC ]]; then
  157. echo -e "${RED}Error: Source for ${NAME} doesn't exist: ${SRC}${NC}"
  158. continue
  159. fi
  160. # Replace the icon file with the source file
  161. cp -- "$SRC" "$DST" || exit
  162. echo "Copied icon for ${NAME}"
  163. done