Open knodalyte opened 1 year ago
Hi @knodalyte!
I guess it's possible, everything is it, by I'm not sure about the implementation details. For the time being, the first thing coming to my mind is a plugin: nnn has a plugin for several dir jumpers (including zoxide), which I think could be easily adapted to clifm.
Let me take a look at it. I will try the plugin approach first.
#!/bin/sh
# Description: Jump to visited directories using external directory jumpers
# Author: L. Abramovich
# License: GPL3
#
# Dependencies: zoxide
if type zoxide >/dev/null 2>&1; then
if type fzf >/dev/null 2>&1; then
dir="$(zoxide query -i -- "$@")"
else
dir="$(zoxide query -- "$@")"
fi
[ -n "$dir" ] && echo "$dir" > "$CLIFM_BUS"
fi
exit 0
Hey @knodalyte, here's the first version of the plugin, for the time being supporting only zoxide
.
Here's how to install the plugin:
$HOME/.config/clifm/plugins/autojump.sh
.actions edit
and then add this line: z=autojump.sh
. Save and exit the editor.z
(plus any desired query). Example: z mydir
.This method has a few drawbacks however:
j
command, neither TAB completion nor autosuggestions are available. zoxide
remains basically frozen while running in clifm: no new directories will be added and scores will be left untouched.As a workaround for the second point, and I'm just thinking aloud, clifm's prompt commands might be used to update the zoxide database (using the zoxide add
command) every time you change directories. I will explore this option and let you know.
UPDATE It works!
To keep the zoxide database up to date, add this prompt command to clifm's main config file (config
or F10):
promptcmd zoxide add -- "$PWD"
NOTE: This is exactly the same thing zoxide
does natively: it adds a zoxide add
command to bash's PROMPT_COMMAND, which is executed immediately before each new prompt, to add new directories to its database.
UPDATE 2
There's still one thing that needs to be figured out: when running on a regular shell, zoxide
keeps track of the last added directory to prevent adding it once and again whenever you issue a command (or just press Enter), generating thus a new prompt, but not changing the current directory. In this case, zoxide
won't add anything to its database.
UPDATE 3
To avoid adding the current directory once and again, replace the above promptcmd line
promptcmd zoxide add -- "$PWD"
by this one:
promptcmd [ "$(cat /tmp/z_oldpwd)" != "$PWD" ] && zoxide add -- "$PWD" && echo "$PWD" > /tmp/z_oldpwd
Sadly, we need to store the last added directory in a file (plus a command call: cat
), which is sub-optimal. But, it basically works.
Thank you for a quick solution!
As you pointed out, this more or less works, but it's the parts that don't work that provide most of the utility of zoxide.
I think I had unrealistic expectations about the extent the clifm command line would function like a commandline outside of clifm. Of course, the overhead of popping in and out of clifm is low enough that jumping back and forth is probably the best solution.
On a separate but related note, I would have expected that using the ; command would allow me to use shell functions like zoxide, so if my command was something like ;z proj but instead clifm tells me "sh: 1: z: not found".
Thanks for you feedback @knodalyte!
As to the ;
command, it will run whatever is in your PATH, preventing clifm from making built-in expansions. But shell functions, as far as I know, are not accessible outside the corresponding shell, not even from within a program launched from the shell itself (there's always a way though).
However, trying to make zoxide
work within clifm (at least partially) totally worth it: it's useful for me to push clifm's capabilities to its limits, becoming aware thus about what it can do (even when I never thought about it), and what it cannot (at least now).
I think I will keep working on this plugin: it at least provides a nice integration with zoxide
(as a viable alternative to the built-in j
command), which I'm sure can also be achieved for other dir jumpers too.
Btw, which are exactly those parts that don't work? Are you referring to autosuggestions and TAB completion, or is it something else?
Yes, exactly, as you pointed out, they are suggestions and tab completion.
I also found an old utility, xd, that is supposed to provide a quick way to change directories, you might want to see if it has any useful ideas for clifm.
Is your feature request related to a problem? Please describe. Is is possible to either set something in the config file(s) or modify how clifm interoperates with my shell (zsh in my case) so that I can use shell functions from within clifm? For example, I would prefer to use zoxide to change directories in both zsh and in clifm, so that I don't have separate directory histories in each.
Describe the solution you'd like For example, having configured zoxide in my .zshrc, in clifm I could use the z command to change directories, similar to using the existing clifm j command.
Describe alternatives you've considered Use z in shell and j in clifm
Additional context If this can be supported, I suspect other shell functions will be usable (nothing in mind right now...)