diff options
-rw-r--r-- | README | 1 | ||||
-rw-r--r-- | doc/HACKING | 1 | ||||
-rw-r--r-- | doc/ranger.1 | 88 | ||||
-rw-r--r-- | doc/ranger.pod | 90 | ||||
-rwxr-xr-x | examples/rifle_sxiv.sh | 11 | ||||
-rw-r--r-- | ranger/__init__.py | 2 | ||||
-rw-r--r-- | ranger/api/commands.py | 2 | ||||
-rw-r--r-- | ranger/config/commands.py | 64 | ||||
-rw-r--r-- | ranger/config/rifle.conf | 2 | ||||
-rw-r--r-- | ranger/core/loader.py | 12 | ||||
-rw-r--r-- | ranger/core/main.py | 40 |
11 files changed, 166 insertions, 147 deletions
diff --git a/README b/README index 52a0b66c..f5057a01 100644 --- a/README +++ b/README @@ -60,7 +60,6 @@ Optional: * w3m for the "w3mimgdisplay" program to preview images Optional, for enhanced file previews (with "scope.sh"): -* bash for running scope.sh * img2txt (from caca-utils) for previewing images * highlight for syntax highlighting of code * atool for previews of archives diff --git a/doc/HACKING b/doc/HACKING index 89452398..72dc94bc 100644 --- a/doc/HACKING +++ b/doc/HACKING @@ -29,7 +29,6 @@ Starting Points Good places to read about ranger internals are: ranger/core/actions.py -ranger/core/environment.py ranger/fsobject/fsobject.py About the UI: diff --git a/doc/ranger.1 b/doc/ranger.1 index acaca462..b43fcc62 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -124,7 +124,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.5.5" "02/17/2013" "ranger manual" +.TH RANGER 1 "ranger-1.5.5" "02/18/2013" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -133,10 +133,12 @@ ranger \- visual file manager .SH "SYNOPSIS" .IX Header "SYNOPSIS" -\&\fBranger\fR [\fB\-\-help\fR] [\fB\-\-version\fR] [\fB\-\-debug\fR] [\fB\-\-clean\fR] -[\fB\-\-list\-unused\-keys\fR] [\fB\-\-fail\-unless\-cd\fR] [\fB\-\-choosedir\fR=\fItargetfile\fR] -[\fB\-\-choosefile\fR=\fItargetfile\fR] [\fB\-\-copy\-config\fR=\fIfile\fR] [\fB\-\-mode\fR=\fImode\fR] -[\fB\-\-flags\fR=\fIflags\fR] [\fIpath/filename\fR] +\&\fBranger\fR [\fB\-\-version\fR] [\fB\-\-help\fR] [\fB\-\-debug\fR] [\fB\-\-clean\fR] +[\fB\-\-confdir\fR=\fIdirectory\fR] [\fB\-\-copy\-config\fR=\fIwhich\fR] +[\fB\-\-choosefile\fR=\fItarget\fR] [\fB\-\-choosefiles\fR=\fItarget\fR] +[\fB\-\-choosedir\fR=\fItarget\fR] [\fB\-\-selectfile\fR=\fIfilepath\fR] +[\fB\-\-list\-unused\-keys\fR] [\fB\-\-list\-tagged\-files\fR=\fItag\fR] +[\fB\-\-profile\fR] [\fB\-\-cmd\fR=\fIcommand\fR] [\fIpath\fR] .SH "DESCRIPTION" .IX Header "DESCRIPTION" ranger is a console file manager with \s-1VI\s0 key bindings. It provides a @@ -164,6 +166,14 @@ exception in the statusbar/log and try to keep running. Activate the clean mode: ranger will not access or create any configuration files nor will it leave any traces on your system. This is useful when your configuration is broken, when you want to avoid clutter, etc. +.IP "\fB\-r\fR \fIdir\fR, \fB\-\-confdir\fR=\fIdir\fR" 14 +.IX Item "-r dir, --confdir=dir" +Change the configuration directory of ranger from ~/.config/ranger to \*(L"dir\*(R". +.IP "\fB\-\-copy\-config\fR=\fIfile\fR" 14 +.IX Item "--copy-config=file" +Create copies of the default configuration files in your local configuration +directory. Existing ones will not be overwritten. Possible values: \fIall\fR, +\&\fIrc\fR, \fIcommands\fR, \fIscope\fR. .IP "\fB\-\-choosefile\fR=\fItargetfile\fR" 14 .IX Item "--choosefile=targetfile" Allows you to pick a file with ranger. This changes the behavior so that when @@ -181,11 +191,6 @@ write the last visited directory into \fItargetfile\fR. .IP "\fB\-\-selectfile\fR=\fItargetfile\fR" 14 .IX Item "--selectfile=targetfile" Open ranger with \fItargetfile\fR selected. -.IP "\fB\-\-copy\-config\fR=\fIfile\fR" 14 -.IX Item "--copy-config=file" -Create copies of the default configuration files in your local configuration -directory. Existing ones will not be overwritten. Possible values: \fIall\fR, -\&\fIrc\fR, \fIcommands\fR, \fIscope\fR. .IP "\fB\-\-list\-unused\-keys\fR" 14 .IX Item "--list-unused-keys" List common keys which are not bound to any action in the \*(L"browser\*(R" context. @@ -195,19 +200,9 @@ use the key code returned by \f(CW\*(C`getch()\*(C'\fR. .IX Item "--list-tagged-files=tag" List all files which are tagged with the given tag. Note: Tags are single characters. The default tag is \*(L"*\*(R" -.IP "\fB\-\-fail\-unless\-cd\fR" 14 -.IX Item "--fail-unless-cd" -Return the exit code 1 if ranger is used to run a file instead of used for file -browsing. (For example, \*(L"ranger \-\-fail\-unless\-cd test.txt\*(R" returns 1.) -.IP "\fB\-m\fR \fIn\fR, \fB\-\-mode\fR=\fIn\fR" 14 -.IX Item "-m n, --mode=n" -When a filename is supplied, run it in mode \fIn\fR. This has no effect unless -the execution of this file type is explicitly handled in the configuration. -.IP "\fB\-f\fR \fIflags\fR, \fB\-\-flags\fR=\fIflags\fR" 14 -.IX Item "-f flags, --flags=flags" -When a filename is supplied, run it with the given \fIflags\fR to modify -behavior. The execution of this file type is explicitly handled in the -configuration. +.IP "\fB\-\-profile\fR" 14 +.IX Item "--profile" +Print statistics of \s-1CPU\s0 usage on exit. .IP "\fB\-\-cmd\fR=\fIcommand\fR" 14 .IX Item "--cmd=command" Execute the command after the configuration has been read. Use this option @@ -628,6 +623,9 @@ Preview directories in the preview column? .IP "preview_files [bool] <zp>" 4 .IX Item "preview_files [bool] <zp>" Preview files in the preview column? +.IP "preview_images [bool]" 4 +.IX Item "preview_images [bool]" +Draw images inside the console with the external program w3mimgpreview? .IP "preview_script [string, none]" 4 .IX Item "preview_script [string, none]" Which script should handle generating previews? If the file doesn't exist, or @@ -668,7 +666,11 @@ Reverse the order of files? Which sorting mechanism should be used? Choose one of \fBatime\fR, \fBbasename\fR, \&\fBctime\fR, \fBmtime\fR, \fBnatural\fR, \fBtype\fR, \fBsize\fR .Sp -Note: You can reverse the order by using an uppercase O in the key combination. +Note: You can reverse the order by typing an uppercase second letter in the key +combination, e.g. \*(L"oN\*(R" to sort from Z to A. +.IP "status_bar_on_top [bool]" 4 +.IX Item "status_bar_on_top [bool]" +Put the status bar at the top of the window? .IP "tilde_in_titlebar [bool]" 4 .IX Item "tilde_in_titlebar [bool]" Abbreviate \f(CW$HOME\fR with ~ in the title bar (first line) of ranger? @@ -720,7 +722,7 @@ ranger. For your convenience, this is a list of the \*(L"public\*(R" commands i \& copypmap key newkey [newkey2...] \& copytmap key newkey [newkey2...] \& cunmap keys... -\& delete [confirmation] +\& delete \& edit [filename] \& eval [\-q] python_code \& filter [string] @@ -747,6 +749,7 @@ ranger. For your convenience, this is a list of the \*(L"public\*(R" commands i \& terminal \& tmap key command \& touch filename +\& travel pattern \& tunmap keys... \& unmap keys... \& unmark pattern @@ -786,9 +789,9 @@ the user, the group and others. A 1 permits execution, a 2 permits writing, a 4 permits reading. Add those numbers to combine them. So a 7 permits everything. .Sp -Key bindings in the form of [\-+]<who><what> and =<octal> also exist. For +Key bindings in the form of [\-+]<who><what> and <octal>= also exist. For example, \fB+ar\fR allows reading for everyone, \-ow forbids others to write and -=777 allows everything. +777= allows everything. .Sp See also: man 1 chmod .IP "cmap \fIkey\fR \fIcommand\fR" 2 @@ -818,14 +821,11 @@ See \f(CW\*(C`copymap\*(C'\fR .IP "cunmap [\fIkeys...\fR]" 2 .IX Item "cunmap [keys...]" Removes key mappings of the console. Works like the \f(CW\*(C`unmap\*(C'\fR command. -.IP "delete [\fIconfirmation\fR]" 2 -.IX Item "delete [confirmation]" +.IP "delete" 2 +.IX Item "delete" Destroy all files in the selection with a roundhouse kick. ranger will ask for a confirmation if you attempt to delete multiple (marked) files or non-empty -directories. -.Sp -When asking for confirmation, this command will only proceed if the last given -word starts with a `y'. +directories. This can be changed by modifying the setting \*(L"confirm_on_delete\*(R". .IP "edit [\fIfilename\fR]" 2 .IX Item "edit [filename]" Edit the current file or the file in the argument. @@ -845,9 +845,9 @@ Displays only the files which contain the \fIstring\fR in their basename. Runni this command without any parameter will reset the fitler. .IP "find \fIpattern\fR" 2 .IX Item "find pattern" -Search files in the current directory that match the given (case-insensitive) -regular expression pattern as you type. Once there is an unambiguous result, -it will be run immediately. (Or entered, if it's a directory.) +Search files in the current directory that contain the given (case-insensitive) +string in their name as you type. Once there is an unambiguous result, it will +be run immediately. (Or entered, if it's a directory.) .IP "grep \fIpattern\fR" 2 .IX Item "grep pattern" Looks for a string in all marked files or directories. @@ -878,9 +878,8 @@ Creates a directory with the name \fIdirname\fR. .IP "open_with [\fIapplication\fR] [\fIflags\fR] [\fImode\fR]" 2 .IX Item "open_with [application] [flags] [mode]" Open the selected files with the given application, unless it is omitted, in -which case the default application is used. \fIflags\fR are characters out of -\&\*(L"sdpcwSDPCW\*(R" and \fImode\fR is any positive integer. Their meanings are discussed -in their own sections. +which case the default application is used. \fIflags\fR and \fImode\fR have their +own section in the man page. .IP "pmap \fIkey\fR \fIcommand\fR" 2 .IX Item "pmap key command" Binds keys for the pager. Works like the \f(CW\*(C`map\*(C'\fR command. @@ -904,7 +903,7 @@ Rename the current file. If a file with that name already exists, the renaming will fail. Also try the key binding A for appending something to a file name. .IP "save_copy_buffer" 2 .IX Item "save_copy_buffer" -Save the copy buffer from \fI~/.config/ranger/copy_buffer\fR. This can be used to +Save the copy buffer to \fI~/.config/ranger/copy_buffer\fR. This can be used to pass the list of copied files to another ranger instance. .IP "search \fIpattern\fR" 2 .IX Item "search pattern" @@ -947,6 +946,13 @@ Binds keys for the taskview. Works like the \f(CW\*(C`map\*(C'\fR command. .IP "touch \fIfilename\fR" 2 .IX Item "touch filename" Creates an empty file with the name \fIfilename\fR, unless it already exists. +.IP "travel \fIpattern\fR" 2 +.IX Item "travel pattern" +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 \s-1ESC\s0 or execute a file. .IP "tunmap [\fIkeys ...\fR]" 2 .IX Item "tunmap [keys ...]" Removes key mappings of the taskview. Works like the \f(CW\*(C`unmap\*(C'\fR command. @@ -1037,7 +1043,7 @@ program out of \*(L"vim\*(R", \*(L"emacs\*(R" and \*(L"nano\*(R". .IP "\s-1SHELL\s0" 8 .IX Item "SHELL" Defines the shell that ranger is going to use with the :shell command and -the \*(L"S\*(R" key. Defaults to \*(L"bash\*(R". +the \*(L"S\*(R" key. Defaults to \*(L"/bin/sh\*(R". .IP "\s-1TERMCMD\s0" 8 .IX Item "TERMCMD" Defines the terminal emulator command that ranger is going to use with the diff --git a/doc/ranger.pod b/doc/ranger.pod index 246dd4ab..1d9c022d 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -7,10 +7,12 @@ ranger - visual file manager =head1 SYNOPSIS -B<ranger> [B<--help>] [B<--version>] [B<--debug>] [B<--clean>] -[B<--list-unused-keys>] [B<--fail-unless-cd>] [B<--choosedir>=I<targetfile>] -[B<--choosefile>=I<targetfile>] [B<--copy-config>=I<file>] [B<--mode>=I<mode>] -[B<--flags>=I<flags>] [I<path/filename>] +B<ranger> [B<--version>] [B<--help>] [B<--debug>] [B<--clean>] +[B<--confdir>=I<directory>] [B<--copy-config>=I<which>] +[B<--choosefile>=I<target>] [B<--choosefiles>=I<target>] +[B<--choosedir>=I<target>] [B<--selectfile>=I<filepath>] +[B<--list-unused-keys>] [B<--list-tagged-files>=I<tag>] +[B<--profile>] [B<--cmd>=I<command>] [I<path>] @@ -50,6 +52,16 @@ Activate the clean mode: ranger will not access or create any configuration files nor will it leave any traces on your system. This is useful when your configuration is broken, when you want to avoid clutter, etc. +=item B<-r> I<dir>, B<--confdir>=I<dir> + +Change the configuration directory of ranger from ~/.config/ranger to "dir". + +=item B<--copy-config>=I<file> + +Create copies of the default configuration files in your local configuration +directory. Existing ones will not be overwritten. Possible values: I<all>, +I<rc>, I<commands>, I<scope>. + =item B<--choosefile>=I<targetfile> Allows you to pick a file with ranger. This changes the behavior so that when @@ -71,12 +83,6 @@ write the last visited directory into I<targetfile>. Open ranger with I<targetfile> selected. -=item B<--copy-config>=I<file> - -Create copies of the default configuration files in your local configuration -directory. Existing ones will not be overwritten. Possible values: I<all>, -I<rc>, I<commands>, I<scope>. - =item B<--list-unused-keys> List common keys which are not bound to any action in the "browser" context. @@ -88,21 +94,9 @@ use the key code returned by C<getch()>. List all files which are tagged with the given tag. Note: Tags are single characters. The default tag is "*" -=item B<--fail-unless-cd> - -Return the exit code 1 if ranger is used to run a file instead of used for file -browsing. (For example, "ranger --fail-unless-cd test.txt" returns 1.) - -=item B<-m> I<n>, B<--mode>=I<n> +=item B<--profile> -When a filename is supplied, run it in mode I<n>. This has no effect unless -the execution of this file type is explicitly handled in the configuration. - -=item B<-f> I<flags>, B<--flags>=I<flags> - -When a filename is supplied, run it with the given I<flags> to modify -behavior. The execution of this file type is explicitly handled in the -configuration. +Print statistics of CPU usage on exit. =item B<--cmd>=I<command> @@ -618,6 +612,10 @@ Preview directories in the preview column? Preview files in the preview column? +=item preview_images [bool] + +Draw images inside the console with the external program w3mimgpreview? + =item preview_script [string, none] Which script should handle generating previews? If the file doesn't exist, or @@ -668,7 +666,12 @@ Reverse the order of files? Which sorting mechanism should be used? Choose one of B<atime>, B<basename>, B<ctime>, B<mtime>, B<natural>, B<type>, B<size> -Note: You can reverse the order by using an uppercase O in the key combination. +Note: You can reverse the order by typing an uppercase second letter in the key +combination, e.g. "oN" to sort from Z to A. + +=item status_bar_on_top [bool] + +Put the status bar at the top of the window? =item tilde_in_titlebar [bool] @@ -729,7 +732,7 @@ ranger. For your convenience, this is a list of the "public" commands including copypmap key newkey [newkey2...] copytmap key newkey [newkey2...] cunmap keys... - delete [confirmation] + delete edit [filename] eval [-q] python_code filter [string] @@ -756,6 +759,7 @@ ranger. For your convenience, this is a list of the "public" commands including terminal tmap key command touch filename + travel pattern tunmap keys... unmap keys... unmark pattern @@ -801,9 +805,9 @@ the user, the group and others. A 1 permits execution, a 2 permits writing, a 4 permits reading. Add those numbers to combine them. So a 7 permits everything. -Key bindings in the form of [-+]<who><what> and =<octal> also exist. For +Key bindings in the form of [-+]<who><what> and <octal>= also exist. For example, B<+ar> allows reading for everyone, -ow forbids others to write and -=777 allows everything. +777= allows everything. See also: man 1 chmod @@ -841,14 +845,11 @@ See C<copymap> Removes key mappings of the console. Works like the C<unmap> command. -=item delete [I<confirmation>] +=item delete Destroy all files in the selection with a roundhouse kick. ranger will ask for a confirmation if you attempt to delete multiple (marked) files or non-empty -directories. - -When asking for confirmation, this command will only proceed if the last given -word starts with a `y'. +directories. This can be changed by modifying the setting "confirm_on_delete". =item edit [I<filename>] @@ -872,9 +873,9 @@ this command without any parameter will reset the fitler. =item find I<pattern> -Search files in the current directory that match the given (case-insensitive) -regular expression pattern as you type. Once there is an unambiguous result, -it will be run immediately. (Or entered, if it's a directory.) +Search files in the current directory that contain the given (case-insensitive) +string in their name as you type. Once there is an unambiguous result, it will +be run immediately. (Or entered, if it's a directory.) =item grep I<pattern> @@ -912,9 +913,8 @@ Creates a directory with the name I<dirname>. =item open_with [I<application>] [I<flags>] [I<mode>] Open the selected files with the given application, unless it is omitted, in -which case the default application is used. I<flags> are characters out of -"sdpcwSDPCW" and I<mode> is any positive integer. Their meanings are discussed -in their own sections. +which case the default application is used. I<flags> and I<mode> have their +own section in the man page. =item pmap I<key> I<command> @@ -945,7 +945,7 @@ will fail. Also try the key binding A for appending something to a file name. =item save_copy_buffer -Save the copy buffer from I<~/.config/ranger/copy_buffer>. This can be used to +Save the copy buffer to I<~/.config/ranger/copy_buffer>. This can be used to pass the list of copied files to another ranger instance. =item search I<pattern> @@ -995,6 +995,14 @@ Binds keys for the taskview. Works like the C<map> command. Creates an empty file with the name I<filename>, unless it already exists. +=item travel I<pattern> + +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. + =item tunmap [I<keys ...>] Removes key mappings of the taskview. Works like the C<unmap> command. @@ -1121,7 +1129,7 @@ program out of "vim", "emacs" and "nano". =item SHELL Defines the shell that ranger is going to use with the :shell command and -the "S" key. Defaults to "bash". +the "S" key. Defaults to "/bin/sh". =item TERMCMD diff --git a/examples/rifle_sxiv.sh b/examples/rifle_sxiv.sh index efa935b2..0cbda01e 100755 --- a/examples/rifle_sxiv.sh +++ b/examples/rifle_sxiv.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # # This script searches image files in a directory, opens them all with sxiv # and sets the first argument to the first image displayed by sxiv. @@ -11,12 +11,19 @@ # [ "$1" == '--' ] && shift -target="$(realpath -s "$1")" + +function abspath { + case "$1" in + /*) printf "%s\n" "$1";; + *) printf "%s\n" "$PWD/$1";; + esac +} function listfiles { find -L "$(dirname "$target")" -maxdepth 1 -type f -iregex \ '.*\(jpe?g\|bmp\|png\|gif\)$' -print0 | sort -z } +target="$(abspath $1)" count="$(listfiles | grep -m 1 -Zznx "$target" | cut -d: -f1)" if [ -n "$count" ]; then 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 |