summaryrefslogtreecommitdiffstats
path: root/lldb/examples/customization
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2011-10-13 01:20:34 +0000
committerJohnny Chen <johnny.chen@apple.com>2011-10-13 01:20:34 +0000
commit7596f9373a10ead8bd824e7cbb96026e264602b7 (patch)
treefcffa687e25e848d8c60e2f3a42a754fc82bdd48 /lldb/examples/customization
parent4f76b23764ee7fe2847483fb5c9e4c2e7af4c1aa (diff)
downloadbcm5719-llvm-7596f9373a10ead8bd824e7cbb96026e264602b7.tar.gz
bcm5719-llvm-7596f9373a10ead8bd824e7cbb96026e264602b7.zip
Add 'cd -' feature to change to the previous working directory.
llvm-svn: 141846
Diffstat (limited to 'lldb/examples/customization')
-rw-r--r--lldb/examples/customization/pwd-cd-and-system/utils.py36
1 files changed, 30 insertions, 6 deletions
diff --git a/lldb/examples/customization/pwd-cd-and-system/utils.py b/lldb/examples/customization/pwd-cd-and-system/utils.py
index 27836f62e1c..0a29420a4ee 100644
--- a/lldb/examples/customization/pwd-cd-and-system/utils.py
+++ b/lldb/examples/customization/pwd-cd-and-system/utils.py
@@ -2,13 +2,37 @@
import os, shlex, subprocess
+# Store the previous working directory for the 'cd -' command.
+class Holder:
+ """Holds the _prev_dir_ class attribute for chdir() function."""
+ _prev_dir_ = None
+
+ @classmethod
+ def prev_dir(cls):
+ return cls._prev_dir_
+
+ @classmethod
+ def swap(cls, dir):
+ cls._prev_dir_ = dir
+
def chdir(debugger, args, result, dict):
- """Change the working directory, or cd to ${HOME}."""
- dir = args.strip()
- if dir:
- os.chdir(args)
- else:
- os.chdir(os.path.expanduser('~'))
+ """
+ Change the working directory, or cd to ${HOME}.
+ You can also issue 'cd -' to change to the previous working directory.
+ """
+ new_dir = args.strip()
+ if not new_dir:
+ new_dir = os.path.expanduser('~')
+ elif new_dir == '-':
+ if not Holder.prev_dir():
+ # Bad directory, not changing.
+ print "bad directory, not changing"
+ return
+ else:
+ new_dir = Holder.prev_dir()
+
+ Holder.swap(os.getcwd())
+ os.chdir(new_dir)
print "Current working directory: %s" % os.getcwd()
def system(debugger, command_line, result, dict):
OpenPOWER on IntegriCloud