From beafd4c14d52004d059b6891a95d873df6221796 Mon Sep 17 00:00:00 2001 From: Jens Petersen Date: Sun, 12 Nov 2023 15:44:36 +0800 Subject: [PATCH] improve ghc-info.sh with a show mode --- ghc-info.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ghc-info.sh b/ghc-info.sh index af1eabf..598faa2 100755 --- a/ghc-info.sh +++ b/ghc-info.sh @@ -1,8 +1,12 @@ #!/bin/sh -[ $# -lt 2 ] && echo "Usage: $(basename "$0") GHCVERSION INFOFIELD" +[ $# -lt 1 ] && echo "Usage: $(basename "$0") GHCVERSION INFOFIELD" && exit 1 -GHCVER=$1 -FIELD=$2 +GHCVER="$1" +FIELD="$2" -/usr/bin/ghc-${GHCVER} --info | grep \"$FIELD\" | sed -e 's/.*","\(.*\)")/\1/' +if [ -z "$FIELD" ]; then + /usr/bin/ghc-${GHCVER} --info | sed -e 's/.*(\(".*"\),\(".*"\).*/\1: \2/' -e '/]/d' +else + /usr/bin/ghc-${GHCVER} --info | grep \""$FIELD"\" | sed -e 's/.*","\(.*\)")/\1/' +fi