Skip to content

Commit

Permalink
Merge branch 'tmp' into dev
Browse files Browse the repository at this point in the history
Improve initializing handling
  • Loading branch information
Michael1015198808 committed May 25, 2020
2 parents 612b4b9 + fbfd15d commit 80e1bf4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# zsh-vocab
Have you ever think of a software or a plugin that allows you to recite words at any time?
Though this tool can't allow you to recite word at any time, it allows you to recite words when using zsh!(Or other powerful shell)
## Version
1.05

## Demo
![](demo.gif)
![](pics/demo.gif)

## screenshots
![](screenshots/demo1.png)
Expand Down
4 changes: 3 additions & 1 deletion UPDATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## V 1.05
Improve initializing handling.
## V 1.04
know now support assign a specific word excpet the last word.
`know` command now support assign a specific word excpet the last word.
## V 1.03
Command Add: know
mark a word as known to decrease its probability to appear.
Expand Down
7 changes: 5 additions & 2 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ def get_word(namespace):
except:
i=0
words=read()
if i==-1:
i=len(words)-1
if words == []:
print("No words in current vocabulary list!", file = stderr)
exit()
if i == -1:
i = len(words)-1
else:
while True:
i+=randint(0,len(words)-1)
Expand Down
19 changes: 15 additions & 4 deletions include.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from sys import argv
from sys import stderr
def read():
try:
os.mkdir(os.path.expanduser("~/.vocab"))
except FileExistsError:
pass
try:
with open(os.path.expanduser("~/.vocab/data.json"),"r") as f:
try:
Expand All @@ -11,16 +15,23 @@ def read():
print(os.path.expanduser("~/.vocab/data.json"+" can't be decoded."),file=stderr)
print("See if it's set to a wrong authority",file=stderr)
print("or the file is broken",file=stderr)
words=[]
print("Type Y to clear the file.", file=stderr)
if input() == 'Y':
write([])
words=[]
else:
exit()
return words
except FileNotFoundError:
print(os.path.expanduser("~/.vocab/data.json"+" is not found."),file=stderr)
print("call "+argv[0]+" help for more information",file=stderr)
print(os.path.expanduser("~/.vocab/data.json"), "is not found.", file=stderr)
print("Initialize it with an empty list", file=stderr)
write([])
return []

def write(words):
try:
with open(os.path.expanduser("~/.vocab/data.json"),"w") as f:
json.dump((words),f)
except FileNotFoundError:
print(os.path.expanduser("~/.vocab/data.json"+" is not found."),file=stderr)
print("call "+argv[0]+" help for more information",file=stderr)
print("call "+argv[0]+" --help for more information",file=stderr)
File renamed without changes

0 comments on commit 80e1bf4

Please sign in to comment.