cleanup code, use safer path concat

This commit is contained in:
phixxy 2026-03-05 00:24:40 -08:00
parent 19f13d7a42
commit 3cdd882b45

View file

@ -51,16 +51,16 @@ def mkstemp(fp):
def run(editor, sk_path, filename=None):
if not filename:
filename = "skratch-XXXXXX"
fp = sk_path + filename
fp = os.path.join(sk_path, filename)
fp = mkstemp(fp)
else:
fp = sk_path + filename
fp = os.path.join(sk_path, filename)
if fp != None:
os.execvp(editor, [editor,fp])
def main():
home_path = os.getenv("HOME")
sk_path = home_path + "/.skratch/"
sk_path = os.path.join(home_path, ".skratch")
make_dir(sk_path)
parser = argparse.ArgumentParser(
@ -78,11 +78,6 @@ def main():
help="list files",
action="store_true")
group.add_argument(
"-n",
help="new file",
action="store_const")
group.add_argument(
"-o",
help="open file",
@ -96,16 +91,12 @@ def main():
args = parser.parse_args()
filename = "skratch-XXXXXX"
home_path = os.getenv("HOME")
sk_path = home_path + "/.skratch/"
editor = get_editor(args.v)
if args.n: run(editor,sk_path,args.n)
elif args.o: run(editor,sk_path,args.o)
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)
else: run(editor,sk_path)
main()