summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2012-03-05 11:27:16 +0100
committerhut <hut@lavabit.com>2012-03-05 11:38:42 +0100
commit23b7f16961a7b679dec16f6ee91401a6b8f6ca82 (patch)
tree22dae0662d03ce8562159d9196fd8c854d6af009
parent6b1666df4664482644efb270f4e0215b469c8ffc (diff)
downloadranger-23b7f16961a7b679dec16f6ee91401a6b8f6ca82.tar.gz
Added $RANGER_LEVEL environment variable (see man page)
-rw-r--r--doc/ranger.113
-rw-r--r--doc/ranger.pod13
-rw-r--r--ranger/core/main.py7
3 files changed, 33 insertions, 0 deletions
diff --git a/doc/ranger.1 b/doc/ranger.1
index 823b31c7..433bb8a7 100644
--- a/doc/ranger.1
+++ b/doc/ranger.1
@@ -872,6 +872,11 @@ with T.  To assign a named tag, type "<tagname>.
 .SH "ENVIRONMENT"
 .IX Header "ENVIRONMENT"
 These environment variables have an effect on ranger:
+.IP "\s-1RANGER_LEVEL\s0" 8
+.IX Item "RANGER_LEVEL"
+Ranger sets this environment variable to \*(L"1\*(R" or increments it if it already
+exists.  External programs can determine whether they were spawned from ranger
+by checking for this variable.
 .IP "\s-1EDITOR\s0" 8
 .IX Item "EDITOR"
 Defines the editor to be used for the \*(L"E\*(R" key.  Defaults to the first installed
@@ -899,6 +904,14 @@ Using PYTHONOPTIMIZE=2 (like python \-OO) will additionally discard any
 docstrings.  Using this will disable the <F1> key on commands.
 .SH "EXAMPLES"
 .IX Header "EXAMPLES"
+.SS "\s-1BASH:\s0 Display that the shell spawned from ranger:"
+.IX Subsection "BASH: Display that the shell spawned from ranger:"
+By putting this in ~/.bashrc, \*(L"(in ranger) \*(R" will be displayed next to your
+prompt to notify you that the shell spawned from ranger.
+.PP
+.Vb 1
+\& [ \-n "$RANGER_LEVEL" ] && PS1="$PS1"\*(Aq(in ranger) \*(Aq
+.Ve
 .SS "\s-1VIM:\s0 File Chooser"
 .IX Subsection "VIM: File Chooser"
 This is a vim function which allows you to use ranger to select a file for
diff --git a/doc/ranger.pod b/doc/ranger.pod
index e8c45826..9f8b4f04 100644
--- a/doc/ranger.pod
+++ b/doc/ranger.pod
@@ -960,6 +960,12 @@ These environment variables have an effect on ranger:
 
 =over 8
 
+=item RANGER_LEVEL
+
+Ranger sets this environment variable to "1" or increments it if it already
+exists.  External programs can determine whether they were spawned from ranger
+by checking for this variable.
+
 =item EDITOR
 
 Defines the editor to be used for the "E" key.  Defaults to the first installed
@@ -998,6 +1004,13 @@ docstrings.  Using this will disable the <F1> key on commands.
 
 =head1 EXAMPLES
 
+=head2 BASH: Display that the shell spawned from ranger:
+
+By putting this in ~/.bashrc, "(in ranger) " will be displayed next to your
+prompt to notify you that the shell spawned from ranger.
+
+ [ -n "$RANGER_LEVEL" ] && PS1="$PS1"'(in ranger) '
+
 =head2 VIM: File Chooser
 
 This is a vim function which allows you to use ranger to select a file for
diff --git a/ranger/core/main.py b/ranger/core/main.py
index 4bb4c48a..b4629801 100644
--- a/ranger/core/main.py
+++ b/ranger/core/main.py
@@ -38,6 +38,13 @@ def main():
 	except:
 		print("Warning: Unable to set locale.  Expect encoding problems.")
 
+	# so that programs can know that ranger spawned them:
+	level = 'RANGER_LEVEL'
+	if level in os.environ and os.environ[level].isdigit():
+		os.environ[level] = str(int(os.environ[level]) + 1)
+	else:
+		os.environ[level] = '1'
+
 	if not 'SHELL' in os.environ:
 		os.environ['SHELL'] = 'bash'