mirror of
https://github.com/QuantumPackage/qp2.git
synced 2024-12-22 20:34:58 +01:00
Improved zcat
This commit is contained in:
parent
b51679b35e
commit
b2a593dd2f
27
bin/zcat
27
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 sys
|
||||||
import gzip
|
import gzip
|
||||||
|
with gzip.open("$1", "rt") as f:
|
||||||
# Check if a file path has been provided
|
|
||||||
if len(sys.argv) < 2:
|
|
||||||
print("Usage: zcat <filename>")
|
|
||||||
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
|
|
||||||
print(f.read())
|
print(f.read())
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
command=$(which -a zcat | grep -v 'qp2/bin/' | head -1)
|
||||||
|
exec command
|
||||||
|
fi
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user