mirror of
https://github.com/Erreur32/cheat.git
synced 2024-12-22 21:52:12 +01:00
When creating a new cheatsheet using the -c option, the program now
first attempts to write to the ~/.cheat directory, or alternatively create it if it does not already exist. Failing that, it attempts to write to the python package directory.
This commit is contained in:
parent
3399b8905d
commit
63c391f67a
1 changed files with 13 additions and 2 deletions
11
cheat
11
cheat
|
@ -67,8 +67,19 @@ def create_cheatsheet(cheat, cheatsheets):
|
|||
exit()
|
||||
|
||||
import cheatsheets as cs
|
||||
|
||||
# Attempt to write the new cheatsheet to the user's ~/.cheat dir if it
|
||||
# exists. If it does not exist, attempt to create it.
|
||||
if os.access(DEFAULT_CHEAT_DIR, os.W_OK) or os.makedirs(DEFAULT_CHEAT_DIR):
|
||||
subprocess.call([os.environ['EDITOR'],
|
||||
os.path.join(DEFAULT_CHEAT_DIR, cheat)])
|
||||
|
||||
# If the directory cannot be created, write to the python package
|
||||
# directory, though that will likely require the use of sudo
|
||||
else:
|
||||
subprocess.call([os.environ['EDITOR'],
|
||||
os.path.join(cs.cheat_dir, cheat)])
|
||||
|
||||
exit()
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Reference in a new issue