From 13bd3e4703b705475cad1037ca0e7aae52450b85 Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 5 Mar 2026 00:44:24 -0800 Subject: [PATCH 1/8] fixed path concat in delete_files --- skratch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/skratch.py b/skratch.py index 5011449..329fccb 100755 --- a/skratch.py +++ b/skratch.py @@ -15,8 +15,9 @@ def delete_all(d): print("Nothing to delete") else: for file in os.listdir(d): - os.remove(d+file) - print(f"removing: {d+file}") + f = os.path.join(d,file) + os.remove(f) + print(f"removing: {f}") print("Done") def list_all(d): From 94e42cfe65e2550db79d29575b446196c54c00aa Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 5 Mar 2026 00:49:05 -0800 Subject: [PATCH 2/8] added delete confirmation --- skratch.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/skratch.py b/skratch.py index 329fccb..a892bcd 100755 --- a/skratch.py +++ b/skratch.py @@ -14,11 +14,14 @@ def delete_all(d): if not os.path.exists(d): print("Nothing to delete") else: - for file in os.listdir(d): - f = os.path.join(d,file) - os.remove(f) - print(f"removing: {f}") - print("Done") + list_all(d) + x = input("Delete the above files? y/N ") + if x.lower() == 'y': + for file in os.listdir(d): + f = os.path.join(d,file) + os.remove(f) + print(f"removing: {f}") + print("Done") def list_all(d): if not os.path.exists(d): From 5673fe0337713821da0ce4827af6811480ad563d Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 5 Mar 2026 00:52:46 -0800 Subject: [PATCH 3/8] -l now states if .skratch is empty --- skratch.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/skratch.py b/skratch.py index a892bcd..64f01a8 100755 --- a/skratch.py +++ b/skratch.py @@ -12,7 +12,7 @@ def make_dir(d): def delete_all(d): if not os.path.exists(d): - print("Nothing to delete") + print("Skratch path doesn't exist") else: list_all(d) x = input("Delete the above files? y/N ") @@ -25,7 +25,9 @@ def delete_all(d): def list_all(d): if not os.path.exists(d): - print("Nothing to list") + print("Skratch path doesn't exist") + elif os.listdir(d) == []: + print("No skratch files exist") else: for file in os.listdir(d): print(file) From 8f7d4845596c008c486869848bd2d72a68e3e86f Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 5 Mar 2026 01:07:55 -0800 Subject: [PATCH 4/8] cleanup of list_all and delete_all --- skratch.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/skratch.py b/skratch.py index 64f01a8..695b3da 100755 --- a/skratch.py +++ b/skratch.py @@ -11,10 +11,8 @@ def make_dir(d): os.mkdir(d) def delete_all(d): - if not os.path.exists(d): - print("Skratch path doesn't exist") - else: - list_all(d) + fc = list_all(d) + if fc: x = input("Delete the above files? y/N ") if x.lower() == 'y': for file in os.listdir(d): @@ -26,11 +24,14 @@ def delete_all(d): def list_all(d): if not os.path.exists(d): print("Skratch path doesn't exist") - elif os.listdir(d) == []: + return 0 + files = os.listdir(d) + if files == []: print("No skratch files exist") else: - for file in os.listdir(d): + for file in files: print(file) + return len(files) def get_editor(use_v): v = os.getenv("VISUAL") From fe069eab7dd7a65e580f8b06a6cff90a7a17c710 Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 5 Mar 2026 01:30:21 -0800 Subject: [PATCH 5/8] fixed some nesting in delete_all --- skratch.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/skratch.py b/skratch.py index 695b3da..d88bf9a 100755 --- a/skratch.py +++ b/skratch.py @@ -11,11 +11,11 @@ def make_dir(d): os.mkdir(d) def delete_all(d): - fc = list_all(d) - if fc: + files = list_all(d) + if files: x = input("Delete the above files? y/N ") if x.lower() == 'y': - for file in os.listdir(d): + for file in files: f = os.path.join(d,file) os.remove(f) print(f"removing: {f}") @@ -31,7 +31,7 @@ def list_all(d): else: for file in files: print(file) - return len(files) + return files def get_editor(use_v): v = os.getenv("VISUAL") From 95742a7e155e9c85b1f746c4eab277076510d5a8 Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 5 Mar 2026 01:31:00 -0800 Subject: [PATCH 6/8] added formatting, requirements, and usage --- README.md | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 284bc27..6dfc170 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,27 @@ # skratch -A cli program to create and edit temporary files +# Skratch -Installation: +A cli program to quickly create and edit temporary files -mv skratch.py /usr/bin/skratch +Requirements: +python3 > 3.6 + +## Installation: + + mv skratch.py /usr/local/bin/skratch + chmod +x /usr/local/bin/skratch set an env variable for $EDITOR and/or $VISUAL in .bashrc -export EDITOR=vi -export VISUAL=geany + export EDITOR=vi + export VISUAL=geany + + + +## Usage +`skratch` creates a random file in .skratch and opens it in the EDITOR +`-c` clears/deletes all files in .skratch +`-l` lists files in .skratch +`-o ` opens a specific file +`-v` opens the VISUAL editor From 4a77a03f45990fac03e75f668ac0f2e221fc0a1f Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 5 Mar 2026 01:32:04 -0800 Subject: [PATCH 7/8] mkstemp nesting cleanup --- skratch.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/skratch.py b/skratch.py index d88bf9a..8e4598e 100755 --- a/skratch.py +++ b/skratch.py @@ -12,15 +12,17 @@ def make_dir(d): def delete_all(d): files = list_all(d) - if files: - x = input("Delete the above files? y/N ") - if x.lower() == 'y': - for file in files: - f = os.path.join(d,file) - os.remove(f) - print(f"removing: {f}") - print("Done") - + if not files: + return + x = input("Delete the above files? y/N ") + if x.lower() != 'y': + return + for file in files: + f = os.path.join(d,file) + os.remove(f) + print(f"removing: {f}") + print("Done") + def list_all(d): if not os.path.exists(d): print("Skratch path doesn't exist") @@ -43,17 +45,17 @@ def get_editor(use_v): return e def mkstemp(fp): - if fp[-6:] == "XXXXXX": - for x in range(0,1000): - r = ''.join(random.choices(string.ascii_letters, k=6)) - fp = fp[:-6] + r - if not os.path.exists(fp): - return fp - print("Error: Could not create new file, try running skratch -c and try again") - return None - else: + if fp[-6:] != "XXXXXX": print(f'Error: mkstemp got filepath: {fp}') return None + for x in range(0,1000): + r = ''.join(random.choices(string.ascii_letters, k=6)) + fp = fp[:-6] + r + if not os.path.exists(fp): + return fp + print("Error: Could not create new file, try running skratch -c and try again") + return None + def run(editor, sk_path, filename=None): if not filename: From 06965f9762795c7047beb4ebbe292e0d0f971fa9 Mon Sep 17 00:00:00 2001 From: phixxy Date: Thu, 5 Mar 2026 01:35:41 -0800 Subject: [PATCH 8/8] fixed help menu -o arg --- skratch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/skratch.py b/skratch.py index 8e4598e..8cbdd0f 100755 --- a/skratch.py +++ b/skratch.py @@ -89,6 +89,7 @@ def main(): group.add_argument( "-o", + metavar="", help="open file", action="store")