Compare commits
3 commits
f210bd0535
...
77f313001a
| Author | SHA1 | Date | |
|---|---|---|---|
| 77f313001a | |||
| e851d44471 | |||
| ac1acfb908 |
2 changed files with 16 additions and 22 deletions
10
README.md
10
README.md
|
|
@ -15,15 +15,13 @@ 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
|
||||||
|
|
||||||
`-c` clears/deletes all files in .skratch
|
`<filename>` opens or creates a file with a specific name in ~/.skratch
|
||||||
|
|
||||||
`-l` lists files in .skratch
|
`-c` clears/deletes all files in ~/.skratch
|
||||||
|
|
||||||
`-o <filename>` opens (or creates) a file with a specific name
|
`-l` lists files in ~/.skratch
|
||||||
|
|
||||||
`-v` opens the VISUAL editor
|
`-v` uses the VISUAL editor
|
||||||
|
|
|
||||||
28
skratch.py
28
skratch.py
|
|
@ -1,5 +1,4 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
|
|
@ -20,7 +19,7 @@ def delete_all(d):
|
||||||
for file in files:
|
for file in files:
|
||||||
f = os.path.join(d,file)
|
f = os.path.join(d,file)
|
||||||
os.remove(f)
|
os.remove(f)
|
||||||
print(f"removing: {f}")
|
print(f"Removing: {f}")
|
||||||
print("Done")
|
print("Done")
|
||||||
|
|
||||||
def list_all(d):
|
def list_all(d):
|
||||||
|
|
@ -62,9 +61,16 @@ def main():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='skratch',
|
prog='skratch',
|
||||||
description='Creates a temp file and opens it in an editor',
|
description='Creates a temp file and opens it in an editor')
|
||||||
epilog='Text at the bottom of help')
|
|
||||||
group = parser.add_mutually_exclusive_group()
|
group = parser.add_mutually_exclusive_group()
|
||||||
|
|
||||||
|
group.add_argument(
|
||||||
|
"filename",
|
||||||
|
nargs="?",
|
||||||
|
help="open file in ~/.skratch",
|
||||||
|
default=None)
|
||||||
|
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-c",
|
"-c",
|
||||||
help="delete all files",
|
help="delete all files",
|
||||||
|
|
@ -75,12 +81,6 @@ def main():
|
||||||
help="list files",
|
help="list files",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
|
|
||||||
group.add_argument(
|
|
||||||
"-o",
|
|
||||||
metavar="<file>",
|
|
||||||
help="open file",
|
|
||||||
action="store")
|
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-v",
|
"-v",
|
||||||
help="visual editor",
|
help="visual editor",
|
||||||
|
|
@ -88,13 +88,9 @@ def main():
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
filename = "skratch-XXXXXX"
|
|
||||||
|
|
||||||
editor = get_editor(args.v)
|
editor = get_editor(args.v)
|
||||||
if args.o: run(editor,sk_path,args.o)
|
if 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: run(editor,sk_path)
|
else: run(editor,sk_path, args.filename)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue