: nply/git-summary

commit 3d221c487337f40cae97d105ca6e26e17bdccdbd
parent e71fbff0de9301ea7c51e4d2defc89af2189b47f
Author: Mirko Ledda <mko.ledda@gmail.com>
Date: Fri, 21 May 2021 08:45:19 +0200

Merge pull request #7 from auphofBSF/FIX/GCP-COS-support

feat: add alpine container support in Google Cloud Platform, Container Optimised OS
2 files changed, 21 insertions(+), 5 deletions(-)
M
README.md
|
6
+++++-
M
git-summary
|
20
++++++++++++++++----
diff --git a/README.md b/README.md
@@ -12,7 +12,7 @@ git-summary is a bash script that will neatly list the current status of any git
 <img src="screenshot.png" width="60%">
 
 ## Requirements
-**Currently supported operating systems:** Linux, MacOS and Cygwin
+**Currently supported operating systems:** Linux, MacOS and Cygwin, containers (alpine based) on Google Cloud Platform - Container Optimised OS (Chromium OS)
 
 ### Linux
 * `sudo apt-get install gawk`

@@ -20,6 +20,10 @@ git-summary is a bash script that will neatly list the current status of any git
 ### MacOS
 * `brew install coreutils`
 
+### in Container on Google Cloud Platform - Container Optimised OS (alpine based containers)
+xargs in Chromium OS does not support -L option, findutils puts an xargs with support for -L
+* `apk add gawk findutils`
+
 ## Installation
 ### Via aliasing
 Clone this repo and alias the script. To do so, add the following line to `~\.bashrc`:
diff --git a/git-summary b/git-summary
@@ -131,10 +131,17 @@ detect_OS() {
     dirname_cmd="gdirname"
     gawk_cmd="awk"
   elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then  # Linux
-    OS=Linux
-    readlink_cmd="readlink"
-    dirname_cmd="dirname"
-    gawk_cmd="gawk"
+    if [[ $(cat /proc/version) == *"Chromium OS"* ]]; then
+      OS=Linux
+      readlink_cmd="readlink"
+      dirname_cmd="dirname_zero"
+      gawk_cmd="gawk"
+    else
+      OS=Linux
+      readlink_cmd="readlink"
+      dirname_cmd="dirname"
+      gawk_cmd="gawk"
+    fi
   elif [ "$(expr substr $(uname -s) 1 6)" == "CYGWIN" ]; then  # Cygwin
     OS=CYGWIN
     readlink_cmd="readlink"

@@ -148,6 +155,11 @@ detect_OS() {
 
 GIT4WINDOWS=1
 
+#  `dirname -z` does not exist on  Chromium OS (Google Cloud Platform - Container Optimised OS)
+dirname_zero(){
+    printf '%b' $(dirname $2)'\0'
+}
+
 detect_Git4Windows() {
     if [[ "$OS" == "CYGWIN" && "$(git --version)" == *"windows"* ]]; then
        GIT4WINDOWS=0