Commit 3c6379b5ccaae10d65f32ecbc9877efaecd26af0

Thomas de Grivel 2023-02-06T17:08:58

shpkg installed

diff --git a/bin/shpkg b/bin/shpkg
index 8edd3c2..4f5cdd6 100755
--- a/bin/shpkg
+++ b/bin/shpkg
@@ -86,6 +86,9 @@ elif [ "x$1" = "xinstall" ] ||
      [ "x$1" = "xi" ]; then
     shift
     verbose 2 shpkg_install "$@"
+elif [ "x$1" = "xinstalled" ]; then
+    shift
+    verbose 2 shpkg_installed
 elif [ "x$1" = "xlist" ] ||
      [ "x$1" = "xl" ]; then
     shift
@@ -106,4 +109,6 @@ elif [ "x$1" = "xupdate" ]; then
 elif [ "x$1" = "xupgrade" ]; then
     shift
     verbose 2 shpkg_upgrade "$@"
+else
+    usage 1
 fi
diff --git a/share/shpkg/shpkg.subr b/share/shpkg/shpkg.subr
index 098ceb6..73b9941 100644
--- a/share/shpkg/shpkg.subr
+++ b/share/shpkg/shpkg.subr
@@ -509,9 +509,21 @@ shpkg_clean_all () {
     done
 }
 
+shpkg_installed () {
+    grep -Ev '\s+#' "${SHPKG_REPO_INDEX}" |
+        grep -Eo '^[^#]*' |
+        while read SHPKG_REPO SHPKG_REPO_DIR REST; do
+            SHPKG_REPO_INSTALLED="${SHPKG_VAR_DB_DIR}/installed/${SHPKG_REPO_DIR}"
+            if [ -f "${SHPKG_REPO_INSTALLED}" ]; then
+                echo -n "${SHPKG_REPO} "
+            fi
+        done
+    echo
+}
+
 shpkg_list () {
-    grep -Eo '^[^#]*' "${SHPKG_REPO_INDEX}" |
-        grep -Ev '\s+#' |
+    grep -Ev '\s+#' "${SHPKG_REPO_INDEX}" |
+        grep -Eo '^[^#]*' |
         while read SHPKG_REPO SHPKG_REPO_DIR REST; do
             SHPKG_REPO_SRC_DIR="${SHPKG_SRC_DIR}/${SHPKG_REPO_DIR}"
             SHPKG_REPO_INSTALLED="${SHPKG_VAR_DB_DIR}/installed/${SHPKG_REPO_DIR}"