2018-02-24 17:42:32 +01:00
|
|
|
#!/usr/bin/python3
|
2014-04-27 05:31:13 +02:00
|
|
|
|
|
|
|
"""cheat
|
|
|
|
|
2017-02-28 05:09:51 +01:00
|
|
|
Create and view cheatsheets on the command line.
|
|
|
|
|
2014-04-27 05:31:13 +02:00
|
|
|
Usage:
|
2018-02-24 17:42:32 +01:00
|
|
|
\033[1;32mcheat\033[0m <cheatsheet>
|
|
|
|
\033[1;32mcheat\033[0m -e <cheatsheet>
|
|
|
|
\033[1;32mcheat\033[0m -s <keyword> [<cheatsheet>]
|
|
|
|
\033[1;32mcheat\033[0m -l
|
|
|
|
\033[1;32mcheat\033[0m -d
|
|
|
|
\033[1;32mcheat\033[0m -v
|
|
|
|
\033[1;32mcheat\033[0m -r <cheatsheet>
|
2014-04-27 05:31:13 +02:00
|
|
|
|
|
|
|
Options:
|
|
|
|
-d --directories List directories on CHEATPATH
|
|
|
|
-e --edit Edit cheatsheet
|
|
|
|
-l --list List cheatsheets
|
2018-02-24 17:42:32 +01:00
|
|
|
-s --search Search cheatsheets for <keyword> and [<cheatsheet>] file
|
2014-04-27 05:31:13 +02:00
|
|
|
-v --version Print the version number
|
2018-02-24 17:42:32 +01:00
|
|
|
-r --remove Delete Cheatsheet
|
2017-02-28 05:09:51 +01:00
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
To view the `tar` cheatsheet:
|
2018-02-24 17:42:32 +01:00
|
|
|
\033[1;31m cheat \033[0m tar
|
2017-02-28 05:09:51 +01:00
|
|
|
|
|
|
|
To edit (or create) the `foo` cheatsheet:
|
|
|
|
cheat -e foo
|
|
|
|
|
|
|
|
To list all available cheatsheets:
|
|
|
|
cheat -l
|
|
|
|
|
|
|
|
To search for "ssh" among all cheatsheets:
|
|
|
|
cheat -s ssh
|
2014-04-27 05:31:13 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
# 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
|
2017-12-19 18:42:07 +01:00
|
|
|
options = docopt(__doc__, version='cheat 2.2.3')
|
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']:
|
2018-02-24 17:42:32 +01:00
|
|
|
print(colorize(sheets.search(options['<keyword>'], options['<cheatsheet>'])))
|
|
|
|
|
|
|
|
# remove File in the cheatsheets
|
|
|
|
elif options['--remove']:
|
|
|
|
sheet.remove(options['<cheatsheet>'])
|
2014-04-27 05:31:13 +02:00
|
|
|
|
|
|
|
# print the cheatsheet
|
|
|
|
else:
|
|
|
|
print(colorize(sheet.read(options['<cheatsheet>'])))
|