summary refs log tree commit diff stats
diff options
context:
space:
mode:
authortau3 <smr.oznob@gmail.com>2018-02-15 20:11:00 +0400
committertau3 <smr.oznob@gmail.com>2018-02-15 20:11:00 +0400
commit7324552d9f89e18046bf4d511317a940105287e2 (patch)
tree48cd1a61407f47c1e73b1f88d09189cbdb228659
parent324e5af2e7ec0a825305dc6a03c95efa3682869a (diff)
downloadranger-7324552d9f89e18046bf4d511317a940105287e2.tar.gz
Fixed start path resolving in case of absent working directory
-rw-r--r--.gitignore2
-rw-r--r--ranger/core/main.py23
2 files changed, 21 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 88c75b90..3d946b72 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,5 @@
 /ranger_fm.egg-info
 
 /stuff/*
+
+.idea
\ No newline at end of file
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 4adea918..5f5af332 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -93,10 +93,7 @@ def main(
         args.selectfile = os.path.abspath(args.selectfile)
         args.paths.insert(0, os.path.dirname(args.selectfile))
 
-    if args.paths:
-        paths = [p[7:] if p.startswith('file:///') else p for p in args.paths]
-    else:
-        paths = [os.environ.get('PWD', os.getcwd())]
+    paths = __get_paths(args)
     paths_inaccessible = []
     for path in paths:
         try:
@@ -235,6 +232,24 @@ https://github.com/ranger/ranger/issues
         return exit_code  # pylint: disable=lost-exception
 
 
+def __get_paths(args):
+    if args.paths:
+        prefix = 'file:///'
+        prefix_length = len(prefix)
+        paths = [path[prefix_length:] if path.startswith(prefix) else path for path in args.paths]
+    else:
+        start_directory = os.environ.get('PWD')
+        is_valid_start_directory = start_directory and os.path.exists(start_directory)
+        if not is_valid_start_directory:
+            start_directory = __get_home_directory()
+        paths = [start_directory]
+    return paths
+
+
+def __get_home_directory():
+    return os.path.expanduser('~')
+
+
 def xdg_path(env_var):
     path = os.environ.get(env_var)
     if path and os.path.isabs(path):