|
|
@@ -697,28 +697,35 @@ def Cd(argv, mem, dir_stack): |
|
|
return 0
|
|
|
|
|
|
|
|
|
WITH_PREFIX = 1
|
|
|
WITHOUT_PREFIX = 2
|
|
|
WITH_LINE_NUMBERS = 1
|
|
|
WITHOUT_LINE_NUMBERS = 2
|
|
|
SINGLE_LINE = 3
|
|
|
|
|
|
def _PrintDirStack(dir_stack, style):
|
|
|
def _PrintDirStack(dir_stack, style, home_dir):
|
|
|
"""Helper for 'dirs'."""
|
|
|
|
|
|
if style == WITH_PREFIX:
|
|
|
if style == WITH_LINE_NUMBERS:
|
|
|
for i, entry in enumerate(dir_stack.Iter()):
|
|
|
print('%2d %s' % (i, entry))
|
|
|
print('%2d %s' % (i, _FormatDir(entry, home_dir)))
|
|
|
|
|
|
elif style == WITHOUT_PREFIX:
|
|
|
elif style == WITHOUT_LINE_NUMBERS:
|
|
|
for entry in dir_stack.Iter():
|
|
|
print(entry)
|
|
|
print(_FormatDir(entry, home_dir))
|
|
|
|
|
|
elif style == SINGLE_LINE:
|
|
|
print(' '.join(dir_stack.Iter()))
|
|
|
print(' '.join(_FormatDir(entry, home_dir)
|
|
|
for entry in dir_stack.Iter()))
|
|
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
|
def Pushd(argv, dir_stack):
|
|
|
def _FormatDir(dir_name, home_dir):
|
|
|
if home_dir and home_dir.tag == value_e.Str and (dir_name == home_dir.s or dir_name.startswith(home_dir.s + '/')):
|
|
|
return dir_name.replace(home_dir.s, '~', 1)
|
|
|
return dir_name
|
|
|
|
|
|
|
|
|
def Pushd(argv, home_dir, dir_stack):
|
|
|
num_args = len(argv)
|
|
|
if num_args <= 0:
|
|
|
util.error('pushd: no other directory')
|
|
|
@@ -727,19 +734,19 @@ def Pushd(argv, dir_stack): |
|
|
util.error('pushd: too many arguments')
|
|
|
return 1
|
|
|
|
|
|
dest_dir = argv[0]
|
|
|
dest_dir = os.path.abspath(argv[0])
|
|
|
try:
|
|
|
os.chdir(dest_dir)
|
|
|
except OSError as e:
|
|
|
util.error("pushd: %r: %s", dest_dir, os.strerror(e.errno))
|
|
|
return 1
|
|
|
|
|
|
dir_stack.Push(dest_dir)
|
|
|
_PrintDirStack(dir_stack, SINGLE_LINE)
|
|
|
_PrintDirStack(dir_stack, SINGLE_LINE, home_dir)
|
|
|
return 0
|
|
|
|
|
|
|
|
|
def Popd(argv, dir_stack):
|
|
|
def Popd(argv, home_dir, dir_stack):
|
|
|
dest_dir = dir_stack.Pop()
|
|
|
if dest_dir is None:
|
|
|
util.error('popd: directory stack is empty')
|
|
|
@@ -751,7 +758,7 @@ def Popd(argv, dir_stack): |
|
|
util.error("popd: %r: %s", dest_dir, os.strerror(e.errno))
|
|
|
return 1
|
|
|
|
|
|
_PrintDirStack(dir_stack, SINGLE_LINE)
|
|
|
_PrintDirStack(dir_stack, SINGLE_LINE, home_dir)
|
|
|
return 0
|
|
|
|
|
|
|
|
|
@@ -761,19 +768,22 @@ def Popd(argv, dir_stack): |
|
|
DIRS_SPEC.ShortFlag('-p')
|
|
|
DIRS_SPEC.ShortFlag('-v')
|
|
|
|
|
|
def Dirs(argv, dir_stack):
|
|
|
def Dirs(argv, home_dir, dir_stack):
|
|
|
arg, i = DIRS_SPEC.Parse(argv)
|
|
|
style = SINGLE_LINE
|
|
|
|
|
|
# Following bash order of flag priority
|
|
|
if arg.l:
|
|
|
util.warn('*** dirs -l not implemented ***')
|
|
|
# Following bash behavior
|
|
|
home_dir = None
|
|
|
if arg.c:
|
|
|
dir_stack.Reset()
|
|
|
return 0
|
|
|
elif arg.v:
|
|
|
_PrintDirStack(dir_stack, WITH_PREFIX)
|
|
|
style = WITH_LINE_NUMBERS
|
|
|
elif arg.p:
|
|
|
_PrintDirStack(dir_stack, WITHOUT_PREFIX)
|
|
|
else:
|
|
|
_PrintDirStack(dir_stack, SINGLE_LINE)
|
|
|
style = WITHOUT_LINE_NUMBERS
|
|
|
|
|
|
_PrintDirStack(dir_stack, style, home_dir)
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
0 comments on commit
fd31f81