2014-04-27 05:31:13 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""cheat
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
cheat <cheatsheet>
|
|
|
|
cheat -e <cheatsheet>
|
|
|
|
cheat -s <keyword>
|
|
|
|
cheat -l
|
|
|
|
cheat -d
|
|
|
|
cheat -v
|
|
|
|
|
|
|
|
cheat allows you to create and view interactive cheatsheets on the
|
|
|
|
command-line. It was designed to help remind *nix system
|
|
|
|
administrators of options for commands that they use frequently,
|
|
|
|
but not frequently enough to remember.
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
To look up 'tar':
|
|
|
|
cheat tar
|
|
|
|
|
|
|
|
To create or edit the cheatsheet for 'foo':
|
|
|
|
cheat -e foo
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-d --directories List directories on CHEATPATH
|
|
|
|
-e --edit Edit cheatsheet
|
|
|
|
-l --list List cheatsheets
|
|
|
|
-s --search Search cheatsheets for <keyword>
|
|
|
|
-v --version Print the version number
|
|
|
|
"""
|
|
|
|
|
|
|
|
# require the dependencies
|
2016-07-19 13:37:18 +02:00
|
|
|
from cheat import sheets, sheet
|
|
|
|
from cheat.utils import colorize
|
2014-04-27 05:31:13 +02:00
|
|
|
from docopt import docopt
|
|
|
|
|
|
|
|
|
2015-10-16 00:56:34 +02:00
|
|
|
if __name__ == '__main__':
|
2014-04-27 05:31:13 +02:00
|
|
|
# parse the command-line options
|
2016-11-27 17:10:05 +01:00
|
|
|
options = docopt(__doc__, version='cheat 2.1.27')
|
2014-04-27 05:31:13 +02:00
|
|
|
|
|
|
|
# list directories
|
|
|
|
if options['--directories']:
|
|
|
|
print("\n".join(sheets.paths()))
|
|
|
|
|
|
|
|
# list cheatsheets
|
|
|
|
elif options['--list']:
|
|
|
|
print(sheets.list())
|
|
|
|
|
|
|
|
# create/edit cheatsheet
|
|
|
|
elif options['--edit']:
|
|
|
|
sheet.create_or_edit(options['<cheatsheet>'])
|
|
|
|
|
|
|
|
# search among the cheatsheets
|
|
|
|
elif options['--search']:
|
|
|
|
print(colorize(sheets.search(options['<keyword>'])))
|
|
|
|
|
|
|
|
# print the cheatsheet
|
|
|
|
else:
|
|
|
|
print(colorize(sheet.read(options['<cheatsheet>'])))
|