35 lines
731 B
Python
Executable file
35 lines
731 B
Python
Executable file
#!/usr/bin/python
|
|
from configparser import ConfigParser
|
|
from os import chdir, getcwd
|
|
from os.path import isfile
|
|
from pathlib import Path
|
|
from signal import signal, SIGPIPE, SIG_DFL
|
|
from sys import argv
|
|
|
|
config = ConfigParser()
|
|
FILE = f'{getcwd()}/.goto'
|
|
while not isfile(FILE):
|
|
if(getcwd() == '/'):
|
|
exit()
|
|
else:
|
|
chdir(Path(getcwd()).parent)
|
|
FILE = f'{getcwd()}/.goto'
|
|
config.read(FILE)
|
|
places = config['goto']
|
|
|
|
if len(argv) == 0:
|
|
exit()
|
|
|
|
if argv[1] == '-l' or argv[1] == '--list':
|
|
for title in places:
|
|
print(f'{title} -> {places[title]}')
|
|
exit()
|
|
|
|
if argv[1] not in places:
|
|
exit()
|
|
|
|
path = places[argv[1]]
|
|
if path.startswith('./'):
|
|
path = f'{str(Path(FILE).parent)}/{path[2:]}'
|
|
signal(SIGPIPE, SIG_DFL)
|
|
print(path)
|