|
Maciej Janicki's website |
2019-07-27
shell
fzf
Change to another shell's working directoryToday I’m going to share another trick for changing a shell’s working directory involving the fuzzy finder. Let us assume that you are doing something in a terminal and then need suddenly need another window for working in the same directory. There is an easy way to do this. It involves defining a function, which shows the current directories of all running shells in fzf, so that we can quickly choose one of them and navigate to it. I’ll start by showing the full code of the function. Then, I’ll discuss it command by command. Of course, I refer to the function presented here by a handy alias: Similarly to the function defined in the previous post, also the alias So now let’s have a look at the commands used in the function. This gives us a list of PIDs of all running shell processes. The environment
variable This is the most important line of the function: we use the PID of a shell’s
process to find out its current working directory. Under Linux, this is very
simple: the directory We follow the link using the command Of course we may have multiple shells running with the same current directory. In this case, we don’t want to have multiple identical entries on our list, hence unique sort. Finally, we pipe the list of directories to the fuzzy finder, which presents us with a neat chooser. | |
| Powered by Jekyll. Copyright © Maciej Janicki 2019-2020. Licensed under CC BY. | |