- #!/usr/bin/env python
-
- import os,sys
- #import fcntl,termios
- import winput
- from winput.vk_codes import *
-
- dirlstfile = "\\bin\\.dirlst"
- dirlst = open(dirlstfile, "r+").read().split("\n")[:-1]
- updated = 0
-
- def listdir(dirlst, filter):
- startc = 'a'
- lastc = 'a'
- dircnt = 0
- for item in dirlst:
- if item!='' and filter in item:
- print(startc,item)
- lastc = startc
- dircnt+=1
- startc=chr(ord(startc)+1)
- if dircnt == 0 :
- print("use 'c +' to add dir cache")
- return
- if dircnt == 1:
- seldir(dirlst, lastc)
- return
- ret = input("select:")
- if ret == '':return
- seldir(dirlst, ret[0])
-
- def shellcmd(cmd):
- #for c in cmd:fcntl.ioctl(0, termios.TIOCSTI,c)
- for c in cmd:
- val = ord(c)
-
- if c==':':
- winput.press_key(VK_SHIFT)
- winput.click_key(0xBA)
- winput.release_key(VK_SHIFT)
- continue
-
- if c=='\\':
- winput.click_key(0xE2)
- continue
-
- if val==0x0a:
- winput.click_key(0x0D)
- continue
-
- if c=='/':
- winput.click_key(0xBF)
- continue
-
- if c=='.':
- winput.click_key(0xBE)
- continue
-
- if val>= 0x40 and val<0x60:
- winput.press_key(VK_SHIFT)
- winput.click_key(val)
- winput.release_key(VK_SHIFT)
- continue
-
- if val>= 0x60 and val<0x80:
- val &= ~0x20
-
- winput.click_key(val)
- winput.stop()
-
- def seldir(dirlst, c):
- #print("cd %s\n"%(dirlst[ord(c)-ord('a')]))
- shellcmd("cd %s\n"%(dirlst[ord(c)-ord('a')]))
-
- if len(sys.argv) > 1:
- if sys.argv[1] == '-':
- updated = 1
- if len(sys.argv) == 2:
- if os.getcwd() in dirlst:
- print("remove self")
- dirlst.remove(os.getcwd())
- else:
- startc = 'a'
- dirbak = dirlst.copy()
- for item in dirlst:
- if startc in sys.argv[2]: dirbak.remove(item)
- startc=chr(ord(startc)+1)
- dirlst = dirbak.copy()
-
- elif sys.argv[1] == '+':
- if os.getcwd() not in dirlst:
- dirlst.append(os.getcwd())
- for item in dirlst:
- if item=="":
- item=os.getcwd()
- dirlst=dirlst[:-1]
- break
- updated = 1
- elif '1' <= sys.argv[1][0] <= '9' and len(sys.argv[1]) == 1:
- shellcmd("cd %s\n"%('../'*(ord(sys.argv[1])-ord('0'))))
- elif len(sys.argv[1]) == 1:
- seldir(dirlst, sys.argv[1])
- else:
- listdir(dirlst, sys.argv[1])
-
- else:
- listdir(dirlst, "")
-
- if updated == 1:
- fl = open(dirlstfile, "w")
- for item in dirlst:
- fl.write("%s\n"%item)
效果截图,切换任意目录,只需要一行3~4个字符的按键命令。
