Compare commits

...

2 commits

Author SHA1 Message Date
d49ba30b35 added -s documentation 2026-03-05 14:55:59 -08:00
cd8184dc7c added -s file suffix 2026-03-05 14:55:45 -08:00
2 changed files with 12 additions and 4 deletions

View file

@ -15,7 +15,8 @@ set an env variable for $EDITOR and/or $VISUAL in .bashrc
export EDITOR=vi export EDITOR=vi
export VISUAL=geany export VISUAL=geany
## Usage ## Usage:
`skratch` creates a random file in .skratch and opens it in the EDITOR `skratch` creates a random file in .skratch and opens it in the EDITOR
`<filename>` opens or creates a file with a specific name in ~/.skratch `<filename>` opens or creates a file with a specific name in ~/.skratch
@ -24,4 +25,6 @@ set an env variable for $EDITOR and/or $VISUAL in .bashrc
`-l` lists files in ~/.skratch `-l` lists files in ~/.skratch
`-s` adds a suffix to the file
`-v` uses the VISUAL editor `-v` uses the VISUAL editor

View file

@ -39,11 +39,11 @@ def get_editor(use_v):
return v return v
return e return e
def run(editor, sk_path, filename=None): def run(editor, sk_path, filename=None, f_suffix=""):
if not filename: if not filename:
t = time.localtime() t = time.localtime()
filename = f"skratch-{t.tm_year}-{t.tm_mon}-{t.tm_mday}-" filename = f"skratch-{t.tm_year}-{t.tm_mon}-{t.tm_mday}-"
fd, fp = tempfile.mkstemp(prefix=filename, dir=sk_path) fd, fp = tempfile.mkstemp(prefix=filename, dir=sk_path, suffix=f_suffix)
os.close(fd) os.close(fd)
else: else:
fp = os.path.join(sk_path, filename) fp = os.path.join(sk_path, filename)
@ -77,6 +77,11 @@ def main():
help="list files", help="list files",
action="store_true") action="store_true")
group.add_argument(
"-s",
help="add suffix",
action="store")
parser.add_argument( parser.add_argument(
"-v", "-v",
help="visual editor", help="visual editor",
@ -87,6 +92,6 @@ def main():
editor = get_editor(args.v) editor = get_editor(args.v)
if args.c: delete_all(sk_path) if args.c: delete_all(sk_path)
elif args.l: list_all(sk_path) elif args.l: list_all(sk_path)
else: run(editor,sk_path, args.filename) else: run(editor,sk_path, args.filename, args.s)
main() main()