Skip to content

Commit 5326608

Browse files
committed
Proof of concept for .cd command
Proposed in awslabs#76. Still needs discussion for whether or not this should be a dot command. If we go with this approach the only thing left is tests.
1 parent 9149483 commit 5326608

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

awsshell/app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ class InputInterrupt(Exception):
4545
pass
4646

4747

48+
class ChangeDirHandler(object):
49+
def run(self, command, application):
50+
# command is a list of parsed commands
51+
if len(command) != 2:
52+
sys.stderr.write("invalid syntax, must be: .cd dirname\n")
53+
return
54+
dirname = os.path.expandvars(os.path.expanduser(command[1]))
55+
try:
56+
os.chdir(dirname)
57+
except OSError as e:
58+
sys.stderr.write("cd: %s\n" % e)
59+
60+
4861
class EditHandler(object):
4962
def __init__(self, popen_cls=None, env=None):
5063
if popen_cls is None:
@@ -85,6 +98,7 @@ def run(self, command, application):
8598
class DotCommandHandler(object):
8699
HANDLER_CLASSES = {
87100
'edit': EditHandler,
101+
'cd': ChangeDirHandler,
88102
}
89103

90104
def __init__(self, output=sys.stdout, err=sys.stderr):

0 commit comments

Comments
 (0)