Voidrice: Lf Jump function doesn't work

Created on 25 Oct 2020  路  18Comments  路  Source: LukeSmithxyz/voidrice

Hi. I spent a long time to fix this but it's weird.

In lfrc we have this line

map J $lf -remote "send $id cd $(cut -d'    ' -f2 ${XDG_CONFIG_HOME:-$HOME/.config}/directories | fzf)"

And i don't know if for you it works but for me i get an error saying that the directory doesn't exist. I tried to play with it a bit and got it to work when using full path "/home/user/etc..". But i can't seem to make it work with enviromental variables. Not even with $HOME.

There is a mistake with the cut -d' ' because the delimiter is sometimes one space sometimes two or three so i added a | rev | cut -d' ' -f1 | rev at the end for testing. The main problem is that the cd doesn't work with enviromental variables.

This would be a cool feature to fix. Thanks.

Most helpful comment

Oh looks like it's more common than i thought.

I came to the same conclusion, it's just cd that won't accept the enviromental variables.
I didn't tried eval so I will take a look but I think a cool solution would fix the cd issue, it has to be something external but i don't have any idea what it may be. Do you have artix linux aswell?
I just ignored the enviromental variables and wrote a sed command to replace every XDG or $HOME variable with ~. So it is more of a patch than a real solution.

Here is the sed command if you need it.

sed 's/\${.*\://;s/\-\$HOME/~/;s/$HOME/~/;s/}//'

If you find out anything else write here it would be amazing to fix it. I will open the issue again since there is more people with the problem

Edit: Ohh I forgot, to fix lf only recognizing some lines i made a rev | cut -d | rev. So the complete line looks like this now. I could optimize it a bit changing the first cut -d that really is extra but as it is just temporary screw it.

map J $lf -remote "send $id cd $(cut -d'    ' -f2 ${XDG_CONFIG_HOME:-$HOME/.config}/directories | sed 's/\${.*\://;s/\-\$HOME/~/;s/$HOME/~/;s/}//' | fzf | rev | cut -d' ' -f1 | rev  )"

All 18 comments

I am looking for this fix too. If lf cannot read environmental variables maybe we should substitute ${XDG...:-$HOME/} with ~ via sed for example.

Couldn't you just put double quotes the $() and it would expand it?

I am looking for this fix too. If lf cannot read environmental variables maybe we should substitute ${XDG...:-$HOME/} with ~ via sed for example

It would be cool to get it to work but yes, if there is no other way we will have to do that. I thought that maybe i was missing something obvious with the variables but looks like it just doesn't work. I couldn't find any relevant info on forums either.

Couldn't you just put double quotes the $() and it would expand it?

That was my first idea but it still won't work that way. I don't know why it just won't take enviromental variables when reading them from a file.

Don't know what to say: werks magically on my machine whether the CONFIG directory is assigned or not.

Are your directory names in the directories file separated by a tab or space? This line assumes they are tab separated.

In mine they are separated by spaces, on some lines its one space on others its multiple spaces. I did a temporary fix for that but the main issue is that cd just won't work for xdg variables if they are read from a file, its really weird. Maybe we should port it to use autojump? I don't know if it would be able to read it from a file though. But it's that or implementing the solution katrushenkov posted, just use sed and replacing the Xdg variables with ~, even though it would ruin their purpose and pretty much work as a messy patch.

I'll have to add a comment to the file that the shortcuts must be separated by tabs.

I'm aware of autojump. I might look into it.

Yeah, well for whatever reasons, the variables are indeed being read on my machine.

Had you run LARBS on this machine or is it your own system?
If your own, what's you default user shell? Where do you have environmental variables set?

Toss it in shellcheck

Just tried separate directories with tabs. Unfortunately unsuccessfully.
I have LARBS on this machine.

I'll have to add a comment to the file that the shortcuts must be separated by tabs.

I'm aware of autojump. I might look into it.

Yeah, well for whatever reasons, the variables are indeed being read on my machine.

Had you run LARBS on this machine or is it your own system?
If your own, what's you default user shell? Where do you have environmental variables set?

It is a clean install of LARBS on artix with my dotfiles. So everything should be set just the same. The enviromental variables are set in ~/.profile

Toss it in shellcheck

The code works well, the error is in cd saying that any directory that has XDG in it does not exist when you read it from a file, if you write it by itself in the shell it changes the directory perfectly. It just looks like on luke's machine works and on some others it doesn't.

Are you using zsh?

Yes

Well i made a temporary fix with sed so i will close this for now to avoid making the issue page too long. Looks like this is a rare issue and i didn't found any info about it, so i will just resignate and use it like this. Probably is some misconfig or something dumb. Thank you all for trying.

Same problem here.

Hey, @AlexSyssoyev could you share what solution you found? I spent a couple of hours trying to see what was the issue and didn't get anything. The furthest I got was to make cd expand the variable in the shell (zsh to be specific) thanks to eval. But eval is not recommended to use. Its alternatives are complicated to understand, and anyway I could not get lf to do what it should do since for some reason lf does not recognize eval.

I will try to explain briefly and clearly what I did:

Let's start by reminding us our little script
$lf -remote "send $id cd $(cut -d' ' -f2 ${XDG_CONFIG_HOME:-$HOME/.config}/directories | fzf)"

And this would be my .config/directories:

# You can add comments to these files with #
/home/claudio/.cache
"$HOME/.config"
$HOME/Downloads
    $HOME/Documents
m   ${XDG_MUSIC_DIR:-$HOME/Music}

ps: The only line that always worked was the first one. All the remaining were not understood by lf.

  • At first, I thought it was a problem with fzf that maybe didn't let cd expand the $HOME for some reason but after replacing it with dmenu I realized that this was not the case.
  • Then I thought it might be a problem with 'cut' and started testing with 'cat', more specifically, lf -remote "send $id cd $(cat ${XDG_CONFIG_HOME:-$HOME/.config}/directories | fzf)" but I realized that was not the case either. As always, the only line that understood lf from ~/.config/directories was the first one
  • I decided to try directly with cd and apparently that's the problem. If you try to get cd expand the variable in this one-liner cd $(cat ${XDG_CONFIG_HOME:-$HOME/.config}/directories | fzf) it will not be able to do so. But, if you add eval it certainly will work: eval cd $(cat ${XDG_CONFIG_HOME:-$HOME/.config}/directories | fzf).

So I tried to add eval to lf, but it just doesn't understand it. Something like:

map J $lf -remote "send $id eval cd $(cut -d' ' -f2 ${XDG_CONFIG_HOME:-$HOME/.config}/directories | fzf)"
This only brings an error saying that lf does not recognize the eval command

Also, it seems that using eval brings a security risk, so it's not recommended to use

Oh looks like it's more common than i thought.

I came to the same conclusion, it's just cd that won't accept the enviromental variables.
I didn't tried eval so I will take a look but I think a cool solution would fix the cd issue, it has to be something external but i don't have any idea what it may be. Do you have artix linux aswell?
I just ignored the enviromental variables and wrote a sed command to replace every XDG or $HOME variable with ~. So it is more of a patch than a real solution.

Here is the sed command if you need it.

sed 's/\${.*\://;s/\-\$HOME/~/;s/$HOME/~/;s/}//'

If you find out anything else write here it would be amazing to fix it. I will open the issue again since there is more people with the problem

Edit: Ohh I forgot, to fix lf only recognizing some lines i made a rev | cut -d | rev. So the complete line looks like this now. I could optimize it a bit changing the first cut -d that really is extra but as it is just temporary screw it.

map J $lf -remote "send $id cd $(cut -d'    ' -f2 ${XDG_CONFIG_HOME:-$HOME/.config}/directories | sed 's/\${.*\://;s/\-\$HOME/~/;s/$HOME/~/;s/}//' | fzf | rev | cut -d' ' -f1 | rev  )"

Thanks! that works pretty well. I think I'll stick with it in the meantime. And I'm using Arch, not Artix.

I don't know if anyone will be able to find the proper solution or Luke will have to use that one-liner instead. Thus, you choose whether to close the issue or not @AlexSyssoyev

Yeah let's close it, i doubt someone will find a real solution.

Are there other people out there that don't have this issue like me? Again, everything just werks for me.

I have checked clean LARBS on several Arch-based systems (Arch, Arcolinux). The same issue. But I'm pretty sure here are many people with somehow well-working lf.

Re-summarizing about clean LARBS:

  1. _lfrc_:
    map J $lf -remote "send $id cd $(cut -d' ' -f2 ${XDG_CONFIG_HOME:-$HOME/.config}/directories | fzf)"

  2. _directories_ (all lines are separated with spaces in voidrice, but also tried with tabs)

  3. lf output for jump to "h" ($HOME):
    cd: chdir /home/usr/h: no such file or directory
    we see issue with "h".

  4. let's change _lfrc_ with @AlexSyssoyev first fix:
    map J $lf -remote "send $id cd $(cut -d' ' -f2 ${XDG_CONFIG_HOME:-$HOME/.config}/directories | fzf | rev | cut -d' ' -f1 | rev)"

  5. Then we get this output when jump to "h" ($HOME):
    cd: chdir /home/usr/$: no such file or directory

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rescenic picture rescenic  路  6Comments

Jemi picture Jemi  路  9Comments

anntnzrb picture anntnzrb  路  8Comments

AlexSyssoyev picture AlexSyssoyev  路  6Comments

Davoodeh picture Davoodeh  路  7Comments