0

I use ranger as my file-manager and was looking for an option that i can pass to ranger, that let‘s me open ranger in a given directory, something like ranger —specfic-directory=„/home/tim/literature/„ or something alike. Neither ranger —help, nor the manpage offered an answer, at least none that i understood. I can‘t imagine that such an option doesn‘t exist!

4 Answers 4

0

You can just ranger /home/Louis/whatever

This works just fine without any arguments

2
  • Oh that's actually a nice and easy option! I previously went with what @J.Adler suggested, but will use your answer from now on! Thank you!
    – Tim Hilt
    Commented Jan 5, 2019 at 8:11
  • Thank you. But what @J.Adler suggested works also in cases where you need to open a separate window of the terminal with the ranger opening in specific directory. For frequent uses calling without arguments would be easy.
    – neelabalan
    Commented Jan 5, 2019 at 10:20
0

You can execute ranger --cmd='cd ~/Desktop'

1
  • I didn't look at this post for a while and later figured out myself that you are right! It's even written in the man-page! Thanks for your answer!
    – Tim Hilt
    Commented Jan 5, 2019 at 8:12
0

If you want to set default directory each time you open ranger irrespective of the directory in which the terminal opened then,

add this line to you .bashrc or whatever corresponding shell you're using

alias ranger="ranger path/to/your/directory"

0

Open ranger at given directory

I am not the author of this function, I founded several years ago somewhere that I don't remember. put it in your .aliases at your home directory for both zsh or bash or whatever.

##################################################
#       This function is working with ranger
#       using Capital (Q) to exit ranger to
#       the last specified directory in ranger.
##################################################
function ranger-cd {
    local IFS=$'\t\n'
    local tempfile="$(mktemp -t tmp.XXXXXX)"
    local ranger_cmd=(
        command
        ranger
        --cmd="map Q chain shell echo %d > "$tempfile"; quitall"
    )

    ${ranger_cmd[@]} "$@"
    if [[ -f "$tempfile" ]] && [[ "$(cat -- "$tempfile")" != "$(echo -n `pwd`)" ]]; then
        cd -- "$(cat "$tempfile")" || return
    fi
    command rm -f -- "$tempfile" 2>/dev/null
}

alias ranger=ranger-cd

How to use

  • While navigate in ranger, using upper-case (Q) keybinding to exit ranger, and it will exit at the last navigated directory. Notice that alias ranger=ranger-cd is must be also added to your .aliases file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .