-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathup.py
More file actions
executable file
·40 lines (34 loc) · 903 Bytes
/
up.py
File metadata and controls
executable file
·40 lines (34 loc) · 903 Bytes
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
38
39
40
#!/usr/bin/python
from __future__ import print_function
import os, sys
from os.path import expanduser
cwd = os.getcwd().split(os.sep)[::-1][:-1]
home = expanduser("~")
arg_input = None
if len(sys.argv) != 2:
for i, dir in enumerate(cwd):
print("% 2d. %s" % (i, dir), file=sys.stderr)
print("? ", file=sys.stderr, end='')
arg_input = raw_input()
else:
arg_input = sys.argv[1]
levels_up = None
if arg_input.isdigit():
levels_up = int(arg_input)
elif arg_input == '~' or arg_input == home:
levels_up = -1
elif arg_input == '':
levels_up = 0
else:
match = arg_input
try:
levels_up = cwd.index(match)
except:
print("up: '%s' is neither a number, nor something in your path" % match, file=sys.stderr)
print("__no_path_found__")
if levels_up > 0:
print("../" * levels_up)
elif levels_up == -1:
print("")
else:
print(".")