about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2019-08-03 00:29:10 +0200
committertoonn <toonn@toonn.io>2019-08-03 00:29:10 +0200
commit498ac4ffa7b90d385de6078a9162606a6bc524c3 (patch)
treedbd31fc46f55caafe5670944fb7aebe661a79a5d
parent6fee63a8d7f91a91ffa2b785e67f4d418055bd98 (diff)
downloadranger-498ac4ffa7b90d385de6078a9162606a6bc524c3.tar.gz
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
-rw-r--r--examples/rc_emacs.conf5
-rw-r--r--ranger/config/rc.conf5
-rw-r--r--ranger/container/settings.py3
-rw-r--r--ranger/core/main.py10
4 files changed, 23 insertions, 0 deletions
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