summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authormrogalski <interesting.ones.are.already.taken@gmail.com>2016-09-16 09:53:11 +0200
committernfnty <git@nfnty.se>2017-01-31 22:55:17 +0100
commitcc8f5270fdb52714c4606ac62eea0de9c6aac04a (patch)
treed4f64f270e4b0e0d913cebc6496478d721ed49e7 /ranger
parent648c3f2cbd126db8ef0e52e0d5d0429ca636d172 (diff)
downloadranger-cc8f5270fdb52714c4606ac62eea0de9c6aac04a.tar.gz
`--choosefiles`: Choose all selected files, not just CWD
Check that paths are accessible and writable

Fixes #667
Diffstat (limited to 'ranger')
-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"