From 498ac4ffa7b90d385de6078a9162606a6bc524c3 Mon Sep 17 00:00:00 2001 From: toonn Date: Sat, 3 Aug 2019 00:29:10 +0200 Subject: Warn when nesting ranger Users frequently request that launching ranger in a subshell started from ranger (using `S`) instead exits the subshell so they end up in their original ranger instance without nesting, which is rarely useful. This isn't possible because a process can't easily kill its parent shell. To at least avoid such confusion we warn about nesting by default. A new setting `nested_ranger_warning` is added to `rc.conf`. The warning can be either disabled or the severity increased so the message is more visible. Fixes #1645 --- examples/rc_emacs.conf | 5 +++++ ranger/config/rc.conf | 5 +++++ ranger/container/settings.py | 3 +++ ranger/core/main.py | 10 ++++++++++ 4 files changed, 23 insertions(+) diff --git a/examples/rc_emacs.conf b/examples/rc_emacs.conf index 0462282e..a2e81892 100644 --- a/examples/rc_emacs.conf +++ b/examples/rc_emacs.conf @@ -206,6 +206,11 @@ set idle_delay 2000 # check all directories above the current one as well? set metadata_deep_search false +# Warn at startup if RANGER_LEVEL env var is greater than 0, in other words +# give a warning when you nest ranger in a subshell started by ranger. +# Special value "bad" makes the warning more visible. +set nested_ranger_warning true + # =================================================================== # == Local Options # =================================================================== diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index f559290d..70701edf 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -301,6 +301,11 @@ set freeze_files false # Print file sizes in bytes instead of the default human-readable format. set size_in_bytes false +# Warn at startup if RANGER_LEVEL env var is greater than 0, in other words +# give a warning when you nest ranger in a subshell started by ranger. +# Special value "bad" makes the warning more visible. +set nested_ranger_warning true + # =================================================================== # == Local Options # =================================================================== diff --git a/ranger/container/settings.py b/ranger/container/settings.py index 478f6124..58e9df2e 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -58,6 +58,7 @@ ALLOWED_SETTINGS = { 'max_history_size': (int, type(None)), 'metadata_deep_search': bool, 'mouse_enabled': bool, + 'nested_ranger_warning': str, 'one_indexed': bool, 'open_all_images': bool, 'padding_right': bool, @@ -105,6 +106,8 @@ ALLOWED_VALUES = { 'confirm_on_delete': ['multiple', 'always', 'never'], 'draw_borders': ['none', 'both', 'outline', 'separators'], 'line_numbers': ['false', 'absolute', 'relative'], + 'nested_ranger_warning': ['true', 'false', 'yes', 'no', 'enabled', + 'disabled', 'bad'], 'one_indexed': [False, True], 'preview_images_method': ['w3m', 'iterm2', 'terminology', 'urxvt', 'urxvt-full', 'kitty', diff --git a/ranger/core/main.py b/ranger/core/main.py index 23648677..bc0b742a 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -180,6 +180,16 @@ def main( for command in args.cmd: fm.execute_console(command) + if int(os.environ[level]) > 1: + warning = 'Warning:' + nested_warning = "You're in a nested ranger instance!" + nrw = fm.settings.nested_ranger_warning.lower() + if nrw in ['true', 'yes', 'enabled']: + fm.notify(' '.join((warning, nested_warning)), bad=False) + elif nrw == 'bad': + fm.notify(' '.join((warning.upper(), nested_warning + '!!')), + bad=True) + if ranger.args.profile: import cProfile import pstats -- cgit 1.4.1-2-gfad0 From 9511bd6e6b0d8a3e8ce04b723cf4903b81db1b61 Mon Sep 17 00:00:00 2001 From: Toon Nolten Date: Sun, 18 Aug 2019 15:05:08 +0200 Subject: Drop truth values; rename warning setting --- doc/ranger.1 | 29 ++++++++++++++++++----------- doc/ranger.pod | 8 ++++++++ examples/rc_emacs.conf | 2 +- ranger/config/rc.conf | 2 +- ranger/container/settings.py | 3 +-- ranger/core/main.py | 6 +++--- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/doc/ranger.1 b/doc/ranger.1 index bccbfa98..af13e690 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 4.11 (Pod::Simple 3.35) +.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== @@ -46,7 +46,7 @@ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" -.\" If the F register is >0, we'll generate index entries on stderr for +.\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. @@ -56,12 +56,12 @@ .. .nr rF 0 .if \n(.g .if rF .nr rF 1 -.if (\n(rF:(\n(.g==0)) \{\ -. if \nF \{\ +.if (\n(rF:(\n(.g==0)) \{ +. if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. -. if !\nF==2 \{\ +. if !\nF==2 \{ . nr % 0 . nr F 2 . \} @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.9.2" "25/07/19" "ranger manual" +.TH RANGER 1 "ranger-1.9.2" "18-08-2019" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -173,7 +173,7 @@ plugins, sample configuration files and some programs for integrating ranger with other software. They are usually installed to \&\fI/usr/share/doc/ranger/examples\fR. .PP -The man page of \fBrifle\fR\|(1) describes the functions of the file opener +The man page of \fIrifle\fR\|(1) describes the functions of the file opener .PP The section \fI\s-1LINKS\s0\fR of this man page contains further resources. .SH "POSITIONAL ARGUMENTS" @@ -342,7 +342,7 @@ To enable this feature, set the option \f(CW\*(C`preview_images_method\*(C'\fR t \fIkitty\fR .IX Subsection "kitty" .PP -This only works on Kitty. It requires \s-1PIL\s0 (or pillow) to work. +This only works on Kitty. It requires \s-1PIL \s0(or pillow) to work. Allows remote image previews, for example in an ssh session. .PP To enable this feature, set the option \f(CW\*(C`preview_images_method\*(C'\fR to kitty. @@ -666,7 +666,7 @@ Toggle the mark-status of all files .IP "V" 14 .IX Item "V" Starts the visual mode, which selects all files between the starting point and -the cursor until you press \s-1ESC.\s0 To unselect files in the same way, use \*(L"uV\*(R". +the cursor until you press \s-1ESC. \s0 To unselect files in the same way, use \*(L"uV\*(R". .IP "/" 14 Search for files in the current directory. .IP ":" 14 @@ -971,6 +971,13 @@ all directories above the current one as well? .IP "mouse_enabled [bool] " 4 .IX Item "mouse_enabled [bool] " Enable mouse input? +.IP "nested_ranger_warning [string]" 4 +.IX Item "nested_ranger_warning [string]" +Warn at startup if \f(CW\*(C`RANGER_LEVEL\*(C'\fR is greater than 0, in other words give a +warning when you nest ranger in a subshell started by ranger. Allowed values +are \f(CW\*(C`true\*(C'\fR, \f(CW\*(C`false\*(C'\fR and \f(CW\*(C`error\*(C'\fR. The special value \f(CW\*(C`error\*(C'\fR promotes the +warning to an error, this is usually shown as red text but will crash ranger +when run with the \f(CW\*(C`\-\-debug\*(C'\fR flag. .IP "one_indexed [bool]" 4 .IX Item "one_indexed [bool]" Start line numbers from 1. Possible values are: @@ -1684,7 +1691,7 @@ Specifies the theme to be used for syntax highlighting when \fIpygmentize\fR is installed, unless \fIhighlight\fR is also installed. Find out possible values by running: python \-c 'import pygments.styles; [print(stl) for stl in - pygments.styles.\fBget_all_styles()\fR]' + pygments.styles.\fIget_all_styles()\fR]' .IP "\s-1HIGHLIGHT_STYLE\s0" 8 .IX Item "HIGHLIGHT_STYLE" Specifies the theme to be used for syntax highlighting when \fIhighlight\fR is @@ -1743,7 +1750,7 @@ copy, run: .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" -\&\fBrifle\fR\|(1) +\&\fIrifle\fR\|(1) .SH "BUGS" .IX Header "BUGS" Report bugs here: diff --git a/doc/ranger.pod b/doc/ranger.pod index 0fd5cc47..4b44fc92 100644 --- a/doc/ranger.pod +++ b/doc/ranger.pod @@ -985,6 +985,14 @@ all directories above the current one as well? Enable mouse input? +=item nested_ranger_warning [string] + +Warn at startup if C is greater than 0, in other words give a +warning when you nest ranger in a subshell started by ranger. Allowed values +are C, C and C. The special value C promotes the +warning to an error, this is usually shown as red text but will crash ranger +when run with the C<--debug> flag. + =item one_indexed [bool] Start line numbers from 1. Possible values are: diff --git a/examples/rc_emacs.conf b/examples/rc_emacs.conf index a2e81892..e3596ba5 100644 --- a/examples/rc_emacs.conf +++ b/examples/rc_emacs.conf @@ -208,7 +208,7 @@ set metadata_deep_search false # Warn at startup if RANGER_LEVEL env var is greater than 0, in other words # give a warning when you nest ranger in a subshell started by ranger. -# Special value "bad" makes the warning more visible. +# Special value "error" makes the warning more visible. set nested_ranger_warning true # =================================================================== diff --git a/ranger/config/rc.conf b/ranger/config/rc.conf index 70701edf..00a20def 100644 --- a/ranger/config/rc.conf +++ b/ranger/config/rc.conf @@ -303,7 +303,7 @@ set size_in_bytes false # Warn at startup if RANGER_LEVEL env var is greater than 0, in other words # give a warning when you nest ranger in a subshell started by ranger. -# Special value "bad" makes the warning more visible. +# Special value "error" makes the warning more visible. set nested_ranger_warning true # =================================================================== diff --git a/ranger/container/settings.py b/ranger/container/settings.py index 58e9df2e..0b098659 100644 --- a/ranger/container/settings.py +++ b/ranger/container/settings.py @@ -106,8 +106,7 @@ ALLOWED_VALUES = { 'confirm_on_delete': ['multiple', 'always', 'never'], 'draw_borders': ['none', 'both', 'outline', 'separators'], 'line_numbers': ['false', 'absolute', 'relative'], - 'nested_ranger_warning': ['true', 'false', 'yes', 'no', 'enabled', - 'disabled', 'bad'], + 'nested_ranger_warning': ['true', 'false', 'error'], 'one_indexed': [False, True], 'preview_images_method': ['w3m', 'iterm2', 'terminology', 'urxvt', 'urxvt-full', 'kitty', diff --git a/ranger/core/main.py b/ranger/core/main.py index bc0b742a..aefaacbc 100644 --- a/ranger/core/main.py +++ b/ranger/core/main.py @@ -183,10 +183,10 @@ def main( if int(os.environ[level]) > 1: warning = 'Warning:' nested_warning = "You're in a nested ranger instance!" - nrw = fm.settings.nested_ranger_warning.lower() - if nrw in ['true', 'yes', 'enabled']: + warn_when_nested = fm.settings.nested_ranger_warning.lower() + if warn_when_nested == 'true': fm.notify(' '.join((warning, nested_warning)), bad=False) - elif nrw == 'bad': + elif warn_when_nested == 'error': fm.notify(' '.join((warning.upper(), nested_warning + '!!')), bad=True) -- cgit 1.4.1-2-gfad0 From 3c2f560bfafb41a85955cd2475915f24ed325b49 Mon Sep 17 00:00:00 2001 From: Wojciech Siewierski Date: Sun, 18 Aug 2019 15:22:52 +0200 Subject: Regenerate the manpages --- doc/ranger.1 | 22 +++++++++++----------- doc/rifle.1 | 22 +++++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/doc/ranger.1 b/doc/ranger.1 index af13e690..f209f5fa 100644 --- a/doc/ranger.1 +++ b/doc/ranger.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 2.27 (Pod::Simple 3.28) +.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== @@ -46,7 +46,7 @@ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" -.\" If the F register is turned on, we'll generate index entries on stderr for +.\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. @@ -56,12 +56,12 @@ .. .nr rF 0 .if \n(.g .if rF .nr rF 1 -.if (\n(rF:(\n(.g==0)) \{ -. if \nF \{ +.if (\n(rF:(\n(.g==0)) \{\ +. if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. -. if !\nF==2 \{ +. if !\nF==2 \{\ . nr % 0 . nr F 2 . \} @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "RANGER 1" -.TH RANGER 1 "ranger-1.9.2" "18-08-2019" "ranger manual" +.TH RANGER 1 "ranger-1.9.2" "08/18/2019" "ranger manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -173,7 +173,7 @@ plugins, sample configuration files and some programs for integrating ranger with other software. They are usually installed to \&\fI/usr/share/doc/ranger/examples\fR. .PP -The man page of \fIrifle\fR\|(1) describes the functions of the file opener +The man page of \fBrifle\fR\|(1) describes the functions of the file opener .PP The section \fI\s-1LINKS\s0\fR of this man page contains further resources. .SH "POSITIONAL ARGUMENTS" @@ -342,7 +342,7 @@ To enable this feature, set the option \f(CW\*(C`preview_images_method\*(C'\fR t \fIkitty\fR .IX Subsection "kitty" .PP -This only works on Kitty. It requires \s-1PIL \s0(or pillow) to work. +This only works on Kitty. It requires \s-1PIL\s0 (or pillow) to work. Allows remote image previews, for example in an ssh session. .PP To enable this feature, set the option \f(CW\*(C`preview_images_method\*(C'\fR to kitty. @@ -666,7 +666,7 @@ Toggle the mark-status of all files .IP "V" 14 .IX Item "V" Starts the visual mode, which selects all files between the starting point and -the cursor until you press \s-1ESC. \s0 To unselect files in the same way, use \*(L"uV\*(R". +the cursor until you press \s-1ESC.\s0 To unselect files in the same way, use \*(L"uV\*(R". .IP "/" 14 Search for files in the current directory. .IP ":" 14 @@ -1691,7 +1691,7 @@ Specifies the theme to be used for syntax highlighting when \fIpygmentize\fR is installed, unless \fIhighlight\fR is also installed. Find out possible values by running: python \-c 'import pygments.styles; [print(stl) for stl in - pygments.styles.\fIget_all_styles()\fR]' + pygments.styles.\fBget_all_styles()\fR]' .IP "\s-1HIGHLIGHT_STYLE\s0" 8 .IX Item "HIGHLIGHT_STYLE" Specifies the theme to be used for syntax highlighting when \fIhighlight\fR is @@ -1750,7 +1750,7 @@ copy, run: .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" -\&\fIrifle\fR\|(1) +\&\fBrifle\fR\|(1) .SH "BUGS" .IX Header "BUGS" Report bugs here: diff --git a/doc/rifle.1 b/doc/rifle.1 index a42734d2..114cc5d0 100644 --- a/doc/rifle.1 +++ b/doc/rifle.1 @@ -1,4 +1,4 @@ -.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) +.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== @@ -54,16 +54,20 @@ .\" Avoid warning from groff about undefined register 'F'. .de IX .. -.if !\nF .nr F 0 -.if \nF>0 \{\ -. de IX -. tm Index:\\$1\t\\n%\t"\\$2" +.nr rF 0 +.if \n(.g .if rF .nr rF 1 +.if (\n(rF:(\n(.g==0)) \{\ +. if \nF \{\ +. de IX +. tm Index:\\$1\t\\n%\t"\\$2" .. -. if !\nF==2 \{\ -. nr % 0 -. nr F 2 +. if !\nF==2 \{\ +. nr % 0 +. nr F 2 +. \} . \} .\} +.rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. @@ -129,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "RIFLE 1" -.TH RIFLE 1 "rifle-1.9.2" "2019-04-03" "rifle manual" +.TH RIFLE 1 "rifle-1.9.2" "08/18/2019" "rifle manual" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l -- cgit 1.4.1-2-gfad0 e>
1
2
3
4
5