Code Monkey home page Code Monkey logo

Comments (5)

doronbehar avatar doronbehar commented on June 18, 2024 3

I guess you are right. I think that this kind of integration might be worth the effort to be merged into the main ZSH repository. But I assume that it would require a lot of work to make it safe and configureable even for users of other fuzzy selection programs such as https://github.com/jhawthorn/fzy for example or other alternatives.

Just for the sake of clearance for everyone who may read this discussion: I think the main reason a fuzzy selector might be even more usable if used from within the completion system of ZSH, is that currently, using the widgets mechanism of ZSH, the interpretation of what available options there are for completion is done separately from the completion system. And considering how much effort has been put to make command completions extremely useful (take git's completion for example) it would be insane to re-implement it in separate functions binded to widgets that they collect the available options of completion and just launch fzf (and not the _complete function for example). Therefor it would be much better to make the existing completion functions launch fzf if available and if it is configured with zstyle.

from zsh-interactive-cd.

doronbehar avatar doronbehar commented on June 18, 2024

Usually when a command needs to be completed with the same completion just like a different command, you use compdef _cd cl but it doesn't work since is not a completion plugin but a zle widget. As far as I understand the code, the widget is defined with check for cd hard-coded when the widget is defined. Try this:

zic-completion-cl () {
	setopt localoptions noshwordsplit noksh_arrays noposixbuiltins
	local tokens cmd
	tokens=(${(z)LBUFFER}) 
	cmd=${tokens[1]} 
	if [[ "$LBUFFER" =~ "^\ *c[ld]$" ]]
	then
		zle ${__zic_default_completion:-expand-or-complete}
	elif [[ "$cmd" =~ "c[ld]" ]]
	then
		_zic_complete ${tokens[2,${#tokens}]/#\~/$HOME}
	else
		zle ${__zic_default_completion:-expand-or-complete}
	fi
}
zle -N zic-completion-cl
bindkey "^I" zic-completion-cl

I have just created a sister function to zic-completion like the origin and I replaced the hard-coded conditions that check the current command line arguments against cd so cl will be checked as well.

Having this kind of customization ability built in with the code should require more work but you can use this as a workaround in the meantime..

from zsh-interactive-cd.

balta2ar avatar balta2ar commented on June 18, 2024

@doronbehar Is there an easy way to generalize this and replace zsh's completion menu with a menu implemented on top of fzf for any command that uses zsh menu? fzf is so great that I'd like to use it in every command that can display a menu with candidates. Is that archievable in zsh?

from zsh-interactive-cd.

doronbehar avatar doronbehar commented on June 18, 2024

Well TBH, I stopped using zsh-interactive-cd after I realized what it does and after I figured out how to produce it's functionality it along with what the features the other ZSH related files that https://github.com/junegunn/fzf offers (key-bindings.zsh and completion.zsh) under it's own domain.

Thanks for being interested in this subject. To be frank, I'm really proud of my ZSH fzf related configuration and that's why I wrote an article about it in my website: https://doronbehar.com/articles/ZSH-FZF-completion/ .

from zsh-interactive-cd.

balta2ar avatar balta2ar commented on June 18, 2024

Yes, my question is not really related to this repo specifically, but it's related to the topic of the issue.

I've read your post. Franky, I have shallow understanding of how zsh (and zle) works and I may be wrong, but you seem to be doing pretty much similar things which are described in fzf wiki, e.g.: https://github.com/junegunn/fzf/wiki/Examples-(completion)#zsh-complete-hg-updatehg-merge

With this approach the downsides are:

  1. you need to have a wrapper for each command that you want to power up with fzf
  2. it gets uglier when you want to support subcommands (e.g. hg up, hg merge)
  3. I guess it gets even worse than that if you want to support flags/arguments (e.g. hg diff --rev <cursor>)

I was wondering whether fzf could be plugged everywhere transparently? What I mean is that interactive menu completion in zsh can be enabled as follows:

zstyle ':completion:*' menu select interactive

I wish there were some alternative with fzf, e.g. menu select fuzzyinteractive which would call fzf or exhibit similar visual behavior without any additional bindings but with the default TAB. I'm afraid that to do that, one would need to go down the rabbit hole and implement it in zsh (in C).

from zsh-interactive-cd.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.