summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/core/actions.py13
-rw-r--r--ranger/core/fm.py3
-rw-r--r--ranger/core/main.py20
3 files changed, 32 insertions, 4 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 7e549d30..f936755f 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -405,8 +405,15 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
                 open(ranger.args.choosefile, 'w').write(self.fm.thisfile.path)
 
             if ranger.args.choosefiles:
-                open(ranger.args.choosefiles, 'w').write("".join(
-                    fobj.path + "\n" for fobj in self.fm.thistab.get_selection()))
+                paths = []
+                for hist in self.fm.thistab.history:
+                    for fobj in hist.files:
+                        if fobj.marked and fobj.path not in paths:
+                            paths += [fobj.path]
+                paths += [f.path for f in self.fm.thistab.get_selection() if f.path not in paths]
+
+                with open(ranger.args.choosefiles, 'w') as fobj:
+                    fobj.write('\n'.join(paths) + '\n')
 
             if ranger.args.choosefile or ranger.args.choosefiles:
                 raise SystemExit
@@ -421,7 +428,7 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
             files = [self.fm.thisfile]
 
         self.signal_emit('execute.before', keywords=kw)
-        filenames = [fobj.path for fobj in files]
+        filenames = [f.path for f in files]
         label = kw.get('label', kw.get('app', None))
         try:
             return self.rifle.execute(filenames, mode, label, flags, None)
diff --git a/ranger/core/fm.py b/ranger/core/fm.py
index 2db18c40..9e703327 100644
--- a/ranger/core/fm.py
+++ b/ranger/core/fm.py
@@ -390,6 +390,7 @@ class FM(Actions,  # pylint: disable=too-many-instance-attributes
             if ranger.args.choosedir and self.thisdir and self.thisdir.path:
                 # XXX: UnicodeEncodeError: 'utf-8' codec can't encode character
                 # '\udcf6' in position 42: surrogates not allowed
-                open(ranger.args.choosedir, 'w').write(self.thisdir.path)
+                with open(ranger.args.choosedir, 'w') as fobj:
+                    fobj.write(self.thisdir.path)
             self.bookmarks.remember(self.thisdir)
             self.bookmarks.save()
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 8ebce9b5..3c7ae13b 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -263,6 +263,26 @@ def parse_arguments():
     args.confdir = expanduser(args.confdir)
     args.cachedir = expanduser(default_cachedir)
 
+    def choose_init(flag):
+        argval = args.__dict__['choose' + flag]
+        try:
+            path = os.path.abspath(argval)
+        except OSError as ex:
+            sys.stderr.write(
+                '--choose{0} is not accessible: {1}\n{2}\n'.format(flag, argval, str(ex)))
+            sys.exit(1)
+        if os.path.exists(path) and not os.access(path, os.W_OK):
+            sys.stderr.write('--choose{0} is not writable: {1}\n'.format(flag, path))
+            sys.exit(1)
+        return path
+
+    if args.choosefile:
+        args.choosefile = choose_init('file')
+    if args.choosefiles:
+        args.choosefiles = choose_init('files')
+    if args.choosedir:
+        args.choosedir = choose_init('dir')
+
     if args.fail_unless_cd:  # COMPAT
         sys.stderr.write("Warning: The option --fail-unless-cd is deprecated.\n"
                          "It was used to facilitate using ranger as a file launcher.\n"