ranger / ranger

A VIM-inspired filemanager for the console
https://ranger.fm
GNU General Public License v3.0
15.54k stars 892 forks source link

Save/restore different ranger sessions #941

Open tigerjack opened 7 years ago

tigerjack commented 7 years ago

ISSUE TYPE

RUNTIME ENVIRONMENT

>uname -a
Linux myarch 4.12.10-1-ARCH 
>ranger --version
ranger version: ranger-master 1.9.0b5
Python version: 3.6.2 (default, Jul 20 2017, 03:52:27) [GCC 7.1.1 20170630]
Locale: en_GB.UTF-8

EXPECTED BEHAVIOR

It could be useful to have a command to store the current opened tabs (the current ranger session) and to restore them later on. It could also be great to store them using a name, pretty much like tmux sessions. The aim is to have multiple sessions saved using different names and restore them at a later moment.

CURRENT BEHAVIOR

At the moment I can only save/restore one session at a time using F10.

CONTEXT

This could be useful for example when you have multiple ranger sessions. F.e. I can have different ranger sessions opened to manage different projects and I don't want to lose all the active tabs after a system reboot .

POSSIBLE SOLUTIONS

Maybe a file containing the working directories of each named session is enough. Ideally you have to press a key binding or execute a command to save the current session using a name. Later on, you can press another key binding to see the list of available sessions and restore one of them.

vimeitor commented 6 years ago

I assume you have tried save_tabs_on_exit and you didn't like it?

tigerjack commented 6 years ago

Yep. Apart from the bug I've already posted https://github.com/ranger/ranger/issues/883, it only works with one session at a time. It could be useful to have different sessions. Imagine as use case having multiple directories related to a specific project that I want to save/restore. Imagine now I'm working on different projects at a time. It could be great to me to have this kind of feature.

SpiroCx commented 2 years ago

This is working well for me.

  1. Create sessions file ~/.local/share/ranger/sessions with entries format: name:paths, eg:

    util2:~/_util ~/_util
    home2:~ ~
  2. Create some aliases to use this file:

    
    alias rf='echo ranger $(cat ~/.local/share/ranger/sessions | fzy | cut -d ":" -f 2) >/tmp/rlaunch && source /tmp/rlaunch'
    alias rfn='echo ranger $(grep $(cat ~/.local/share/ranger/sessions | cut -d ":" -f 1 | fzy) ~/.local/share/ranger/sessions | cut -d ":" -f 2) >/tmp/rlaunch && source /tmp/rlaunch'
    alias rr='rs $(tmux display -pt "${TMUX_PANE:?}" "#{window_name}")'

uncomment only one of these

zsh:

function rs() { echo ranger $(grep $*: ~/.local/share/ranger/sessions | cut -d ":" -f 2) >/tmp/rlaunch && source /tmp/rlaunch }

bash:

rs() { echo ranger $(grep $*: ~/.local/share/ranger/sessions | cut -d ":" -f 2) >/tmp/rlaunch && source /tmp/rlaunch; }



3.  Use them like this:
rf - select session from fzy list, showing names + paths
rfn - select session from fzy list, showing names only
rr - launch session with same name as tmux tab
rs name - launch session "**name**"