cleanup code, use safer path concat
This commit is contained in:
parent
19f13d7a42
commit
3cdd882b45
1 changed files with 5 additions and 14 deletions
19
skratch.py
19
skratch.py
|
|
@ -51,16 +51,16 @@ def mkstemp(fp):
|
||||||
def run(editor, sk_path, filename=None):
|
def run(editor, sk_path, filename=None):
|
||||||
if not filename:
|
if not filename:
|
||||||
filename = "skratch-XXXXXX"
|
filename = "skratch-XXXXXX"
|
||||||
fp = sk_path + filename
|
fp = os.path.join(sk_path, filename)
|
||||||
fp = mkstemp(fp)
|
fp = mkstemp(fp)
|
||||||
else:
|
else:
|
||||||
fp = sk_path + filename
|
fp = os.path.join(sk_path, filename)
|
||||||
if fp != None:
|
if fp != None:
|
||||||
os.execvp(editor, [editor,fp])
|
os.execvp(editor, [editor,fp])
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
home_path = os.getenv("HOME")
|
home_path = os.getenv("HOME")
|
||||||
sk_path = home_path + "/.skratch/"
|
sk_path = os.path.join(home_path, ".skratch")
|
||||||
make_dir(sk_path)
|
make_dir(sk_path)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
|
|
@ -78,11 +78,6 @@ def main():
|
||||||
help="list files",
|
help="list files",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
|
||||||
group.add_argument(
|
|
||||||
"-n",
|
|
||||||
help="new file",
|
|
||||||
action="store_const")
|
|
||||||
|
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-o",
|
"-o",
|
||||||
help="open file",
|
help="open file",
|
||||||
|
|
@ -96,16 +91,12 @@ def main():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
filename = "skratch-XXXXXX"
|
filename = "skratch-XXXXXX"
|
||||||
home_path = os.getenv("HOME")
|
|
||||||
sk_path = home_path + "/.skratch/"
|
|
||||||
|
|
||||||
editor = get_editor(args.v)
|
editor = get_editor(args.v)
|
||||||
if args.n: run(editor,sk_path,args.n)
|
if args.o: run(editor,sk_path,args.o)
|
||||||
elif args.o: run(editor,sk_path,args.o)
|
|
||||||
elif args.c: delete_all(sk_path)
|
elif args.c: delete_all(sk_path)
|
||||||
elif args.l: list_all(sk_path)
|
elif args.l: list_all(sk_path)
|
||||||
else:
|
else: run(editor,sk_path)
|
||||||
run(editor,sk_path)
|
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue