summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2013-02-18 01:21:16 +0100
committerhut <hut@lavabit.com>2013-02-18 01:21:16 +0100
commit740d1e5fd20525f2ac2c6b6af493b0c21d2e845e (patch)
tree58bb68e0ba333c39bc40bb1e1e130c3dbd056f59 /ranger
parent95bca173ce92294f31c052555b78938626f3c120 (diff)
parent2b3110fcfe4ecfeec120c700eb7b7ddb85c4fc40 (diff)
downloadranger-740d1e5fd20525f2ac2c6b6af493b0c21d2e845e.tar.gz
Merge branch 'master' into vcs
Conflicts:
	doc/ranger.1
Diffstat (limited to 'ranger')
-rw-r--r--ranger/__init__.py2
-rw-r--r--ranger/api/commands.py2
-rw-r--r--ranger/config/commands.py64
-rw-r--r--ranger/config/rifle.conf2
-rw-r--r--ranger/core/loader.py12
-rw-r--r--ranger/core/main.py40
6 files changed, 61 insertions, 61 deletions
diff --git a/ranger/__init__.py b/ranger/__init__.py
index 6894258d..2dbffb7e 100644
--- a/ranger/__init__.py
+++ b/ranger/__init__.py
@@ -26,7 +26,7 @@ MAX_RESTORABLE_TABS = 3
 MACRO_DELIMITER = '%'
 DEFAULT_PAGER = 'less'
 LOGFILE = '/tmp/ranger_errorlog'
-USAGE = '%prog [options] [path/filename]'
+USAGE = '%prog [options] [path]'
 VERSION = 'ranger-master %s\n\nPython %s' % (__version__, sys.version)
 
 # If the environment variable XDG_CONFIG_HOME is non-empty, CONFDIR is ignored
diff --git a/ranger/api/commands.py b/ranger/api/commands.py
index ce381e18..010ea37b 100644
--- a/ranger/api/commands.py
+++ b/ranger/api/commands.py
@@ -12,7 +12,7 @@ from ranger.core.shared import FileManagerAware
 from ranger.ext.lazy_property import lazy_property
 
 SETTINGS_RE = re.compile(r'^\s*([^\s]+?)=(.*)$')
-DELETE_WARNING = 'delete seriously? '
+DELETE_WARNING = 'delete seriously? '  # COMPAT
 
 def alias(*_): pass # COMPAT
 
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 94304f1c..daeb49f7 100644
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -1056,22 +1056,33 @@ class pmap(map_):
     context = 'pager'
 
 
-# TODO: Maybe merge this with :find?
-class narrow(Command):
+class travel(Command):
     """
-    :narrow <string>
+    :travel <string>
 
-    Displays only the files which contain <string> in their basename.
-    Unlike :filter, this command executes the selection and removes the filter
-    again when run.
+    Filters the current directory for files containing the letters in the
+    string, possibly with other letters in between.  The filter is applied as
+    you type.  When only one directory is left, it is entered and the console
+    is automatially reopened, allowing for fast travel.
+    To close the console, press ESC or execute a file.
     """
 
     def execute(self):
+        thisdir = self.fm.thisdir
+
         self.cancel() # Clean up
         if self.rest(1) == "..":
             self.fm.move(left=1)
-        else:
+        elif len(thisdir.files) > 0:
             self.fm.move(right=1)
+        else:
+            self.fm.cd(self.rest(1))
+
+        # reopen the console:
+        if thisdir != self.fm.thisdir:
+            self.fm.open_console(self.__class__.__name__ + " ")
+            if self.rest(1) != "..":
+                self.fm.block_input(0.5)
 
     def cancel(self):
         self.fm.thisdir.temporary_filter = None
@@ -1080,9 +1091,15 @@ class narrow(Command):
     def quick(self):
         self.fm.thisdir.temporary_filter = self.build_regex(self.rest(1))
         self.fm.thisdir.load_content(schedule=False)
+        arg = self.rest(1)
+
+        if arg == ".":
+            return False # Make sure we can always use ".."
+        elif arg and len(self.fm.thisdir.files) == 1 or arg == "..":
+            return True
 
     def tab(self):
-        if self.fm.env.cwd.files[-1] is not self.fm.env.cf:
+        if self.fm.thisdir.files[-1] is not self.fm.thisfile:
             self.fm.move(down=1)
         else:
             # We're at the bottom, so wrap
@@ -1102,35 +1119,6 @@ class narrow(Command):
         return re.compile(regex % ".*".join(arg), flags)
 
 
-class travel(narrow, Command):
-    """
-    :travel <string>
-
-    Displays only the files which contain <string> in their basename.
-    Unlike :narrow, this leaves open the console so you can travel faster
-    from directory to directory.
-    """
-
-    def execute(self):
-        thisfile = self.fm.thisfile
-        narrow.execute(self)
-
-        # reopen the console:
-        if thisfile and thisfile.is_directory or self.rest(1) == "..":
-            self.fm.open_console(self.__class__.__name__ + " ")
-            if self.rest(1) != "..":
-                self.fm.block_input(0.5)
-
-    def quick(self):
-        narrow.quick(self)
-        arg = self.rest(1)
-
-        if arg == ".":
-            return False # Make sure we can always use ".."
-        elif arg and len(self.fm.thisdir.files) == 1 or arg == "..":
-            return True
-
-
 class filter(Command):
     """
     :filter <string>
@@ -1154,7 +1142,7 @@ class grep(Command):
 
     def execute(self):
         if self.rest(1):
-            action = ['grep', '--color=always', '--line-number']
+            action = ['grep', '--line-number']
             action.extend(['-e', self.rest(1), '-r'])
             action.extend(f.path for f in self.fm.thistab.get_selection())
             self.fm.execute_command(action, flags='p')
diff --git a/ranger/config/rifle.conf b/ranger/config/rifle.conf
index 842c85e2..cc369cda 100644
--- a/ranger/config/rifle.conf
+++ b/ranger/config/rifle.conf
@@ -96,7 +96,7 @@ name ^[mM]akefile$            = make
 ext py  = python -- "$1"
 ext pl  = perl -- "$1"
 ext rb  = ruby -- "$1"
-ext sh  = bash -- "$1"
+ext sh  = sh -- "$1"
 ext php = php -- "$1"
 
 #--------------------------------------------
diff --git a/ranger/core/loader.py b/ranger/core/loader.py
index bae19e9e..926c11d1 100644
--- a/ranger/core/loader.py
+++ b/ranger/core/loader.py
@@ -133,6 +133,7 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
         self.kill_on_pause = kill_on_pause
 
     def generate(self):
+        py3 = sys.version >= '3'
         if self.input:
             stdin = PIPE
         else:
@@ -141,12 +142,17 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
                 stdout=PIPE, stderr=PIPE, stdin=stdin)
         self.signal_emit('before', process=process, loader=self)
         if self.input:
+            if py3:
+                import io
+                stdin = io.TextIOWrapper(process.stdin)
+            else:
+                stdin = process.stdin
             try:
-                process.stdin.write(self.input)
+                stdin.write(self.input)
             except IOError as e:
                 if e.errno != errno.EPIPE and e.errno != errno.EINVAL:
                     raise
-            process.stdin.close()
+            stdin.close()
         if self.silent and not self.read:
             while process.poll() is None:
                 yield
@@ -154,7 +160,6 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
                     break
                 sleep(0.03)
         else:
-            py3 = sys.version >= '3'
             selectlist = []
             if self.read:
                 selectlist.append(process.stdout)
@@ -199,6 +204,7 @@ class CommandLoader(Loadable, SignalDispatcher, FileManagerAware):
         if not self.finished and not self.paused:
             if self.kill_on_pause:
                 self.finished = True
+                self.process.kill()
                 return
             try:
                 self.process.send_signal(20)
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 579d40eb..16096deb 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -34,13 +34,13 @@ def main():
         os.environ[level] = '1'
 
     if not 'SHELL' in os.environ:
-        os.environ['SHELL'] = 'bash'
+        os.environ['SHELL'] = 'sh'
 
     ranger.arg = arg = parse_arguments()
     if arg.copy_config is not None:
         fm = FM()
         fm.copy_config_files(arg.copy_config)
-        return 1 if arg.fail_unless_cd else 0
+        return 1 if arg.fail_unless_cd else 0 # COMPAT
     if arg.list_tagged_files:
         fm = FM()
         try:
@@ -54,7 +54,7 @@ def main():
                         sys.stdout.write(line[2:])
                 elif len(line) > 0 and '*' in arg.list_tagged_files:
                     sys.stdout.write(line)
-        return 1 if arg.fail_unless_cd else 0
+        return 1 if arg.fail_unless_cd else 0 # COMPAT
 
     SettingsAware._setup(clean=arg.clean)
 
@@ -64,13 +64,16 @@ def main():
 
     targets = arg.targets or ['.']
     target = targets[0]
-    if arg.targets:
+    if arg.targets:  # COMPAT
         if target.startswith('file://'):
             target = target[7:]
         if not os.access(target, os.F_OK):
             print("File or directory doesn't exist: %s" % target)
             return 1
         elif os.path.isfile(target):
+            sys.stderr.write("Warning: Using ranger as a file launcher is "
+                   "deprecated.\nPlease use the standalone file launcher "
+                   "'rifle' instead.\n")
             def print_function(string):
                 print(string)
             from ranger.ext.rifle import Rifle
@@ -82,7 +85,7 @@ def main():
             rifle = Rifle(rifleconf)
             rifle.reload_config()
             rifle.execute(targets, number=ranger.arg.mode, flags=ranger.arg.flags)
-            return 1 if arg.fail_unless_cd else 0
+            return 1 if arg.fail_unless_cd else 0 # COMPAT
 
     crash_traceback = None
     try:
@@ -101,7 +104,7 @@ def main():
             for key in range(33, 127):
                 if key not in maps:
                     print(chr(key))
-            return 1 if arg.fail_unless_cd else 0
+            return 1 if arg.fail_unless_cd else 0 # COMPAT
 
         if fm.username == 'root':
             fm.settings.preview_files = False
@@ -166,7 +169,7 @@ def main():
 
 def parse_arguments():
     """Parse the program arguments"""
-    from optparse import OptionParser
+    from optparse import OptionParser, SUPPRESS_HELP
     from os.path import expanduser
     from ranger import CONFDIR, USAGE, VERSION
     from ranger.ext.openstruct import OpenStruct
@@ -182,20 +185,18 @@ def parse_arguments():
             help="activate debug mode")
     parser.add_option('-c', '--clean', action='store_true',
             help="don't touch/require any config files. ")
+    parser.add_option('-r', '--confdir', type='string',
+            metavar='dir', default=default_confdir,
+            help="change the configuration directory. (%default)")
     parser.add_option('--copy-config', type='string', metavar='which',
             help="copy the default configs to the local config directory. "
             "Possible values: all, rc, rifle, commands, scope")
     parser.add_option('--fail-unless-cd', action='store_true',
-            help="experimental: return the exit code 1 if ranger is" \
-                    "used to run a file (with `ranger filename`)")
-    parser.add_option('-r', '--confdir', type='string',
-            metavar='dir', default=default_confdir,
-            help="the configuration directory. (%default)")
+            help=SUPPRESS_HELP)  # COMPAT
     parser.add_option('-m', '--mode', type='int', default=0, metavar='n',
-            help="if a filename is supplied, run it with this mode")
+            help=SUPPRESS_HELP)  # COMPAT
     parser.add_option('-f', '--flags', type='string', default='',
-            metavar='string',
-            help="if a filename is supplied, run it with these flags.")
+            metavar='string', help=SUPPRESS_HELP)  # COMPAT
     parser.add_option('--choosefile', type='string', metavar='TARGET',
             help="Makes ranger act like a file chooser. When opening "
             "a file, it will quit and write the name of the selected "
@@ -207,10 +208,10 @@ def parse_arguments():
     parser.add_option('--choosedir', type='string', metavar='TARGET',
             help="Makes ranger act like a directory chooser. When ranger quits"
             ", it will write the name of the last visited directory to TARGET")
-    parser.add_option('--list-unused-keys', action='store_true',
-            help="List common keys which are not bound to any action.")
     parser.add_option('--selectfile', type='string', metavar='filepath',
             help="Open ranger with supplied file selected.")
+    parser.add_option('--list-unused-keys', action='store_true',
+            help="List common keys which are not bound to any action.")
     parser.add_option('--list-tagged-files', type='string', default=None,
             metavar='tag',
             help="List all files which are tagged with the given tag, default: *")
@@ -224,6 +225,11 @@ def parse_arguments():
     arg = OpenStruct(options.__dict__, targets=positional)
     arg.confdir = expanduser(arg.confdir)
 
+    if arg.fail_unless_cd: # COMPAT
+        sys.stderr.write("Warning: The option --fail-unless-cd is deprecated.\n"
+            "It was used to faciliate using ranger as a file launcher.\n"
+            "Now, please use the standalone file launcher 'rifle' instead.\n")
+
     return arg