Ranger file manager: what do gl and gL do?

In ~/.config/ranger/rc.conf there’s a section on shortcuts with straightforward mappings like map gh cd ~ and map ge cd /etc but there are also

map gl cd -r .
map gL cd -r %f

I can’t figure out what gl and gL do. (cd --help) doesn’t have cd -r.)

See

man ranger

near the bottom KEY BINDINGS section, i suspect that gl gL are ranger specific

1 Like

3 Likes

@keybreak and @Stagger_Lee
thanks for helping but I’m still unsure about the role of those mappings. So I’ll leave them alone for now.

Meanwhile, there’s gotbletu who’s done quite a few videos on Ranger :+1:

1 Like

According to a dev over at the Ranger subreddit:

… These are not to be confused with the shell’s cd command. This is about ranger’s :cd command. Looking at the documentation for :cd with ?c, the -r flag forces a “real” path. So IIUC it expands symlinks. The first mapping would change ranger’s directory to the symlink-resolved path of the current directory, the second mapping would move into the highlighted directory after it is symlink-resolved.

So if I type gL when a file which is a symlink is highlighted, I’m moved to the folder containing the original file and the original file is now highlighted.

I still don’t understand what gl does. Baby steps.

2 Likes
map gl cd -r .

This doesn’t make sense to me.

But in this regard, I never understood the utility of the single dot referencing the current directory in unix system.

.
..
1 Like

I’m going through this Ranger thread, presently 85 pages long, in the hope of finding an answer and any other useful hints.

The changelog indicates that gl and gL were introduced in v1.2.0 with this mention:

  • Added keys: gl and gL to resolve links, see 11?

Well, playing around in ranger, it seems that gl and gL does the same thing except gL select the original file that was selected in the simlinked directory while gl resolves the simlink but does not highlight the file you selected.

ex: while selecting the directory /lib/bash

  • pressing gl redirect you to /usr/lib/ but does not select the directory bash necessarily.
    (the selection depends on your browsing history)
  • pressing gL WILL select /usr/lib/bash.
1 Like

I use it quite a bit on my headless enos server to copy files from a USB thumb drive.

Cd to an existing directory where you want to copy the file to
Then mount the USB Thumb drive to /mnt

$ cd ~/username/Temp
$ lsblk -f
$ sudo mount /dev/sda /mnt
$ cp /mnt/somedirectory/somefile .
$ sudo umount /mnt

The . will represent the current working directory for the target directory

Anyway, you can use . to represent the current working directory in various CLI commands.
It it just a shorthand kind of thing that is mostly only useful in a terminal situation.

Also can use … in cd commands

$ cd ..

will move you back one directory towards /

$ cd ../.. 

will move you back two directories towards /

$ cd ../Temp

will move back one directory then switch to directory Temp from there.

One can also use . as part of the full pathname when executing a file that is not in the $PATH.
As long as you are in the directory containing the app
$ ./somescript
So this will execute somescript in the current working directory.

Pudge

EDIT:
For those who learn best by doing, like myself, here is a follow along tutorial on a few bash commands;

3 Likes

Taken from ranger help’s [c]ommands.

:cd [-r] <path>
The cd command changes the directory.
If the path is a file, selects that file.
The command 'cd -' is equivalent to typing ``.
Using the option "-r" will get you to the real path.

So imagine that you go through a symlink to some directory ~/somelink/workdir which you can see at the top of the screen. You are in that directory and it is referenced by a relative path.
When you use cd -r . it will dereference that to absolute path /somewhere/workdir.
The symlink ~/somelink was pointing to /somewhere.

As @Pudge pointed out . just means this directory I am currently in and %f is in ranger just a placeholder meaning the file my cursor is pointing at.

3 Likes

What bugged me was that just following the simlink would also redirect me to the real path, so I did not understood the need for the command at all. But I have a better understanding of the concept now.

2 Likes

I do not have use for it either. That’s why I remapped it to map gl cd /var/log.

One more use for . is, for example, . .bashrc instead of typing source .bashrc.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.