zuno / slackpkgplus

slackpkg+
57 stars 10 forks source link

Patch for terse, colored search output #16

Closed edrozenberg closed 3 years ago

edrozenberg commented 3 years ago

In case anyone else finds it useful, for my own use I customize slackpkgplus.sh with changes similar to the below. The only thing left that's not perfect for my OCD :) is that search results for upgrade entries are long (show both current and suggested pkg names) and don't fit in 80x25, flowing to a second line.

Patch to modify slackpkg search output:

+# Color escape codes +c_red='\033[0;31m' +c_grn='\033[0;32m' +c_yel='\033[0;33m' +c_blu='\033[0;34m' +c_cyn='\033[0;36m' +c_blk='\033[1;30m' +c_gry='\033[1;90m' +c_wht='\033[1;67m' +c_hid='\033[8m' +c_off='\033[0m' + declare -A MIRRORPLUS declare -A NOTIFYMSG

@@ -1266,7 +1278,7 @@ local PNAME

 {

@@ -1288,11 +1300,13 @@ RAWNAME="${PNAME/%.t[blxg]z/}"

   # Default is uninstalled
zuno commented 3 years ago

There was a similar proposal in past but I cannot find it (about 5y ago). It's a good idea but may be improved

set TERSESEARCH= off/on/tiny

test it with more background color (I've a light yellow background shell)

[edit]replaced done #|sort with done|sort[/edig]

diff --git a/src/slackpkgplus.sh b/src/slackpkgplus.sh
index 3bc9b64..7286ef6 100755
--- a/src/slackpkgplus.sh
+++ b/src/slackpkgplus.sh
@@ -1,5 +1,23 @@
 # vim: set tabstop=2 shiftwidth=2 expandtab 

+# Color escape codes
+c_blk='\033[1;30m'
+c_red='\033[1;31m'
+c_grn='\033[1;32m'
+c_yel='\033[1;33m'
+c_blu='\033[1;34m'
+c_mag='\033[1;35m'
+c_cyn='\033[1;36m'
+c_gry='\033[1;90m'
+c_wht='\033[1;67m'
+c_hid='\033[8m'
+c_off='\033[0m'
+
+c_upgr="$c_red"
+c_inst="$c_grn"
+c_mask="$c_gry"
+c_unin="$c_blu"
+
 # Thanks to AlienBob and phenixia2003 (on LQ) for contributing
 # A special thanks to all packagers that make slackpkg+ useful

@@ -32,6 +50,7 @@ if [ -e $CONF/slackpkgplus.conf ];then
   EXTDETAILED_INFO=$DETAILED_INFO
   EXTWW_FILE_SEARCH=$WW_FILE_SEARCH
   EXTUSETERSE=$USETERSE
+  EXTTERSESEARCH=$TERSESEARCH
   EXTPROXY=$PROXY

   . $CONF/slackpkgplus.conf
@@ -51,6 +70,7 @@ if [ -e $CONF/slackpkgplus.conf ];then
   DETAILED_INFO=${EXTDETAILED_INFO:-$DETAILED_INFO}
   WW_FILE_SEARCH=${EXTWW_FILE_SEARCH:-$WW_FILE_SEARCH}
   USETERSE=${EXTUSETERSE:-$USETERSE}
+  TERSESEARCH=${EXTTERSESEARCH:-$TERSESEARCH}
   PROXY=${EXTPROXY:-$PROXY}

   if [ "$PROXY" == "off" ];then
@@ -1266,7 +1286,7 @@ if [ "$SLACKPKGPLUS" = "on" ];then
     local PNAME

     {
-    echo "[ Status#] [ Repository#] [ Package# ]"
+    [ "$TERSESEARCH" == "off" ] && echo "[ Status#] [ Repository#] [ Package# ]"

     INSTPKGS="$(ls -f $ROOT/var/log/packages/)"

@@ -1315,8 +1335,13 @@ if [ "$SLACKPKGPLUS" = "on" ];then

             # If installed is it uptodate?
             if [ "${CINSTPKG}" = "${RAWNAME}" ]; then
-              STATUS="installed"
-              echo "  $STATUS#    $REPO#    $CINSTPKG"
+             if [ "$TERSESEARCH" == "off" ];then
+               echo "  installed#    $REPO#    $CINSTPKG"
+             elif [ "$TERSESEARCH" == "tiny" ];then
+               echo -e "[${c_inst}I${c_off}]#$REPO#:#$CINSTPKG"
+             else
+               echo -e "[${c_inst}inst${c_off}]#$REPO#:#$CINSTPKG"
+             fi
             else

               INSTPKG_REPO=$(grep -m 1 " $CINSTPKG " ${WORKDIR}/pkglist | cut -f1 -d" " | sed "s/SLACKPKGPLUS_//")
@@ -1325,15 +1350,27 @@ if [ "$SLACKPKGPLUS" = "on" ];then
                 CINSTPKG="$INSTPKG_REPO:$CINSTPKG"
               fi

-              STATUS="upgrade"
-              echo "  $STATUS#    $REPO#    $CINSTPKG --> ${RAWNAME}"
+             if [ "$TERSESEARCH" == "off" ];then
+               echo "  upgrade#    $REPO#    $CINSTPKG --> ${RAWNAME}"
+             elif [ "$TERSESEARCH" == "tiny" ];then
+               echo -e "[${c_upgr}U${c_off}]#$REPO#:#$CINSTPKG --> ${RAWNAME}"
+             else
+               echo -e "[${c_upgr}upgr${c_off}]#$REPO#:#$CINSTPKG --> ${RAWNAME}"
+             fi
+
             fi
           fi
         done
       else
-        echo "  $STATUS#    $REPO#    ${RAWNAME}"
+       if [ "$TERSESEARCH" == "off" ];then
+         echo "  $STATUS#    $REPO#    ${RAWNAME}"
+       elif [ "$TERSESEARCH" == "tiny" ];then
+         echo -e "[$(echo $STATUS|sed -e "s/uninstalled(masked)/\\${c_mask}M\\${c_off}/" -e "s/uninstalled/\\${c_unin}-\\${c_off}/")]#$REPO#:#${RAWNAME}"
+       else
+         echo -e "[$(echo $STATUS|sed -e "s/uninstalled(masked)/\\${c_mask}mask\\${c_off}/" -e "s/uninstalled/\\${c_unin}unin\\${c_off}/")]#$REPO#:#${RAWNAME}"
+       fi
       fi
     done|sort
     echo -en "\r" >&2
edrozenberg commented 3 years ago

@zuno this looks great thanks!

Added to my slackpkgplus.conf:

# Set TERSESEARCH to off/on/tiny to determine output of `slackpkg search`
TERSESEARCH=<somevalue>

With TERSESEARCH=on

TERSESEARCH on

With TERSESEARCH=tiny

TERSESEARCH tiny
zuno commented 3 years ago

pushed on test branch

zuno commented 3 years ago

1.7.5 released to include it.

edrozenberg commented 3 years ago

Sounds great thanks! Will download the latest.

edrozenberg commented 3 years ago

There's a small correction needed for slackpkgplus.x86.sample and slackpkgplus.x86_64.sample for the [U] upgrade letter:

Currently: # tiny: [-] uninstalled, [I] installed, [I] upgrade, [M] uninstalled/masked

Should be: # tiny: [-] uninstalled, [I] installed, [U] upgrade, [M] uninstalled/masked