wok-6.x rev 16921
Add sdft.
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Thu Jul 17 20:58:52 2014 +0300 (2014-07-17) |
parents | c8d463cdcdb3 |
children | 371ffcd4f10c 952382c025de |
files | sdft/receipt sdft/stuff/sdft |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/sdft/receipt Thu Jul 17 20:58:52 2014 +0300 1.3 @@ -0,0 +1,16 @@ 1.4 +# SliTaz package receipt. 1.5 + 1.6 +PACKAGE="sdft" 1.7 +VERSION="140717" 1.8 +CATEGORY="development" 1.9 +SHORT_DESC="SliTaz Desktop Files Tools" 1.10 +MAINTAINER="al.bobylev@gmail.com" 1.11 +LICENSE="GPL3" 1.12 +WEB_SITE="http://www.slitaz.org/" 1.13 + 1.14 +# Rules to gen a SliTaz package suitable for Tazpkg. 1.15 +genpkg_rules() 1.16 +{ 1.17 + mkdir -p $fs/usr/bin 1.18 + install -m 755 -o root $stuff/sdft $fs/usr/bin/sdft 1.19 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/sdft/stuff/sdft Thu Jul 17 20:58:52 2014 +0300 2.3 @@ -0,0 +1,124 @@ 2.4 +#!/bin/sh 2.5 +# sdft - SliTaz Desktop Files Tools 2.6 +# - tools for edit and pretty print .desktop files for SliTaz GNU/Linux 2.7 +# Aleksej Bobylev <al.bobylev@gmail.com>, 2014 2.8 + 2.9 +VERSION="040717" 2.10 + 2.11 +### functions ### 2.12 +usage() { 2.13 + cat << "EOT" 2.14 +sdft - SliTaz Desktop Files Tools, v. $VERSION 2.15 +Tools for edit and pretty print .desktop files for SliTaz GNU/Linux 2.16 + 2.17 +Usage: 2.18 +sdft /path/to/file.desktop [COMMAND ...] 2.19 + 2.20 +Commands: 2.21 +-a "LINE" Add a LINE to .desktop file 2.22 +-r "LINE" Remove all lines with LINE 2.23 +-s "LINE" Substitute existing LINE (like '-r' then '-a') 2.24 +-g Remove GenericName lines (who uses it?) 2.25 +-x Remove X- lines 2.26 +-t Remove Terminal line 2.27 +-tf Remove Terminal=false line 2.28 +-te Remove TryExec line 2.29 +-o Remove sections other than '[Desktop Entry]' 2.30 +-i In-place edit (replace original) 2.31 + 2.32 +Examples: 2.33 +sdft $src/my.desktop -a "Name[en_GB]=Desktop" 2.34 +sdft $src/my.desktop -r "Name[en_GB]" 2.35 +sdft $src/my.desktop -s "Categories=Utility;Calculator;" 2.36 +sdft $src/my.desktop -r "X-GNOME-.*" 2.37 +sdft $src/my.desktop -a "Name[en_GB]=Desktop" -g -o 2.38 + 2.39 +EOT 2.40 +} 2.41 +extract() { 2.42 + local EX=${1//[/\[}; EX=${EX//]/\]} 2.43 + grep -e "^$EX=" $WORKING/section 2.44 + sed -i "/^$EX=/d" $WORKING/section 2.45 +} 2.46 +extract_no_repeat() { 2.47 + local IT_NAME="$1" IT_CONTENT 2.48 + IT_CONTENT=$(extract "$IT_NAME" | sed "s|$IT_NAME=\(.*\)|\1|") 2.49 + [ "x$IT_CONTENT" != x ] && echo "$IT_NAME=$IT_CONTENT" 2.50 + extract "$IT_NAME[.*]" | sort | sed -n "/$IT_NAME\[.*\]=$IT_CONTENT$/!p" 2.51 +} 2.52 +semicolon() { 2.53 + sed -e 's|.*|&;|' -e 's|;;|;|g' 2.54 +} 2.55 +### /functions ### 2.56 + 2.57 + 2.58 + 2.59 +case "$1" in 2.60 + -h|--help) usage; exit 0 ;; 2.61 + -v|-V|--version) echo "sdft v. $VERSION"; exit 0 ;; 2.62 +esac 2.63 + 2.64 +# working dir 2.65 +WORKING=$(mktemp -d) 2.66 +# original .desktop file to process it 2.67 +ORIGINAL="$WORKING/original.desktop" 2.68 +DESKTOP="$1"; cp "$DESKTOP" $ORIGINAL 2.69 + 2.70 +SECTION="Desktop Entry" 2.71 +if ! grep -qF "[$SECTION]" "$ORIGINAL"; then 2.72 + echo "Seems $1 is not a Desktop file. Abort" >&2 2.73 + exit 1 2.74 +fi 2.75 + 2.76 +# extract section content 2.77 +sed -n "/^\[$SECTION\]$/,/^\[.*\]$/{/^\[/!p}" $ORIGINAL > $WORKING/section 2.78 + 2.79 +# rest of the file 2.80 +sed "/^\[$SECTION\]$/,/^\[.*\]$/{/^[^\[]/d}" $ORIGINAL | sed "/^\[$SECTION\]$/d" > $WORKING/rest 2.81 + 2.82 +shift 2.83 +while [ "x$1" != "x" ]; do 2.84 + case "$1" in 2.85 + -a) shift; echo "$1" >> $WORKING/section; shift ;; 2.86 + -r) shift; extract "$1" > /dev/null; shift ;; 2.87 + -s) shift; extract "${1%%=*}" > /dev/null; echo "$1" >> $WORKING/section; shift ;; 2.88 + -g) shift; extract_no_repeat 'GenericName' > /dev/null ;; 2.89 + -x) shift; extract 'X-.*' > /dev/null ;; 2.90 + -t) shift; extract 'Terminal' > /dev/null ;; 2.91 + -tf) shift; sed -i '/^Terminal=false$/d' $WORKING/section ;; 2.92 + -te) shift; extract 'TryExec' > /dev/null ;; 2.93 + -o) shift; REMOVE_OTHER="yes" ;; 2.94 + -i) shift; IN_PLACE="yes" ;; 2.95 + *) echo "Unknown command '$1'" >&2; shift ;; 2.96 + esac 2.97 +done 2.98 + 2.99 +{ 2.100 + echo "[$SECTION]" 2.101 + extract 'Encoding' > /dev/null 2.102 + extract 'Version' > /dev/null 2.103 + extract 'Type' 2.104 + extract_no_repeat 'Name' 2.105 + extract_no_repeat 'GenericName' 2.106 + extract_no_repeat 'Comment' 2.107 + extract 'Terminal' 2.108 + extract 'StartupNotify' 2.109 + extract 'TryExec' 2.110 + extract 'Exec' 2.111 + extract 'Icon'; extract 'Icon[.*]' > /dev/null 2.112 + extract 'Categories' | sed 's|Application;||' | semicolon 2.113 + extract 'NoDisplay' 2.114 + extract 'MimeType' | semicolon 2.115 + 2.116 + cat $WORKING/section | sort | sed -n '/^$/!p' 2.117 + [ "x$REMOVE_OTHER" != "xyes" ] && cat $WORKING/rest | sed -n '/^$/!p' 2.118 +} > $WORKING/new 2.119 + 2.120 +if [ "x$IN_PLACE" == "xyes" ]; then 2.121 + cp -f $WORKING/new "$DESKTOP" 2.122 +else 2.123 + cat $WORKING/new 2.124 +fi 2.125 + 2.126 +# clean 2.127 +rm -rf $WORKING