mirror of https://github.com/cheat/cheat.git
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
|
#!/usr/bin/env python
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import subprocess
|
||||||
|
|
||||||
DEFAULT_CHEAT_DIR = os.path.join(os.path.expanduser('~'), '.cheat')
|
DEFAULT_CHEAT_DIR = os.path.join(os.path.expanduser('~'), '.cheat')
|
||||||
USE_PYGMENTS = False
|
USE_PYGMENTS = False
|
||||||
|
@ -69,8 +70,28 @@ def main():
|
||||||
for key, value in cheatsheets.items()]))
|
for key, value in cheatsheets.items()]))
|
||||||
exit()
|
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
|
# print the cheatsheet if it exists
|
||||||
if keyphrase in cheatsheets:
|
if keyphrase in cheatsheets:
|
||||||
|
print ''.join('*' for x in range(80)) + "\n"
|
||||||
filename = os.path.join(cheatsheets[keyphrase], keyphrase)
|
filename = os.path.join(cheatsheets[keyphrase], keyphrase)
|
||||||
if USE_PYGMENTS:
|
if USE_PYGMENTS:
|
||||||
pretty_print(filename)
|
pretty_print(filename)
|
||||||
|
@ -78,6 +99,7 @@ def main():
|
||||||
with open(filename) as istream:
|
with open(filename) as istream:
|
||||||
for l in istream:
|
for l in istream:
|
||||||
sys.stdout.write(l)
|
sys.stdout.write(l)
|
||||||
|
print "\n" + ''.join('*' for x in range(80))
|
||||||
|
|
||||||
# if it does not, say so
|
# if it does not, say so
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue