From ee51b8b76c1091c7abac3cdab2421d729b7bfdd8 Mon Sep 17 00:00:00 2001 From: Martin Preisler Date: Tue, 19 Feb 2013 21:11:28 +0100 Subject: [PATCH] Handle non-existant CWDs gracefully --- powerline/segments/common.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/powerline/segments/common.py b/powerline/segments/common.py index 04196924..03aad401 100644 --- a/powerline/segments/common.py +++ b/powerline/segments/common.py @@ -52,9 +52,17 @@ def cwd(dir_shorten_len=None, dir_limit_depth=None): ''' import re try: - cwd = os.getcwdu() - except AttributeError: - cwd = os.getcwd() + try: + cwd = os.getcwdu() + except AttributeError: + cwd = os.getcwd() + except OSError as e: + if e.errno == 2: + # user most probably deleted the directory + # this happens when removing files from Mercurial repos for example + cwd = "[not found]" + else: + raise home = os.environ.get('HOME') if home: cwd = re.sub('^' + re.escape(home), '~', cwd, 1)