wok annotate sdft/stuff/sdft @ rev 22781

updated freetype and freetype-dev (2.6.4 -> 2.10.1)
author Hans-G?nter Theisgen
date Sun Jan 26 09:26:49 2020 +0100 (2020-01-26)
parents f226094b72d6
children
rev   line source
al@16921 1 #!/bin/sh
al@16921 2 # sdft - SliTaz Desktop Files Tools
al@19496 3 # - tools for editing and pretty printing .desktop files for SliTaz Linux
al@19847 4 # Aleksej Bobylev <al.bobylev@gmail.com>, 2014-2017
al@16921 5
al@19847 6 VERSION="170314"
al@16921 7
al@16921 8 ### functions ###
al@16921 9 usage() {
al@19496 10 cat <<EOT
al@16921 11 sdft - SliTaz Desktop Files Tools, v. $VERSION
al@19496 12 Tools for editing and pretty printing .desktop files for SliTaz Linux
al@16921 13
al@16921 14 Usage:
al@16921 15 sdft /path/to/file.desktop [COMMAND ...]
al@16921 16
al@16921 17 Commands:
al@16921 18 -a "LINE" Add a LINE to .desktop file
al@16921 19 -r "LINE" Remove all lines with LINE
al@16921 20 -s "LINE" Substitute existing LINE (like '-r' then '-a')
al@16921 21 -g Remove GenericName lines (who uses it?)
al@16921 22 -x Remove X- lines
al@16921 23 -t Remove Terminal line
al@16921 24 -tf Remove Terminal=false line
al@16921 25 -te Remove TryExec line
al@16921 26 -o Remove sections other than '[Desktop Entry]'
al@19496 27 -k "LIST" Keep only specified locales and remove the rest
al@16921 28 -i In-place edit (replace original)
al@16921 29
al@16921 30 Examples:
al@19496 31 sdft \$src/my.desktop -a "Name[en_GB]=Desktop"
al@19496 32 sdft \$src/my.desktop -r "Name[en_GB]"
al@19496 33 sdft \$src/my.desktop -s "Categories=Utility;Calculator;"
al@19496 34 sdft \$src/my.desktop -r "X-GNOME-.*"
al@19496 35 sdft \$src/my.desktop -a "Name[en_GB]=Desktop" -g -o
al@19496 36 sdft \$src/my.desktop -k "en pt ru" # keeps en en_GB en_US pt pt_BR ru ru_UA...
al@16921 37
al@16921 38 EOT
al@16921 39 }
al@19496 40
al@16921 41 extract() {
al@19847 42 local EX="${1//[/\[}"; EX="${EX//]/\]}"
al@19496 43 grep -e "^$EX=" $WORKING/section
al@16921 44 sed -i "/^$EX=/d" $WORKING/section
al@16921 45 }
al@19496 46
al@16921 47 extract_no_repeat() {
al@16921 48 local IT_NAME="$1" IT_CONTENT
al@16921 49 IT_CONTENT=$(extract "$IT_NAME" | sed "s|$IT_NAME=\(.*\)|\1|")
al@19496 50 [ -n "$IT_CONTENT" ] && echo "$IT_NAME=$IT_CONTENT"
al@18554 51 extract "$IT_NAME[.*]" | sort #| sed -n "/$IT_NAME\[.*\]=$IT_CONTENT$/!p"
al@16921 52 }
al@19496 53
al@16921 54 semicolon() {
al@16921 55 sed -e 's|.*|&;|' -e 's|;;|;|g'
al@16921 56 }
al@19496 57
al@16921 58 ### /functions ###
al@16921 59
al@16921 60
al@16921 61
al@16921 62 case "$1" in
al@19496 63 ''|-h|--help) usage; exit 0 ;;
al@16921 64 -v|-V|--version) echo "sdft v. $VERSION"; exit 0 ;;
al@16921 65 esac
al@16921 66
al@19496 67 [ ! -s "$1" ] && exit 1
al@19496 68
al@19496 69
al@16921 70 # working dir
al@16921 71 WORKING=$(mktemp -d)
al@16921 72 # original .desktop file to process it
al@16921 73 ORIGINAL="$WORKING/original.desktop"
al@16921 74 DESKTOP="$1"; cp "$DESKTOP" $ORIGINAL
al@16921 75
al@16921 76 SECTION="Desktop Entry"
al@16921 77 if ! grep -qF "[$SECTION]" "$ORIGINAL"; then
al@16921 78 echo "Seems $1 is not a Desktop file. Abort" >&2
al@16921 79 exit 1
al@16921 80 fi
al@16921 81
al@16921 82 # extract section content
al@16921 83 sed -n "/^\[$SECTION\]$/,/^\[.*\]$/{/^\[/!p}" $ORIGINAL > $WORKING/section
al@16921 84
al@16921 85 # rest of the file
al@16921 86 sed "/^\[$SECTION\]$/,/^\[.*\]$/{/^[^\[]/d}" $ORIGINAL | sed "/^\[$SECTION\]$/d" > $WORKING/rest
al@16921 87
al@16921 88 shift
al@19496 89 while [ -n "$1" ]; do
al@16921 90 case "$1" in
al@19496 91 -a) shift; echo "$1" >> $WORKING/section; shift ;;
al@19496 92 -r) shift; extract "$1" >/dev/null; shift ;;
al@19496 93 -s) shift; extract "${1%%=*}" >/dev/null; echo "$1" >> $WORKING/section; shift ;;
al@19496 94 -g) shift; extract_no_repeat 'GenericName' >/dev/null ;;
al@19496 95 -x) shift; extract 'X-.*' >/dev/null ;;
al@19496 96 -t) shift; extract 'Terminal' >/dev/null ;;
al@19496 97 -te) shift; extract 'TryExec' >/dev/null ;;
al@19496 98 -tf) shift; sed -i '/^Terminal=false$/d' $WORKING/section ;;
al@19496 99 -o) shift; REMOVE_OTHER='yes' ;;
al@19496 100 -k) shift; klocales="$1"; shift ;;
al@19496 101 -i) shift; IN_PLACE='yes' ;;
al@19496 102 *) echo "Unknown command '$1'" >&2; shift ;;
al@16921 103 esac
al@16921 104 done
al@16921 105
al@16921 106 {
al@16921 107 echo "[$SECTION]"
al@19496 108 extract 'Encoding' >/dev/null
al@19496 109 extract 'Version' >/dev/null
al@16921 110 extract 'Type'
al@16921 111 extract_no_repeat 'Name'
al@16921 112 extract_no_repeat 'GenericName'
al@16921 113 extract_no_repeat 'Comment'
al@16921 114 extract 'Terminal'
al@16921 115 extract 'StartupNotify'
al@16921 116 extract 'TryExec'
al@16921 117 extract 'Exec'
al@19496 118 extract 'Icon'
al@19496 119 extract 'Icon[.*]' >/dev/null
al@16921 120 extract 'Categories' | sed 's|Application;||' | semicolon
al@16921 121 extract 'NoDisplay'
al@16921 122 extract 'MimeType' | semicolon
al@16921 123
pascal@22023 124 sort < $WORKING/section | sed -n '/^$/!p'
pascal@22023 125 [ "$REMOVE_OTHER" != 'yes' ] && sed -n '/^$/!p' < $WORKING/rest
al@16921 126 } > $WORKING/new
al@16921 127
al@19496 128
al@19496 129 if [ -n "$klocales" ]; then
al@19496 130 # Existing locales from Name, GenericName and Comment
al@19496 131 elocales=" $(sed -n 's%\(Name\|Comment\)\[\([a-zA-Z@_]*\)\].*%\2%p' $WORKING/new | sort -u | tr '\n' ' ') "
al@19496 132 for klocale in $klocales; do
al@19496 133 elocales=${elocales//$klocale}
al@19496 134 done
al@19496 135 for elocale in $elocales; do
al@19496 136 sed -i "/\[$elocale\]/d" $WORKING/new
al@19496 137 done
al@19496 138 fi
al@19496 139
al@19496 140
al@19496 141 if [ "$IN_PLACE" == 'yes' ]; then
al@16921 142 cp -f $WORKING/new "$DESKTOP"
al@16921 143 else
al@16921 144 cat $WORKING/new
al@16921 145 fi
al@16921 146
al@16921 147 # clean
al@16921 148 rm -rf $WORKING