mirror of
https://github.com/Erreur32/cheat.git
synced 2024-10-31 21:11:07 +01:00
Added in an edit option that allows a user to edit the cheatsheet from their default editor. Also made some visual changes to the output of the cheatsheet.
This commit is contained in:
parent
7cfaddf935
commit
dcf8e758a8
22
cheat
22
cheat
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
|
||||
DEFAULT_CHEAT_DIR = os.path.join(os.path.expanduser('~'), '.cheat')
|
||||
USE_PYGMENTS = False
|
||||
@ -69,8 +70,28 @@ def main():
|
||||
for key, value in cheatsheets.items()]))
|
||||
exit()
|
||||
|
||||
# if the user wants to edit a cheatsheet
|
||||
if sys.argv[1].lower() in ['-e', '--edit']:
|
||||
if len(sys.argv) < 2:
|
||||
print 'Must provide a cheatsheet to edit'
|
||||
exit()
|
||||
|
||||
cheatsheet = ' '.join(sys.argv[2:])
|
||||
|
||||
if cheatsheet not in cheatsheets:
|
||||
print 'No cheatsheet found for %s.' % cheatsheet
|
||||
exit()
|
||||
|
||||
if 'EDITOR' not in os.environ:
|
||||
print 'Must set your EDITOR environment variable to default editor path'
|
||||
exit()
|
||||
|
||||
subprocess.call([os.environ['EDITOR'],
|
||||
os.path.join(cheatsheets[cheatsheet], cheatsheet)])
|
||||
|
||||
# print the cheatsheet if it exists
|
||||
if keyphrase in cheatsheets:
|
||||
print ''.join('*' for x in range(80)) + "\n"
|
||||
filename = os.path.join(cheatsheets[keyphrase], keyphrase)
|
||||
if USE_PYGMENTS:
|
||||
pretty_print(filename)
|
||||
@ -78,6 +99,7 @@ def main():
|
||||
with open(filename) as istream:
|
||||
for l in istream:
|
||||
sys.stdout.write(l)
|
||||
print "\n" + ''.join('*' for x in range(80))
|
||||
|
||||
# if it does not, say so
|
||||
else:
|
||||
|
Loading…
Reference in New Issue
Block a user