mirror of
https://github.com/powerline/powerline.git
synced 2025-07-28 00:04:39 +02:00
Handle non-existant CWDs gracefully
This commit is contained in:
parent
e14f5e4208
commit
ee51b8b76c
@ -51,10 +51,18 @@ def cwd(dir_shorten_len=None, dir_limit_depth=None):
|
||||
limit directory depth to this number (e.g. :file:`/long/path/to/powerline` → :file:`⋯/to/powerline`)
|
||||
'''
|
||||
import re
|
||||
try:
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user