Skip to content

Instantly share code, notes, and snippets.

@ezr
Created December 3, 2021 03:56
Show Gist options
  • Save ezr/c44123295d0a5b04fd8294b013daa487 to your computer and use it in GitHub Desktop.
Save ezr/c44123295d0a5b04fd8294b013daa487 to your computer and use it in GitHub Desktop.
Print out a cheat sheet, falls back to tldr pages
#!/usr/bin/env python3
# depends on:
# https://github.com/sharkdp/bat
# https://github.com/tldr-pages/tldr
from glob import glob
from os import listdir, environ
import subprocess
from sys import argv
if len(argv) == 1:
print(f" usage: {argv[0]} <term>")
exit(1)
try:
DIR = environ["CHEATDIR"]
except KeyError:
print("[!] error: make sure to export CHEATDIR environment variable")
d = dict()
for item in listdir(DIR):
d[item.split(".")[0]] = item
try:
target = "%s/%s" % (DIR, d[argv[1]])
subprocess.run(["bat", "-p", target])
except KeyError:
subprocess.run(["tldr", argv[1]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment