├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── cheat-screenshot.png ├── cheat ├── __init__.py ├── cheat.py ├── cheat.py2 ├── printer.py └── utils.py ├── cheatsheets ├── bash.ini ├── docker.ini ├── emacs.ini ├── example.ini ├── firefox.ini ├── git.ini ├── i3.ini ├── markdown.ini ├── nc.ini ├── pdb.ini ├── systemd.ini ├── tmux-conf.ini ├── tmux.ini ├── vagrant.ini └── vim.ini ├── docs └── Printers.md ├── pylintrc └── tests ├── __init__.py ├── test_main.py ├── test_print.py ├── test_utils.py └── testsheets └── test.ini /.gitignore: -------------------------------------------------------------------------------- 1 | #Emacs 2 | 3 | \#* 4 | .\#* 5 | 6 | #Custom 7 | config/my-* 8 | 9 | #Python Defaults 10 | 11 | # Byte-compiled / optimized / DLL files 12 | __pycache__/ 13 | *.py[cod] 14 | *$py.class 15 | 16 | # C extensions 17 | *.so 18 | 19 | # Distribution / packaging 20 | .Python 21 | env/ 22 | build/ 23 | develop-eggs/ 24 | dist/ 25 | downloads/ 26 | eggs/ 27 | .eggs/ 28 | lib/ 29 | lib64/ 30 | parts/ 31 | sdist/ 32 | var/ 33 | *.egg-info/ 34 | .installed.cfg 35 | *.egg 36 | .venv/ 37 | 38 | # PyInstaller 39 | # Usually these files are written by a python script from a template 40 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 41 | *.manifest 42 | *.spec 43 | 44 | # Installer logs 45 | pip-log.txt 46 | pip-delete-this-directory.txt 47 | 48 | # Unit test / coverage reports 49 | htmlcov/ 50 | .tox/ 51 | .coverage 52 | .coverage.* 53 | .cache 54 | nosetests.xml 55 | coverage.xml 56 | *,cover 57 | .hypothesis/ 58 | 59 | # Translations 60 | *.mo 61 | *.pot 62 | 63 | # Django stuff: 64 | *.log 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | #Ipython Notebook 73 | .ipynb_checkpoints 74 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.5" 4 | - "3.6" 5 | - "3.7" 6 | install: 7 | - pip install coveralls 8 | - pip install coverage 9 | - pip install pylint==2.3.1 10 | script: 11 | - pylint cheat 12 | - python -m unittest discover 13 | - coverage run -m unittest discover 14 | - coverage report -m 15 | after_success: 16 | coveralls 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Markus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.com/martialblog/cheatsheet.svg?branch=master)](https://travis-ci.com/martialblog/cheatsheet) [![Coverage Status](https://coveralls.io/repos/github/martialblog/cheatsheet/badge.svg?branch=master)](https://coveralls.io/github/martialblog/cheatsheet?branch=master) 2 | 3 | # Commandline Cheatsheets 4 | 5 | Everybody likes cheatsheets. If you're like me and use lots of different tools but you can't remember all those cool shortcuts to impress your colleagues. 6 | 7 | Sure, there are lots of PDFs out there with everything you need. But are you really gonna have an PDF reader next to your terminal to look up shortcuts? Come on, who are we kidding? 8 | 9 | I'm trying to solve that problem by putting the cheatsheets where they belong. The terminal you're working in! 10 | 11 | - Cheatsheets directly in your terminal 12 | - Open-Format so you can customize/add/share 13 | - Grep-able! 14 | 15 | ## Requirements 16 | 17 | Nothing but good old Python (3.x), it's not rocketscience. 18 | 19 | I also provided a Python 2.x version. However, main branch is 3.x. 20 | 21 | ## Setup 22 | Clone this repository to ```~/cheat.d```. Like so: 23 | 24 | ```bash 25 | git clone https://github.com/martialblog/cheatsheet.git ~/.cheat.d 26 | ``` 27 | 28 | For usability you can set an alias: 29 | 30 | ```bash 31 | alias cheat="python3 ~/.cheat.d/cheat/cheat.py" 32 | ``` 33 | 34 | For Python 2: 35 | 36 | ```bash 37 | alias cheat="python2 ~/.cheat.d/cheat/cheat.py2" 38 | ``` 39 | 40 | And away we go! 41 | 42 | ```bash 43 | user@computer$ cheat git 44 | ``` 45 | 46 | ![Cheat Screenshot](cheat-screenshot.png?raw=true "Cheat Screenshot") 47 | 48 | To list all available cheatsheets: 49 | 50 | ```bash 51 | user@computer$ cheat --list 52 | ``` 53 | 54 | ### Custom cheatsheets 55 | 56 | You can add custom cheatsheet that will be "gitgnored" by using the prexif **my-** 57 | 58 | # Contributing 59 | 60 | Every Pull Request is welcome, either to extend features or to add new cheatsheets. 61 | 62 | ## Unittest 63 | 64 | To run the Unittests simply run the Python Unittest Module within the repository: 65 | 66 | ```bash 67 | python3 -m unittest -v 68 | ``` 69 | -------------------------------------------------------------------------------- /cheat-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martialblog/cheatsheet/f80745f60383b9ca492b88fc3c162ff52192dce9/cheat-screenshot.png -------------------------------------------------------------------------------- /cheat/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martialblog/cheatsheet/f80745f60383b9ca492b88fc3c162ff52192dce9/cheat/__init__.py -------------------------------------------------------------------------------- /cheat/cheat.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | """ 5 | Main script, where all parts come together. 6 | containers Argument Parser for commandline arguments and main function. 7 | """ 8 | 9 | 10 | from argparse import ArgumentParser 11 | from configparser import ConfigParser 12 | from configparser import Error as ConfigParserError 13 | from os import path 14 | from printer import PrinterFactory 15 | from utils import print_available_sheets, Colors 16 | 17 | 18 | def commandline(): 19 | """ 20 | Configures the Argument Parser and returns the parsed commandline args. 21 | """ 22 | 23 | description = 'Cool Command-line Cheatsheets' 24 | help_general = 'The cheatsheet you want to see' 25 | help_list = 'List all available cheatsheets' 26 | help_colors = 'Print output without colors' 27 | help_inline = 'One cheat per line, this is the default' 28 | help_breakline = 'Break lines' 29 | 30 | argumentparser = ArgumentParser(description=description) 31 | printertype = argumentparser.add_mutually_exclusive_group() 32 | 33 | argumentparser.add_argument('--list', dest='listcheats', action="store_true", required=False, help=help_list) 34 | argumentparser.add_argument('--nc', dest='nocolor', action="store_false", required=False, help=help_colors) 35 | argumentparser.add_argument('cheatsheet', nargs='?', help=help_general) 36 | 37 | printertype.set_defaults(printer='InlinePrinter') 38 | printertype.add_argument('-l', help=help_inline, action='store_const', dest='printer', const='InlinePrinter') 39 | printertype.add_argument('-b', help=help_breakline, action='store_const', dest='printer', const='BreaklinePrinter') 40 | 41 | return argumentparser 42 | 43 | 44 | def main(argparser): 45 | """ 46 | Where the magic happens. 47 | 48 | :param argparser: Configures Argument Parser 49 | """ 50 | 51 | cmdargs = argparser.parse_args() 52 | filedir = path.dirname(path.abspath(__file__ + '../../')) 53 | cheatsheetdir = path.join(filedir, 'cheatsheets/') 54 | extension = '.ini' 55 | filename = cheatsheetdir + str(cmdargs.cheatsheet) + extension 56 | 57 | # Lists the Cheatsheats 58 | if cmdargs.listcheats: 59 | print_available_sheets(cheatsheetdir) 60 | exit(0) 61 | 62 | # Print help if nothing is provided 63 | if cmdargs.cheatsheet is None: 64 | argparser.print_help() 65 | exit(2) 66 | 67 | # Check if file is available 68 | if not path.isfile(filename): 69 | print(filename + ' is not available.') 70 | exit(2) 71 | 72 | # Build the Printer 73 | configparser = ConfigParser() 74 | printer_constructor = PrinterFactory.create_printer(cmdargs.printer) 75 | printcolored = cmdargs.nocolor 76 | cheatprinter = printer_constructor(configparser, Colors, printcolored) 77 | 78 | # Read the file and exit script 79 | try: 80 | configparser.read(filename) 81 | cheatprinter.printsheet() 82 | exitcode = 0 83 | except ConfigParserError as exception: 84 | print(filename + ' contains error.\n') 85 | print(exception) 86 | exitcode = 1 87 | finally: 88 | exit(exitcode) 89 | 90 | if __name__ == '__main__': 91 | 92 | ARGPARSER = commandline() 93 | main(ARGPARSER) 94 | -------------------------------------------------------------------------------- /cheat/cheat.py2: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python2 2 | # pylint: skip-file 3 | 4 | 5 | """ 6 | Notice: This is the Python 2 codebase, which I don't really work on much. 7 | """ 8 | 9 | 10 | from ConfigParser import ConfigParser 11 | from argparse import ArgumentParser 12 | from sys import path 13 | from sys import exit 14 | 15 | 16 | class Printer(object): 17 | 18 | def __init__(self, configparser): 19 | self.configparser = configparser 20 | 21 | def printsheet(self, template): 22 | for desc, value in self.configparser.items('cheats'): 23 | output = template.format(desc, value) 24 | print(output) 25 | 26 | 27 | class InlinePrinter(Printer): 28 | """ 29 | Prints the cheatssheet inline, so that it's grep-able. 30 | """ 31 | 32 | @property 33 | def width(self): 34 | width = 0 35 | 36 | for desc, value in self.configparser.items('cheats'): 37 | if len(desc) > width: 38 | width = len(desc) 39 | 40 | return str(width) 41 | 42 | def printsheet(self): 43 | print_format = "{0:" + self.width + "} {1}" 44 | super(InlinePrinter, self).printsheet(print_format) 45 | 46 | 47 | class BreaklinePrinter(Printer): 48 | """ 49 | Prints the cheatsheet with newlines 50 | """ 51 | 52 | def printsheet(self): 53 | print_format = "{0} \n {1}" 54 | super(BreaklinePrinter, self).printsheet(print_format) 55 | 56 | 57 | def main(): 58 | # GENERAL SETTINGS! 59 | directory = path[0] + "/../cheatsheets/" 60 | extention = ".ini" 61 | description = "Cool Command-line Cheatsheets" 62 | help_general = "The cheatsheet you want to see" 63 | help_inline = "One cheat per line, this is default" 64 | help_breakline = "Break lines" 65 | 66 | # COMMAND-LINE ARGUMENTS! 67 | argumentparser = ArgumentParser(description=description) 68 | printertype = argumentparser.add_mutually_exclusive_group() 69 | 70 | argumentparser.add_argument('cheatsheet', help=help_general) 71 | printertype.set_defaults(printer='InlinePrinter') 72 | printertype.add_argument('-l', help=help_inline, action='store_const', dest='printer', const='InlinePrinter') 73 | printertype.add_argument('-b', help=help_breakline, action='store_const', dest='printer', const='BreaklinePrinter') 74 | 75 | # WHERE THE RUBBER MEETS THE ROAD! 76 | cmd_arguments = argumentparser.parse_args() 77 | filename = directory + cmd_arguments.cheatsheet + extention 78 | CheatPrinterConstructor = globals()[cmd_arguments.printer] 79 | configparser = ConfigParser() 80 | cheatprinter = CheatPrinterConstructor(configparser) 81 | 82 | try: 83 | configparser.read(filename) 84 | cheatprinter.printsheet() 85 | exitcode = 0 86 | except Exception as e: 87 | # I know lazy handling, but it works perfect... Sorry. 88 | print(filename + " not available or contains errors.") 89 | print(e) 90 | exitcode = 1 91 | finally: 92 | exit(exitcode) 93 | 94 | if __name__ == "__main__": 95 | main() 96 | -------------------------------------------------------------------------------- /cheat/printer.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env/python3 2 | 3 | 4 | """ 5 | Printer Classes. 6 | Handle the printing of the cheatsheet files. 7 | 8 | The factory pattern creates a Printer Object from the commandline arguments. 9 | Meaning that there's no need for an elaborate if-else condition. 10 | """ 11 | 12 | 13 | class Printer: 14 | """ 15 | Base class for the cheatsheet printers. Takes care of the actuall printing. 16 | """ 17 | 18 | def __init__(self, configparser, colors, print_colored=True): 19 | """ 20 | BaseClass constucter. 21 | 22 | :param configparser: ConfigParser object with the cheatsheets. 23 | :param print_colored: Print console output with color or not. 24 | """ 25 | 26 | self.configparser = configparser 27 | self.colors = colors 28 | self.print_colored = print_colored 29 | 30 | def add_color(self, string): 31 | """ 32 | Adds color to the console output. 33 | 34 | :param string: The string to add color to. 35 | """ 36 | 37 | default_color = self.colors.DEFAULT 38 | param_color = self.colors.PARAM 39 | reset_color = self.colors.RESET 40 | 41 | string = string.replace('<', param_color + '<') 42 | string = string.replace('>', '>' + reset_color) 43 | 44 | colored = default_color + string + reset_color 45 | 46 | return colored 47 | 48 | def printcheats(self, template): 49 | """ 50 | Loops over the entries in the ConfigParser and prints them with a specific template. 51 | 52 | :param template: Template to use with the format() function. 53 | """ 54 | 55 | sections = self.configparser.sections() 56 | sections.remove('main') 57 | 58 | for section in sections: 59 | print(section.upper()) 60 | for description in self.configparser[section]: 61 | value = self.configparser[section][description] 62 | value = self.add_color(value) if self.print_colored else value 63 | output = template.format(description.capitalize(), value) 64 | print(output) 65 | 66 | 67 | class InlinePrinter(Printer): 68 | """ 69 | Prints the cheatssheet line-by-line, so that it's grep-able. 70 | """ 71 | 72 | @property 73 | def width(self): 74 | """ 75 | Width of the longest ConfigParser entry. 76 | """ 77 | 78 | width = 1 79 | 80 | # Calculate new width 81 | for section in self.configparser.sections(): 82 | longest_width = len(max(self.configparser[section], key=len)) 83 | if longest_width > width: 84 | width = longest_width 85 | 86 | return str(width) 87 | 88 | def printsheet(self): 89 | """ 90 | Sets the printer template to print inline and calls the Printer.printsheet(). 91 | """ 92 | 93 | print_format = "{0:<" + self.width + "} {1}" 94 | super().printcheats(print_format) 95 | 96 | 97 | class BreaklinePrinter(Printer): 98 | """ 99 | Prints the cheatsheet and breaks the line after the description. 100 | """ 101 | 102 | def printsheet(self): 103 | """ 104 | Sets the printer template to print with newlines and calls the Printer.printsheet(). 105 | """ 106 | 107 | print_format = "{0} \n {1}" 108 | super().printcheats(print_format) 109 | 110 | 111 | class PrinterFactory: 112 | """ 113 | Creates a Printer object from the String given by the argparse option. 114 | """ 115 | 116 | printer_classes = { 117 | 'InlinePrinter': InlinePrinter, 118 | 'BreaklinePrinter': BreaklinePrinter 119 | } 120 | 121 | @staticmethod 122 | def create_printer(name): 123 | """ 124 | Returns a specific Printer Object. 125 | 126 | :param name: Printer Object to return. 127 | """ 128 | 129 | return PrinterFactory.printer_classes[name] 130 | -------------------------------------------------------------------------------- /cheat/utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | 4 | """ 5 | Utility functions and classes for common tasks. 6 | """ 7 | 8 | 9 | from configparser import ConfigParser 10 | from configparser import Error as ConfigParserError 11 | from os import listdir, path 12 | 13 | 14 | def print_available_sheets(directory): 15 | """ 16 | Prints all available cheatsheets in the sheet folder to the stdout. 17 | 18 | :param directory: The directory where the cheatsheets are located. 19 | """ 20 | 21 | parser = ConfigParser() 22 | files = listdir(directory) 23 | 24 | for name in sorted(files): 25 | try: 26 | parser.read(path.join(directory, name)) 27 | print('{0}'.format(parser['main']['name'])) 28 | except ConfigParserError: 29 | # TOOD: What to do here? 30 | pass 31 | 32 | 33 | class Colors: 34 | """ 35 | Wrapper class for colored output 36 | """ 37 | 38 | DEFAULT = '\033[94m' 39 | PARAM = '\033[93m' 40 | RESET = '\033[1;m' 41 | -------------------------------------------------------------------------------- /cheatsheets/bash.ini: -------------------------------------------------------------------------------- 1 | [main] 2 | name=bash 3 | desc=Those cool bash shortcuts 4 | [cheats] 5 | Cursor to the start = Ctrl + A 6 | Cursor to the end = Ctrl + E 7 | Cut word on the left = Ctrl + W 8 | Cut everything before the cursor = Ctrl + U 9 | Cut everything after the cursor = Ctrl + K 10 | Paste the last thing to be cut = Ctrl + Y 11 | Last exit status = $? 12 | Reverse search history = Ctrl + R 13 | Repeat last command = !! 14 | -------------------------------------------------------------------------------- /cheatsheets/docker.ini: -------------------------------------------------------------------------------- 1 | [main] 2 | name= docker 3 | desc= Some Docker cheats 4 | [cheats] 5 | creates a container but does not start it. = docker create 6 | allows the container to be renamed. = docker rename 7 | creates and starts a container in one operation. = docker run 8 | deletes a container. = docker rm 9 | updates a container's resource limits. = docker update 10 | starts a container so it is running. = docker start 11 | stops a running container. = docker stop 12 | stops and starts a container. = docker restart 13 | pauses a running container, "freezing" it in place. = docker pause 14 | will unpause a running container. = docker unpause 15 | blocks until running container stops. = docker wait 16 | sends a SIGKILL to a running container. = docker kill 17 | will connect to a running container. = docker attach 18 | shows running containers. = docker ps 19 | gets logs from container. = docker logs 20 | looks at all the info on a container (including IP address). = docker inspect 21 | gets events from container. = docker events 22 | shows public facing port of container. = docker port 23 | shows running processes in container. = docker top 24 | shows containers' resource usage statistics. = docker stats 25 | shows changed files in the container's FS. = docker diff 26 | shows running and stopped containers. = docker ps -a 27 | shows a running list of containers. = docker stats --all 28 | to execute a command in container. = docker exec 29 | shows all images. = docker images 30 | creates an image from a tarball. = docker import 31 | creates image from Dockerfile. = docker build 32 | creates image from a container, pausing it temporarily if it is running. = docker commit 33 | removes an image. = docker rmi 34 | loads an image from a tar archive as STDIN, including images and tags (as of 0.7). = docker load 35 | saves an image to a tar archive stream to STDOUT with all parent layers, tags & versions (as of 0.7). = docker save 36 | shows history of image. = docker history 37 | tags an image to a name (local or registry). = docker tag 38 | to login to a registry. = docker login 39 | to logout from a registry. = docker logout 40 | searches registry for image. = docker search 41 | pulls an image from registry to local machine. = docker pull 42 | pushes an image to the registry from local machine. = docker push 43 | 44 | -------------------------------------------------------------------------------- /cheatsheets/emacs.ini: -------------------------------------------------------------------------------- 1 | [main] 2 | name=emacs 3 | desc=Escape Meta Alt Control Shift 4 | [cheats] 5 | Open a file = C-x C-f 6 | Write buffer = C-x C-w 7 | Toogle read-only mode = C-x C-q 8 | Regular expression search = C-M-s 9 | Move to next S-Expression = C-M-f 10 | Move to next function = C-M-e 11 | Delete this window = C-x 0 12 | Delete all other windows = C-x 1 13 | Split window horizontally = C-x 2 14 | Split window vertically = C-x 3 15 | Intent current line = TAB 16 | Intent region = C-M-\ 17 | Intent S-Expression = C-M-q 18 | Transpose lines = C-x C-t 19 | Kill region = C-w 20 | Yank back last kill = C-y 21 | Mark buffer = C-x h 22 | Mark S-Expression = C-M-@ 23 | Mark function = C-M-h 24 | Switch buffer = C-x b 25 | kill buffer = C-x k 26 | -------------------------------------------------------------------------------- /cheatsheets/example.ini: -------------------------------------------------------------------------------- 1 | [main] 2 | name=example 3 | desc=An example for start your own 4 | [common] 5 | Simple Example = example foobar 6 | Example with Parameter = example foo 7 | [workflow] 8 | Example in another section = example barfoo 9 | -------------------------------------------------------------------------------- /cheatsheets/firefox.ini: -------------------------------------------------------------------------------- 1 | [main] 2 | name=firefox 3 | desc=Browse like a pro. A Prowser... 4 | [cheats] 5 | Back=Alt + Left 6 | Forward=Alt + Right 7 | Home=Alt + Home 8 | Reload=Ctrl + R 9 | Reload override cache=Ctrl Shift + R 10 | Stop=Esc 11 | Focus Search Bar=Ctrl + K 12 | Switch Search Engines=Ctrl + 13 | Toggle Audio=Ctrl + M 14 | Undo Close Tab=Ctrl + Shift + T 15 | Select Tab=Alt + <[1-8]> 16 | Bookmark this Page=Ctrl + D 17 | Bookmark Sidebar=Ctrl + B 18 | Page Source=Ctrl + U 19 | Page Info=Ctrl + I 20 | -------------------------------------------------------------------------------- /cheatsheets/git.ini: -------------------------------------------------------------------------------- 1 | [main] 2 | name=git 3 | desc=My awesome git cheatsheet 4 | [cheats] 5 | Add file to staging area = git add 6 | Change remote URL = git remote set-url origin 7 | Create remote branch = git push -u origin 8 | Clone a remote git repository = git clone 9 | Delete a merged branch = git branch -d 10 | Differences in two branches = git diff 11 | Fetch and Rebase = git pull --rebase 12 | List changes since two weeks = git whatchanged --since=