tazpkg diff tazpkg @ rev 819

tazpkg: re-write "desc" function to use all available sorts of descriptions (installed, mirrored, short, long, localized)
author Aleksej Bobylev <al.bobylev@gmail.com>
date Fri Jul 24 15:11:32 2015 +0300 (2015-07-24)
parents d2eaee40047c
children 5c4634856840
line diff
     1.1 --- a/tazpkg	Sun Jul 19 15:17:03 2015 +0300
     1.2 +++ b/tazpkg	Fri Jul 24 15:11:32 2015 +0300
     1.3 @@ -1547,17 +1547,40 @@
     1.4  
     1.5  	desc|-d)
     1.6  		# Display package description
     1.7 -		if [ -n "$(grep -e "^$PACKAGE"$'\t' $PKGS_DB/installed.info)" ]; then
     1.8 +		unset desc
     1.9 +
    1.10 +		# 1) Localized description
    1.11 +		for LC in $LANG ${LANG%_*}; do
    1.12 +			[ -e "$PKGS_DB/descriptions.$LC.txt" ] &&
    1.13 +			desc="$(awk -vRS='' -vFS='\n' -vOFS='\n' -vp="$PACKAGE" '
    1.14 +				$1 == p { $1 = ""; print $0; exit; }
    1.15 +				' "$PKGS_DB/descriptions.$LC.txt" | sed '1d')"
    1.16 +		done
    1.17 +
    1.18 +		# 2) Installed description
    1.19 +		if [ -z "$desc" -a -s "$INSTALLED/$PACKAGE/description.txt" ]; then
    1.20 +			desc="$(cat "$INSTALLED/$PACKAGE/description.txt")"
    1.21 +		fi
    1.22 +
    1.23 +		# 3) Mirrored description
    1.24 +		if [ -z "$desc" -a -s "$PKGS_DB/descriptions.txt" ]; then
    1.25 +			desc="$(awk -vRS='' -vFS='\n' -vOFS='\n' -vp="$PACKAGE" '
    1.26 +				$1 == p { $1 = ""; print $0; exit; }
    1.27 +				' "$PKGS_DB/descriptions.txt" | sed '1d')"
    1.28 +		fi
    1.29 +
    1.30 +		# 4) Short description only in terminal
    1.31 +		if [ -z "$desc" ] && im; then
    1.32 +			desc="$(print_short_description "$PACKAGE")"
    1.33 +		fi
    1.34 +
    1.35 +		if [ -n "$desc" ]; then
    1.36 +			# Title and footer only in terminal
    1.37  			im && title 'Description of package "%s"' "$PACKAGE"
    1.38 -			if [ -s "$INSTALLED/$PACKAGE/description.txt" ]; then
    1.39 -				cat "$INSTALLED/$PACKAGE/description.txt"
    1.40 -			else
    1.41 -				im && awk -F$'\t' -vp="$PACKAGE" '{
    1.42 -					if ($1 == p) print $4 }' $PKGS_DB/installed.info
    1.43 -			fi
    1.44 +			echo "$desc"
    1.45  			im && footer
    1.46  		else
    1.47 -			im && _ 'Package "%s" is not installed.' "$PACKAGE"
    1.48 +			im && _ 'Description absent.'
    1.49  		fi
    1.50  		;;
    1.51