Craig Oates
4 years ago
4 changed files with 119 additions and 66 deletions
@ -1,25 +0,0 @@ |
|||||||
# Cheatsheet |
|
||||||
|
|
||||||
Here is a collection of shortcuts you are trying to learn. |
|
||||||
|
|
||||||
## Emacs |
|
||||||
|
|
||||||
- `**ctrl-c e**`: Does something fancy. |
|
||||||
- **m-x c e l p**: Exports .org file to .pdf. |
|
||||||
|
|
||||||
## Custom Global Shortcuts |
|
||||||
|
|
||||||
`num-4`: Opens Emacs at tasks.org. |
|
||||||
|
|
||||||
`num-5`: Pushes published files to abbether. |
|
||||||
|
|
||||||
`num-6`: Opens this cheatsheet. |
|
||||||
|
|
||||||
## Block code |
|
||||||
|
|
||||||
```python |
|
||||||
from rich.console import Console |
|
||||||
|
|
||||||
console = Console() |
|
||||||
``` |
|
||||||
|
|
@ -1,41 +0,0 @@ |
|||||||
import argparse |
|
||||||
from rich.console import Console |
|
||||||
from rich.markdown import Markdown |
|
||||||
from rich.table import Column, Table |
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments(): |
|
||||||
parser = argparse.ArgumentParser( |
|
||||||
"Displays a nicely formatted cheatsheet of") |
|
||||||
parser.add_argument("-a", "--append", |
|
||||||
help="Append a shortcut to your collection using Markdown.") |
|
||||||
args = parser.parse_args() |
|
||||||
return args |
|
||||||
|
|
||||||
|
|
||||||
def display_file(): |
|
||||||
with open("cheatsheet.md") as cheats: |
|
||||||
markdown = Markdown(cheats.read()) |
|
||||||
console = Console() |
|
||||||
console.print(markdown) |
|
||||||
|
|
||||||
|
|
||||||
def append_to_file(data): |
|
||||||
# This is not implemented. |
|
||||||
x = 0 |
|
||||||
|
|
||||||
|
|
||||||
def main(): |
|
||||||
args = parse_arguments() |
|
||||||
a = args.append |
|
||||||
# print(args) |
|
||||||
if a is None: |
|
||||||
display_file() |
|
||||||
else: |
|
||||||
print("Appending to file...") |
|
||||||
append_to_file(args.append) |
|
||||||
x = 4 |
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__": |
|
||||||
main() |
|
@ -0,0 +1,9 @@ |
|||||||
|
altgraph==0.17 |
||||||
|
colorama==0.4.3 |
||||||
|
commonmark==0.9.1 |
||||||
|
pkg-resources==0.0.0 |
||||||
|
pprintpp==0.4.0 |
||||||
|
Pygments==2.6.1 |
||||||
|
PyInstaller==3.6 |
||||||
|
rich==1.0.0 |
||||||
|
typing-extensions==3.7.4.2 |
@ -0,0 +1,110 @@ |
|||||||
|
#!/usr/bin/python3 |
||||||
|
|
||||||
|
from sys import stdin |
||||||
|
import argparse |
||||||
|
import logging |
||||||
|
from pathlib import Path |
||||||
|
from rich import print |
||||||
|
from rich.console import Console |
||||||
|
from rich.markdown import Markdown |
||||||
|
from rich.logging import RichHandler |
||||||
|
from rich.traceback import install |
||||||
|
|
||||||
|
# Global Variables (Making things easy for myself) |
||||||
|
# ==================================================================== |
||||||
|
logging.basicConfig(level="NOTSET", format="%(message)s", |
||||||
|
datefmt="[%X] ", handlers=[RichHandler()]) |
||||||
|
log = logging.getLogger("rich") |
||||||
|
# install() |
||||||
|
console = Console() |
||||||
|
data_location = Path.joinpath(Path.home(), "shortcut-learner.md") |
||||||
|
|
||||||
|
# ==================================================================== |
||||||
|
|
||||||
|
|
||||||
|
def parse_arguments(): |
||||||
|
parser = argparse.ArgumentParser( |
||||||
|
"Displays a nicely formatted cheatsheet in the console.") |
||||||
|
parser.add_argument("-a", "--append", |
||||||
|
help="Append a shortcut to your collection using Markdown.") |
||||||
|
parser.add_argument("-d", "--delete", action="store_true", |
||||||
|
help="Deletes file storing your shortcuts list.") |
||||||
|
args = parser.parse_args() |
||||||
|
return args |
||||||
|
|
||||||
|
|
||||||
|
def create_new_file(): |
||||||
|
print("Create new file [b](Y/n)[/b]? ", end="") |
||||||
|
create = stdin.readline(1).strip() |
||||||
|
if create == "y" or not create: |
||||||
|
log.info(f"Creating new data file at: {data_location}") |
||||||
|
try: |
||||||
|
with open(f"{data_location}", "w+") as new_file: |
||||||
|
new_file.write("# Shortcuts \n\n") |
||||||
|
new_file.write( |
||||||
|
"The shortcuts I intend to learn are as follows:\n\n") |
||||||
|
except IOError: |
||||||
|
log.critical("Data file could not be created.") |
||||||
|
console.print_exception() |
||||||
|
except Exception as e: |
||||||
|
log.critical("Unrecoverable system error.") |
||||||
|
console.print_exception() |
||||||
|
elif create == "n": |
||||||
|
log.info("No data file created. Exiting program.") |
||||||
|
else: |
||||||
|
log.error("Invalid argument. Please enter 'y' or 'n'. Exiting program.") |
||||||
|
|
||||||
|
|
||||||
|
def load_file(): |
||||||
|
try: |
||||||
|
with open(data_location) as data_file: |
||||||
|
markdown = Markdown(data_file.read()) |
||||||
|
console.print(markdown) |
||||||
|
except IOError: |
||||||
|
log.warning("Data file cannot be found.") |
||||||
|
create_new_file() |
||||||
|
except Exception as e: |
||||||
|
log.critical("Unrecoverable system error.") |
||||||
|
console.print_exception() |
||||||
|
|
||||||
|
|
||||||
|
def append_to_file(data): |
||||||
|
log.info(f"\"{data}\" added to file.") |
||||||
|
log.info("Opening data file...") |
||||||
|
try: |
||||||
|
with open(data_location, "a") as data_file: |
||||||
|
data_file.write(f"{data}\n\n") |
||||||
|
except IOError: |
||||||
|
log.warning("Data file cannot be found.") |
||||||
|
create_new_file() |
||||||
|
except Exception as e: |
||||||
|
log.critical("Unrecoverable system error.") |
||||||
|
console.print_exception() |
||||||
|
|
||||||
|
|
||||||
|
def delete_file(): |
||||||
|
try: |
||||||
|
log.warning(f"Deleting file {data_location}...") |
||||||
|
Path.unlink(data_location) |
||||||
|
log.info("File deleted.") |
||||||
|
except IOError: |
||||||
|
log.info("No file was found. Nothing deleted.") |
||||||
|
except Exception as e: |
||||||
|
log.critical("Unrecoverable system error.") |
||||||
|
console.print_exception() |
||||||
|
|
||||||
|
|
||||||
|
def main(): |
||||||
|
args = parse_arguments() |
||||||
|
if args.delete is False: |
||||||
|
if args.append is None: |
||||||
|
load_file() |
||||||
|
else: |
||||||
|
append_to_file(args.append) |
||||||
|
load_file() |
||||||
|
else: |
||||||
|
delete_file() |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
main() |
Loading…
Reference in new issue