-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasycmd.py
More file actions
executable file
·37 lines (27 loc) · 1.21 KB
/
Copy patheasycmd.py
File metadata and controls
executable file
·37 lines (27 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
import argparse
import platform
import os
from storage import Storage
def main():
parser = argparse.ArgumentParser(description='Quick save and find a frequently used command')
subparsers = parser.add_subparsers(dest='command')
cache_parser = subparsers.add_parser('cache', help='Cache a command')
cache_parser.add_argument('value', help='The command needs to be cached')
cache_parser.add_argument('-a', dest='alias', help='Alias of the command')
find_parser = subparsers.add_parser('find', help='Find a command by either entering part of it or its alias')
find_parser.add_argument('keyword', help='Keyword to find a command')
parser.add_argument('-s', dest='source', help='Source file path')
args = parser.parse_args()
path = os.path.join(args.source or os.curdir, 'easycmd.csv')
storage = Storage(path)
if args.command == 'cache':
storage.cache(args.value, args.alias or None)
elif args.command == 'find':
matches = storage.match(args.keyword)
for alias, cmd in matches.items():
print('ALIAS:', alias, 'CMD:', cmd)
else:
print('Command unsupported: ', args.command)
if __name__ == '__main__':
main()