From b2a593dd2fc8326a03defd20d7f30aa6b0291b4a Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 18 Apr 2023 11:27:51 +0200 Subject: [PATCH] Improved zcat --- bin/zcat | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/bin/zcat b/bin/zcat index ebf64b7d..ae11ce84 100755 --- a/bin/zcat +++ b/bin/zcat @@ -1,15 +1,22 @@ -#!/usr/bin/env python3 +#!/bin/bash +# On Darwin: try gzcat if available, otherwise use Python + +if [[ $(uname -s) = Darwin ]] ; then + which gzcat &> /dev/null + if [[ $? -eq 0 ]] ; then + exec gzcat $@ + else + + exec python3 << EOF import sys import gzip - -# Check if a file path has been provided -if len(sys.argv) < 2: - print("Usage: zcat ") - sys.exit(1) - -# Open the gzip file -with gzip.open(sys.argv[1], "rt") as f: - # Read the contents of the file and print to standard output +with gzip.open("$1", "rt") as f: print(f.read()) +EOF + fi +else + command=$(which -a zcat | grep -v 'qp2/bin/' | head -1) + exec command +fi