gokcehan/lf

Is Redefining the `cd` cmd Possible?

Closed this issue · 2 comments

I discovered this zoxide extension recently on the wiki:

cmd z %{{
  result="$(zoxide query --exclude $PWD $@ | sed 's/\\/\\\\/g;s/"/\\"/g')"
  lf -remote "send $id cd \"$result\""
}}

In my terminal, I have aliased z to cd, and I was hoping to implement a similar alias in Lf. I tried renaming the cmd above to cd, but unfortunately, it didn't work (the default cd command remains unchanged).

I also tried preceding that cmd definition with cmd cd, following this info in the docs:

You can delete an existing command by leaving the expression empty:

cmd trash          # deletes 'trash' command

However, the built-in cd command does not get deleted. Is what I'm trying to do possible?

TL;DR Not possible. Built-in commands are hardcoded via a massive switch statement starting from here, and thus cannot be redefined or deleted. User-defined commands are internally stored in a map and handled by the default case at the bottom.

You are probably better off sticking with cmd z, or triggering that code via a custom map keybinding.

Thanks for the quick answer!