Skip to content

Instantly share code, notes, and snippets.

@ajkerrigan
Created January 19, 2020 19:15
Show Gist options
  • Select an option

  • Save ajkerrigan/7bd8f0c14543b7a78a68b71e95b8d5a1 to your computer and use it in GitHub Desktop.

Select an option

Save ajkerrigan/7bd8f0c14543b7a78a68b71e95b8d5a1 to your computer and use it in GitHub Desktop.
vdhash.py
#!/usr/bin/env python3
import hashlib
import sys
from pathlib import Path
if len(sys.argv) != 2:
print(f'Usage: {sys.argv[0]} <file>')
sys.exit(1)
try:
p = Path(sys.argv[1])
# Strip and hash, matching the behavior of VisiData's plugin checker:
# https://github.com/saulpw/visidata/blob/v2.-2.0/visidata/plugins.py#L46-L48
print(hashlib.sha256(p.read_bytes().strip()).hexdigest())
except FileNotFoundError as err:
print(f"Can't find file: {err.filename}")
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment