|
|
@ -33,6 +33,24 @@ def no_parents(paths): |
|
|
paths.append(path) |
|
|
paths.append(path) |
|
|
return ret |
|
|
return ret |
|
|
|
|
|
|
|
|
|
|
|
def abbreviate(path,n=72): |
|
|
|
|
|
if len(path) > n: |
|
|
|
|
|
elements = [] |
|
|
|
|
|
b = os.path.basename(path) |
|
|
|
|
|
while not b == '': |
|
|
|
|
|
elements.append(b) |
|
|
|
|
|
os.path.basename(path) |
|
|
|
|
|
path = os.path.dirname(path) |
|
|
|
|
|
b = os.path.basename(path) |
|
|
|
|
|
elements.append(path) |
|
|
|
|
|
elements = elements[::-1] |
|
|
|
|
|
l = len(elements) |
|
|
|
|
|
prefix = elements[:l//2] |
|
|
|
|
|
postfix = elements[l//2:] |
|
|
|
|
|
|
|
|
|
|
|
while len(os.path.join(*prefix,'...',*postfix)) |
|
|
|
|
|
else: |
|
|
|
|
|
return path |
|
|
|
|
|
|
|
|
def str_coerce(s,**kwargs): |
|
|
def str_coerce(s,**kwargs): |
|
|
if isinstance(s,datetime.datetime): |
|
|
if isinstance(s,datetime.datetime): |
|
|
@ -50,11 +68,11 @@ def print2d(l,datetime_format = "%A, %B %e, %Y %H:%M:%S",seperator= ' | ',spacer |
|
|
except IndexError: |
|
|
except IndexError: |
|
|
max_col.append(len(col)) |
|
|
max_col.append(len(col)) |
|
|
|
|
|
|
|
|
fmt_row = '{content}' |
|
|
|
|
|
|
|
|
fmt_row = '{content}' |
|
|
if l_end: |
|
|
if l_end: |
|
|
fmt_row = f'{l_end} ' + fmt_row |
|
|
|
|
|
if r_end: |
|
|
|
|
|
fmt_row = fmt_row + f' {r_end}' |
|
|
|
|
|
|
|
|
fmt_row = '{} {}'.format(l_end,fmt_row) |
|
|
|
|
|
if r_end: |
|
|
|
|
|
fmt_row = '{} {}'.format(fmt_row,r_end) |
|
|
|
|
|
|
|
|
done = [] |
|
|
done = [] |
|
|
for row in l: |
|
|
for row in l: |
|
|
@ -64,14 +82,40 @@ if r_end: |
|
|
if bottom: |
|
|
if bottom: |
|
|
bottom = bottom*len(done[0]) |
|
|
bottom = bottom*len(done[0]) |
|
|
row_sep = ('\n'+bottom+'\n') |
|
|
row_sep = ('\n'+bottom+'\n') |
|
|
else: |
|
|
|
|
|
row_sep = '\n' |
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
row_sep = '\n' |
|
|
final = row_sep.join(done) |
|
|
final = row_sep.join(done) |
|
|
if bottom: |
|
|
if bottom: |
|
|
final = '\n'.join((bottom,final,bottom)) |
|
|
final = '\n'.join((bottom,final,bottom)) |
|
|
if interactive: |
|
|
|
|
|
if not bottom: |
|
|
|
|
|
final += '\n' |
|
|
|
|
|
|
|
|
if interactive: |
|
|
|
|
|
if not bottom: |
|
|
|
|
|
final += '\n' |
|
|
pager(final) |
|
|
pager(final) |
|
|
else: |
|
|
else: |
|
|
return final |
|
|
return final |
|
|
|
|
|
|
|
|
|
|
|
def picker(rows,interactive=False): |
|
|
|
|
|
opts = { |
|
|
|
|
|
'spacer':' ', |
|
|
|
|
|
'seperator':' ', |
|
|
|
|
|
'interactive': interactive, |
|
|
|
|
|
'bottom':'=', |
|
|
|
|
|
'l_end':'<', |
|
|
|
|
|
'r_end':'>', |
|
|
|
|
|
} |
|
|
|
|
|
drows = ( (i,)+row for i,row in enumerate(rows)) |
|
|
|
|
|
print2d(drows,**opts) |
|
|
|
|
|
which = None |
|
|
|
|
|
while not which: |
|
|
|
|
|
try: |
|
|
|
|
|
which = input('Which one?: ') |
|
|
|
|
|
except KeyboardInterrupt: |
|
|
|
|
|
quit() |
|
|
|
|
|
try: |
|
|
|
|
|
which = srt_keys[int(which)] |
|
|
|
|
|
except ValueError: |
|
|
|
|
|
which = None |
|
|
|
|
|
return rows[which] |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
|
|
abbreviate(os.getcwd()) |