about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2014-09-15 02:09:42 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2014-09-15 02:09:42 +0200
commitf97eb82f134406e20d9e6ee428123ce0bb905654 (patch)
tree23c1ba6e6696496f471df8b663a58ae93a077ab5
parent8909ba361996a50e2f0504c39ae67666a57e8457 (diff)
downloadxtools-f97eb82f134406e20d9e6ee428123ce0bb905654.tar.gz
xtools-f97eb82f134406e20d9e6ee428123ce0bb905654.tar.xz
xtools-f97eb82f134406e20d9e6ee428123ce0bb905654.zip
xq: strip colors, small refactor
-rwxr-xr-xxq14
1 files changed, 11 insertions, 3 deletions
diff --git a/xq b/xq
index 12c857f..29a1b48 100755
--- a/xq
+++ b/xq
@@ -1,15 +1,23 @@
 #!/bin/sh
 # xq PKGS... - query information about XBPS package
 
+rmcol() {
+	sed 's/\x1b\[[0-9;]*[mG]//g'
+}
+
+totop() {
+	sed -n 's/^'"$1"'/&/p;tk;H;:k;${x;s/\n//;p};d'
+}
+
 BRANCH=$(git symbolic-ref -q --short HEAD 2>/dev/null)
 ADDREPO="--repository=hostdir/binpkgs/$BRANCH
 	--repository=../hostdir/binpkgs/$BRANCH
 	--repository=../../hostdir/binpkgs/$BRANCH"
 
 for pkg; do
-	xbps-query $ADDREPO -S "$pkg" |
-		sed -n 's/^short_desc/&/p;tk;H;:k;${x;s/\n//;p};d' |
-		sed -n 's/^pkgver/&/p;tk;H;:k;${x;s/\n//;p};d'
+	xbps-query $ADDREPO -S "$pkg" | rmcol |
+		totop short_desc |
+		totop pkgver
 	xbps-query $ADDREPO -x "$pkg" | sed 's/^/	/;1s/^/depends:\n/'
 	REVDEP=$(xbps-query -X "$pkg" | sed 's/^/	/' )
 	if [ "$REVDEP" ]; then