Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Last active July 12, 2024 20:57
Show Gist options
  • Save lukepighetti/8e4a13db5bdcd68a7d83eee19051ab14 to your computer and use it in GitHub Desktop.
Save lukepighetti/8e4a13db5bdcd68a7d83eee19051ab14 to your computer and use it in GitHub Desktop.
Helix – tree file picker... TODAY?!?
[keys.normal]
C-f = [":new", ":insert-output lf-pick", ":theme default", "select_all", "split_selection_on_newline", "goto_file", "goto_last_modified_file", ":buffer-close!", ":theme tokyonight_storm"]
# touch ~/.local/bin/lf-pick
# chmod +x ~/.local/bin/lf-pick
function lfp(){
local TEMP=$(mktemp)
lf -selection-path=$TEMP
cat $TEMP
}
lfp
@beeb
Copy link

beeb commented Mar 13, 2023

Great workaround! But for me on both macOS and WSL2 the UI reloading doesn't work. I use a custom theme but still, the only thing I changed compared to the above was the last command with my theme name. The theme gets re-applied but half of the UI still shows the lf stuff.
If I then manually change the theme again back and forth the UI becomes OK.
Any other way I could trigger a UI refresh, maybe adding a delay of some sort (could help)?

@lukepighetti
Copy link
Author

I'm not familiar with anything, unfortunately. Scripting is very limited in Helix right now!

@webbb82
Copy link

webbb82 commented Mar 26, 2023

that helix config code block sure is a mouthful aint she lol

@mikaeilorfanian
Copy link

lfp(){
  local TEMP=$(mktemp)
  lf -selection-path=$TEMP
  cat $TEMP
}

lfp

worked for me

@danielgaban
Copy link

Hello, can someone provide a translated script for powershell windows?

@mikaeilorfanian
Copy link

WSL2 + Ubuntu + Helix is lighter than vscode on windows. I don't see a reason to not use WSL if you've already switched to Helix. You're going to have issues all the time making things compatible with Windows.

@danielgaban
Copy link

I have wsl installed but I dont know how to use it. I will get learn. Thank you for the advice @mikaeilorfanian

@gabydd
Copy link

gabydd commented May 27, 2023

if you do want to use this script please use this version: https://gist.github.com/gabydd/570f0dd5f71dda35241500c18f5d27e3 it should mitigate most if not all of the problems with this script

@iztsv
Copy link

iztsv commented Aug 18, 2023

also I've faced with the issue when some key bindings does not work after file opening (for example Alt-d) :(

@rodrigopim
Copy link

rodrigopim commented Feb 2, 2024

WSL2 + Ubuntu + Helix is lighter than vscode on windows. I don't see a reason to not use WSL if you've already switched to Helix. You're going to have issues all the time making things compatible with Windows.

I'm using WSL2 + Arch + Helix + Java in my job and works fine! Only in cases I need to debug in Weblogic I do with Apache Netbeans.

""
But, this hack with LF not work in my notebook. UI broken.
""
Correction: using keybinding works like a charm!!! thanks rs.

I want to see how will work in my desktop.

@godalming123
Copy link

godalming123 commented Feb 12, 2024

@lukepighetti use the redraw function to update the helix window instead of changing your theme:

[keys.normal]
C-f = [":new", ":insert-output lf-pick", "select_all", "split_selection_on_newline", "goto_file", "goto_last_modified_file", ":buffer-close!", ":redraw"]

@rodrigopim
Copy link

@lukepighetti use the redraw function to update the helix window instead of changing your theme:

[keys.normal]
C-f = [":new", ":insert-output lf-pick", "select_all", "split_selection_on_newline", "goto_file", "goto_last_modified_file", ":buffer-close!", ":redraw"]

nice, thanks!
image

@isaldarriaga
Copy link

WSL2 + Ubuntu + Helix is lighter than vscode on windows. I don't see a reason to not use WSL if you've already switched to Helix. You're going to have issues all the time making things compatible with Windows.

Agree.. though

I noticed helix running slow in WSL.

If you benchmark the disks WSL create for you (lsblk, sudo gnome-disks or dd equivalent) you'll notice /sda inside WSL is 1000x times slower than your regular disk (some Mbps vs Gbps). 😵‍💫

WSL is virtualized and won't compare to native performance ever.
All programs inside WSL run slow as hell: e.g. chrome, webstorm, neovim, etc.

Some inconveniences i personally find in wsl:

  • Official instructions to setup nerd font doesn't work.
  • There's no official arch image with AUR (Apt repos does not compare in size and quality to aur / see repology.org)

Alternatives

  • windows containers: actually not a solution (windows in windows??)
  • docker desktop: you have to pay for it (uninstalled immediately)
  • if you have to deal with windows virtualized in azure (even worse):
    • vm in vm doesnt work either (virtualbox)
    • alacritty and other terms doesn't work well or just crashes
  • podman (virtualized with wsl ???)

The only benefit i see with wsl is the networking setup that works out of the box in windows (if you need vpn).

Still looking for a better workflow, maybe hyper-v with garuda, though require network setup for vpn access.

@kkonevets
Copy link

lfp(){
  local TEMP=$(mktemp)
  lf -selection-path=$TEMP
  cat $TEMP
}

lfp

worked for me

Yep, thanks, worked for me too on linux

@fgionghi
Copy link

Hei!
I really missed the functionality of open lf in the current directory. With helix itself seems impossibile to get the file path of the current buffer, but this guy is using wezterm to do that: https://quantonganh.com/2023/08/19/turn-helix-into-ide.md

Here what is working for me:

#!/bin/bash

function lfp(){
  status_line=$(wezterm cli get-text | rg -e "(?:NOR\s+|NORMAL|INS\s+|INSERT|SEL\s+|SELECT)\s+[\x{2800}-\x{28FF}]*\s+(\S*)\s[^│]* (\d+):*.*" -o --replace '$1 $2')
  filename=$(echo $status_line | awk '{ print $1}')
  local TEMP=$(mktemp)
  lf -selection-path=$TEMP $filename
  cat $TEMP
}

lfp

@Akselmo
Copy link

Akselmo commented Jul 12, 2024

Is there a way to set the current working directory with this as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment