diff --git a/README.md b/README.md index 535db84..2661220 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,15 @@ set an env variable for $EDITOR and/or $VISUAL in .bashrc export EDITOR=vi export VISUAL=geany + + ## Usage `skratch` creates a random file in .skratch and opens it in the EDITOR -`` opens or creates a file with a specific name in ~/.skratch +`-c` clears/deletes all files in .skratch -`-c` clears/deletes all files in ~/.skratch +`-l` lists files in .skratch -`-l` lists files in ~/.skratch +`-o ` opens (or creates) a file with a specific name -`-v` uses the VISUAL editor +`-v` opens the VISUAL editor diff --git a/skratch.py b/skratch.py index 9672b16..dde8a29 100755 --- a/skratch.py +++ b/skratch.py @@ -1,4 +1,5 @@ #!/usr/bin/python3 + import sys import os import argparse @@ -19,7 +20,7 @@ def delete_all(d): for file in files: f = os.path.join(d,file) os.remove(f) - print(f"Removing: {f}") + print(f"removing: {f}") print("Done") def list_all(d): @@ -61,16 +62,9 @@ def main(): parser = argparse.ArgumentParser( prog='skratch', - description='Creates a temp file and opens it in an editor') - + description='Creates a temp file and opens it in an editor', + epilog='Text at the bottom of help') group = parser.add_mutually_exclusive_group() - - group.add_argument( - "filename", - nargs="?", - help="open file in ~/.skratch", - default=None) - group.add_argument( "-c", help="delete all files", @@ -81,6 +75,12 @@ def main(): help="list files", action="store_true") + group.add_argument( + "-o", + metavar="", + help="open file", + action="store") + parser.add_argument( "-v", help="visual editor", @@ -88,9 +88,13 @@ def main(): args = parser.parse_args() + filename = "skratch-XXXXXX" + editor = get_editor(args.v) - if args.c: delete_all(sk_path) + if args.o: run(editor,sk_path,args.o) + elif args.c: delete_all(sk_path) elif args.l: list_all(sk_path) - else: run(editor,sk_path, args.filename) + else: run(editor,sk_path) main() +