mirror of
https://github.com/Erreur32/cheat.git
synced 2024-12-22 13:42:11 +01:00
fec0382892
python3 + add color + remove sheet
71 lines
1.7 KiB
Python
Executable file
71 lines
1.7 KiB
Python
Executable file
#!/usr/bin/python3
|
|
|
|
"""cheat
|
|
|
|
Create and view cheatsheets on the command line.
|
|
|
|
Usage:
|
|
\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>
|
|
|
|
Options:
|
|
-d --directories List directories on CHEATPATH
|
|
-e --edit Edit cheatsheet
|
|
-l --list List cheatsheets
|
|
-s --search Search cheatsheets for <keyword> and [<cheatsheet>] file
|
|
-v --version Print the version number
|
|
-r --remove Delete Cheatsheet
|
|
|
|
Examples:
|
|
|
|
To view the `tar` cheatsheet:
|
|
\033[1;31m cheat \033[0m tar
|
|
|
|
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
|
|
"""
|
|
|
|
# require the dependencies
|
|
from cheat import sheets, sheet
|
|
from cheat.utils import colorize
|
|
from docopt import docopt
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# parse the command-line options
|
|
options = docopt(__doc__, version='cheat 2.2.3')
|
|
|
|
# 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>'], options['<cheatsheet>'])))
|
|
|
|
# remove File in the cheatsheets
|
|
elif options['--remove']:
|
|
sheet.remove(options['<cheatsheet>'])
|
|
|
|
# print the cheatsheet
|
|
else:
|
|
print(colorize(sheet.read(options['<cheatsheet>'])))
|