Compare commits
No commits in common. "06965f9762795c7047beb4ebbe292e0d0f971fa9" and "3cdd882b45055b33135187ee97762978745a0650" have entirely different histories.
06965f9762
...
3cdd882b45
2 changed files with 24 additions and 49 deletions
25
README.md
25
README.md
|
|
@ -1,27 +1,12 @@
|
||||||
# skratch
|
# skratch
|
||||||
|
|
||||||
# Skratch
|
A cli program to create and edit temporary files
|
||||||
|
|
||||||
A cli program to quickly create and edit temporary files
|
Installation:
|
||||||
|
|
||||||
Requirements:
|
mv skratch.py /usr/bin/skratch
|
||||||
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
|
set an env variable for $EDITOR and/or $VISUAL in .bashrc
|
||||||
|
|
||||||
export EDITOR=vi
|
export EDITOR=vi
|
||||||
export VISUAL=geany
|
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 <filename>` opens a specific file
|
|
||||||
`-v` opens the VISUAL editor
|
|
||||||
|
|
|
||||||
48
skratch.py
48
skratch.py
|
|
@ -11,29 +11,20 @@ def make_dir(d):
|
||||||
os.mkdir(d)
|
os.mkdir(d)
|
||||||
|
|
||||||
def delete_all(d):
|
def delete_all(d):
|
||||||
files = list_all(d)
|
if not os.path.exists(d):
|
||||||
if not files:
|
print("Nothing to delete")
|
||||||
return
|
else:
|
||||||
x = input("Delete the above files? y/N ")
|
for file in os.listdir(d):
|
||||||
if x.lower() != 'y':
|
os.remove(d+file)
|
||||||
return
|
print(f"removing: {d+file}")
|
||||||
for file in files:
|
print("Done")
|
||||||
f = os.path.join(d,file)
|
|
||||||
os.remove(f)
|
|
||||||
print(f"removing: {f}")
|
|
||||||
print("Done")
|
|
||||||
|
|
||||||
def list_all(d):
|
def list_all(d):
|
||||||
if not os.path.exists(d):
|
if not os.path.exists(d):
|
||||||
print("Skratch path doesn't exist")
|
print("Nothing to list")
|
||||||
return 0
|
|
||||||
files = os.listdir(d)
|
|
||||||
if files == []:
|
|
||||||
print("No skratch files exist")
|
|
||||||
else:
|
else:
|
||||||
for file in files:
|
for file in os.listdir(d):
|
||||||
print(file)
|
print(file)
|
||||||
return files
|
|
||||||
|
|
||||||
def get_editor(use_v):
|
def get_editor(use_v):
|
||||||
v = os.getenv("VISUAL")
|
v = os.getenv("VISUAL")
|
||||||
|
|
@ -45,17 +36,17 @@ def get_editor(use_v):
|
||||||
return e
|
return e
|
||||||
|
|
||||||
def mkstemp(fp):
|
def mkstemp(fp):
|
||||||
if fp[-6:] != "XXXXXX":
|
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:
|
||||||
print(f'Error: mkstemp got filepath: {fp}')
|
print(f'Error: mkstemp got filepath: {fp}')
|
||||||
return None
|
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):
|
def run(editor, sk_path, filename=None):
|
||||||
if not filename:
|
if not filename:
|
||||||
|
|
@ -89,7 +80,6 @@ def main():
|
||||||
|
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-o",
|
"-o",
|
||||||
metavar="<file>",
|
|
||||||
help="open file",
|
help="open file",
|
||||||
action="store")
|
action="store")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue