Skip to content

RANGER_LEVEL not available in fish #1574

Closed

Description

@donatellaq

When I invoke a shell from ranger, the environment variable RANGER_LEVEL can be used to detect that ranger is the parent process. However, it seems that it doesn't work with fish.

Activity

  1. zanchey commented on Jul 23, 2014

    @zanchey
    Member

    When you say that it is not available, do you mean that it does not appear in the output of set?

  2. donatellaq commented on Jul 23, 2014

    @donatellaq
    Author

    I've found the MANPATH example here. Thus, I tried

    test -n $RANGER_LEVEL
    

    which didn't work.

    But you're right. It can be found with the set command. So I can use

    set | grep "^RANGER_LEVEL"
    

    Or what would be the current method?
    Thank you so far
    Donatella

  3. ridiculousfish commented on Jul 23, 2014

    @ridiculousfish
    Member

    The most canonical way would be:

    if set -q -x RANGER_LEVEL
        # It's set as an environment variable
    end
    

    Can you please explain "didn't work?" What did you see and what did you expect to see instead?

  4. donatellaq commented on Jul 23, 2014

    @donatellaq
    Author

    That's it.

    To answer your question:
    test -n $RANGER_LEVEL is always true. It doesn't matter whether the shell was spawned by ranger or not. But the example mentioned above says:

    If the variable MANPATH is defined and not empty, print the contents:
    
    if test -n $MANPATH
        echo $MANPATH
    end
    

    It's obviously essential that the variable is defined. I expected test -n would be false if not.
    Anyway, my problem has been solved. The thread can be closed. Thanks for the quick answer.

  5. ridiculousfish commented on Jul 23, 2014

    @ridiculousfish
    Member

    Oh, I get it. This is the nasty case where an undefined variable expands into zero arguments, i.e. test -n, and then the POSIX requirements on test require it to return true because it was passed exactly one argument. The example from the docs should really read test -n "$MANPATH".

  6. ridiculousfish commented on Jul 23, 2014

    @ridiculousfish
    Member

    Let's leave this open to track updating the example from the docs.

  7. donatellaq commented on Jul 24, 2014

    @donatellaq
    Author

    Thanks for the explanation. I understand now, why test -n behaves how it does. By the way, it's even more confusing in zsh:

    test -n $UNDEFINED_VARIABLE -> true
    test -z $UNDEFINED_VARIABLE -> true
    [[ -n $UNDEFINED_VARIABLE ]] -> false
    [[ -z $UNDEFINED_VARIABLE ]] -> true
    

    But now it becomes off topic.

  8. removed
    docs
    on Apr 27, 2015
  9. added this to the milestone on Jul 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions