From 23b7f16961a7b679dec16f6ee91401a6b8f6ca82 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 5 Mar 2012 11:27:16 +0100 Subject: Added $RANGER_LEVEL environment variable (see man page) --- doc/ranger.1 | 13 +++++++++++++ doc/ranger.pod | 13 +++++++++++++ ranger/core/main.py | 7 +++++++ 3 files changed, 33 insertions(+) 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 ". .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 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 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' -- cgit 1.4.1-2-gfad0