mirror of
https://github.com/FAUSheppy/config
synced 2026-04-26 19:42:30 +02:00
Compare commits
3 Commits
52c4454da1
...
cad812d787
| Author | SHA1 | Date | |
|---|---|---|---|
| cad812d787 | |||
| 0da972ce7e | |||
| e89098ec0a |
43
binary_checker.py
Executable file
43
binary_checker.py
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
|
||||
def is_binary(path, chunk_size=1024):
|
||||
try:
|
||||
with open(path, 'rb') as f:
|
||||
chunk = f.read(chunk_size)
|
||||
if not chunk:
|
||||
return False # empty file → treat as text
|
||||
|
||||
# If there are null bytes, it's very likely binary
|
||||
if b'\x00' in chunk:
|
||||
return True
|
||||
|
||||
# Define what we consider "text" bytes
|
||||
text_bytes = bytearray(range(32, 127)) + b'\n\r\t\f\b'
|
||||
|
||||
# Count non-text bytes
|
||||
nontext = sum(byte not in text_bytes for byte in chunk)
|
||||
|
||||
# If more than 30% are non-text, treat as binary
|
||||
return (nontext / len(chunk)) > 0.3
|
||||
|
||||
except Exception:
|
||||
# On error (e.g., file not readable), treat as binary
|
||||
return True
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print(f"Usage: {sys.argv[0]} <file>", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
path = sys.argv[1]
|
||||
|
||||
if is_binary(path):
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
35
zshrc
35
zshrc
@@ -229,4 +229,37 @@ alias connect_synology="ssh -f -o ExitOnForwardFailure=yes -i ~/.ssh/sheppy-mast
|
||||
#alias tcpdump_http=stdbuf -oL -eL /usr/bin/tcpdump -A -s 10240 "tcp port 8000 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)" | egrep -a --line-buffered ".+(GET |HTTP\/|POST )|^[A-Za-z0-9-]+: " | perl -nle 'BEGIN{$|=1} { s/.*?(GET |HTTP\/[0-9.]* |POST )/\n$1/g; print }'
|
||||
ths_ssh="ssh -f -o ExitOnForwardFailure=yes -i .ssh/sheppy-master -L 8000:host.docker.internal:22 root@172.16.1.4 sleep 3600 && ssh cheffe@localhost -p 8000"
|
||||
#trap ctrl_c INT; function ctrl_c() {};
|
||||
alias sss='ssh root@192.168.1.89 -t "systemctl suspend; exit"'
|
||||
alias sss='ssh root@192.168.1.48 -t "systemctl suspend; exit"'
|
||||
|
||||
alias json_to_yaml="jq . $@ | yq -y"
|
||||
|
||||
cat() {
|
||||
|
||||
# no args
|
||||
if [[ $# -eq 0 ]]; then
|
||||
command cat
|
||||
return
|
||||
fi
|
||||
|
||||
for file in "$@"; do
|
||||
|
||||
# Skip non-regular files (pipes, etc.)
|
||||
if [[ ! -f "$file" ]]; then
|
||||
command cat "$file"
|
||||
continue
|
||||
fi
|
||||
|
||||
~/.config/binary_checker.py "$file"
|
||||
if [[ $? -ne 0 ]] then
|
||||
echo -n "'$file' looks a bit binary, you sure you wanna cat that? [y/N] "
|
||||
read reply
|
||||
|
||||
if [[ ! "$reply" =~ ^[Yy]$ ]]; then
|
||||
echo "Skipping '$file'"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
command cat "$file"
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user