Git Product home page Git Product logo

Comments (17)

adelin-b avatar adelin-b commented on August 18, 2024 1

So this is what im doing at the moment but I'm still unsatisfied

fzf_tab_preview_commit='
# Show commits and branch commits 
git show $( echo "$in" | cut -f 1 -d " " ) | diff-so-fancy --colors
'

fzf_tab_preview_options=''

fzf_tab_preview_command='
# Show information on command
which ${~ctxt[hpre]}$in | grep -v "not found" 2> /dev/null;
whatis ${~ctxt[hpre]}$in 2> /dev/null;

# Show my own snippets related to the command
grep -w "$in" ~/.config/clisnippets 2> /dev/null;

# tldr show cheatsheet of command
tldr $in 2> /dev/null;

# Search through man and give the description segment
man "${~ctxt[hpre]}$in" 2> /dev/null |col -bx|awk -v S="$2" "DESCRIPTION ~ S {cap="true"; print} DESCRIPTION !~ S && /^[A-Z ]+$/ {cap="false"} DESCRIPTION !~ S && !/^[A-Z ]+$/ {if(cap == "true")print}" 2> /dev/null;
'

fzf_tab_preview_file='
# Display images
tiv -h ${FZF_PREVIEW_LINES} -w ${FZF_PREVIEW_COLUMNS} $in  2> /dev/null;

# Display directory
# du -h ${~ctxt[hpre]}$in 2> /dev/null | tail -n1
lsd --tree --icon --depth 2  --color=always $in 2> /dev/null
# exa -1 --color=always $in 2> /dev/null;

# Display file
bat --theme="OneHalfDark" --style=numbers,changes --color always $in 2> /dev/null | head -n50 | grep -v "bat warning"; 2> /dev/null;

# Display exif data
exiftool $in  2> /dev/null;
'

fzf_tab_preview_systemctl_service='
systemctl status $in
systemctl help $in
'

  zstyle ':fzf-tab:complete:*' extra-opts --preview=$extract$fzf_tab_preview_file
  zstyle ':fzf-tab:complete:*:options' extra-opts '' # --preview=$extract$fzf_tab_preview_options
  zstyle ':fzf-tab:complete:-command-:*' extra-opts --preview=$extract$fzf_tab_preview_command
  zstyle ':fzf-tab:complete:git*:*' extra-opts --preview=$extract$fzf_tab_preview_commit$fzf_tab_preview_file
  zstyle ':fzf-tab:complete:systemctl*:*' extra-opts --preview=$extract$fzf_tab_preview_systemctl_service

However this is not really the way I want to achieve it, I don't really get how to interpret the result of C-x h

tags in context :completion::complete:git::
    argument-rest  (_arguments _git _git)
tags in context :completion::complete:git-checkout::
    argument-rest options  (_arguments _git-checkout _git _git)
tags in context :completion::complete:git-checkout:argument-rest:
    modified-files tree-ishs remote-branch-names-noprefix  (_git-checkout _git _git) 
    modified-files                                         (__git_files __git_modified_files _git-checkout _git _git) 
    recent-branches commits                                (__git_commits_prefer_recent _git-checkout _git _git) 
    recent-branches                                        (__git_recent_branches __git_commits_prefer_recent _git-checkout _git _git) 

I would like to be able to target each tag differently for example

  zstyle ':fzf-tab:complete:git*:commits' extra-opts --preview=$extract' echo Commits\n; '$fzf_tab_preview_commit$fzf_tab_preview_file
  zstyle ':fzf-tab:complete:git*:modified-files' extra-opts --preview=$extract' echo Modified files \n; '$fzf_tab_preview_commit$fzf_tab_preview_file

or even better something like

  zstyle ':fzf-tab:complete:*:*' extra-opts --preview=$extract' tag=$extractedTagName 
if [[ tag == "file" ]]; then
  
fi
if [[ tag == "commits" ]]; then
  
fi
if [[ tag == "recent branches" ]]; then
  
fi
  '

from fzf-tab.

Aloxaf avatar Aloxaf commented on August 18, 2024
  1. You can use different context:
# for command
zstyle ':fzf-tab:complete:-command-:*' extra-opts --preview=$extract'
  which ${~ctxt[hpre]}$in | grep -v "not found" 2> /dev/null;
  whatis ${~ctxt[hpre]}$in 2> /dev/null;
  man "${~ctxt[hpre]}$in" 2> /dev/null |col -bx|awk -v S="$2" "DESCRIPTION ~ S {cap="true"; print} DESCRIPTION !~ S && /^[A-Z ]+$/ {cap="false"} DESCRIPTION !~ S && !/^[A-Z ]+$/ {if(cap == "true")print}" 2> /dev/null;
'
# for options
zstyle ':fzf-tab:complete:*:options' extra-opts --preview=$extract'echo $in'
  1. (&3) It has nothing to do with zstyle. --preview will spawn a new zsh process with zsh -c PREVIEW_CODE, which won't load the zshrc and know nothing about your current zsh session.
    Here are two solutions:
  • Source your zshrc manually. This is a simple solution but you might need to modify your zshrc to ensure that unnecessary code won't be sourced.
  • use zstyle -e. It will eval its content as zsh code and get the final value from the reply variable.
  1. I don't understand... Can you give me a example?

from fzf-tab.

justinlovinger avatar justinlovinger commented on August 18, 2024

@Aloxaf Can context target files, for any command? I would like --preview when completing files, but not options, processes, etc.

In general, are the available fzf-tab zstyle contexts documented anywhere? The readme implies you can use c-x h to find contexts, but that doesn't work for fzf-tab in my experience. I can't use c-x h during fzf, and the :completion: contexts don't seem related to :fzf-tab: contexts.

from fzf-tab.

Aloxaf avatar Aloxaf commented on August 18, 2024

@justinlovinger

Can context target files, for any command?

For most command, you can use fzf-tab:complete:*:argument-rest, except some special commands like file. You should use :fzf-tab:complete:file:* for file command.

In general, are the available fzf-tab zstyle contexts documented anywhere?

Unfortunately, there aren't. There are command-specific, though most command will repect to a regular format. You may find some useful information here.

the :completion: contexts don't seem related to :fzf-tab: contexts

Just replace :completion: to :fzf-tab:.

from fzf-tab.

Aloxaf avatar Aloxaf commented on August 18, 2024

Ummm, there may need a way to extract the group name.

from fzf-tab.

adelin-b avatar adelin-b commented on August 18, 2024

Indeed with extracted group name and tag and context string we could really leverage a lot of interesting preview easily

from fzf-tab.

magnetophon avatar magnetophon commented on August 18, 2024

@adelin-b That gif looks fantastic, thanks for posting it, and the code that goes with it!
I pasted your code into my zshrc, but I'm getting an incorrect preview.
I don't expect you to troubleshoot this for me, therefore I haven't provided more details, but could you just tell me:

  • do I need to (not) do anything else?
  • does the placement/order of where I paste your code matter?

from fzf-tab.

adelin-b avatar adelin-b commented on August 18, 2024

Here is an updated version of this code snippet as they were breaking changes since.
https://gist.github.com/adelin-b/53fecd0f9010819bae2e69792da29704

  • You need to install the dependencies of cli used in the code snippets
  • It only matter of where compinit is I think but im not sure, it should be before
  • back up you system in case in a completion something pop like ;rm ~/* -rf or worst a ; ssh .... that would allow your machine to be used from remote

from fzf-tab.

magnetophon avatar magnetophon commented on August 18, 2024

@adelin-b Thanks a lot!
Unfortunately, that link gave me: "We couldn’t find any files to show."

from fzf-tab.

adelin-b avatar adelin-b commented on August 18, 2024

It should be working now, mind that there will be a revision of this gist to escape the completion string to prevent injection @magnetophon

from fzf-tab.

magnetophon avatar magnetophon commented on August 18, 2024

@adelin-b WOW! Thank you very much!
That works perfectly!

@Aloxaf Any chance to make this a part of fzf-tab?

from fzf-tab.

adelin-b avatar adelin-b commented on August 18, 2024

It is actually really usefull but not much people ive shown this like it as it look clutered
In my experience it saved me countless keystroke

  • by not having to ls <directory> before copying / accessing it / removing it
  • by not having to preview images
  • showing git diff automatically on the file I want to add or branch to checkout / rebase onto

It replace packages like https://github.com/wfxr/forgit https://github.com/chriswalz/bit and all of thoses

from fzf-tab.

magnetophon avatar magnetophon commented on August 18, 2024

It is actually really usefull but not much people ive shown this like it as it look clutered

I imagine that if @Aloxaf ads this to fzf-tab, it will be an option.

from fzf-tab.

Aloxaf avatar Aloxaf commented on August 18, 2024

@Aloxaf Any chance to make this a part of fzf-tab?

Sorry, the answer is no. Though this configuration is cool, it goes beyond the purpose of this repo.
Just like p10k is cool but it still hasn't been the default theme of zsh.

from fzf-tab.

magnetophon avatar magnetophon commented on August 18, 2024

@Aloxaf Ok, fair enough.

from fzf-tab.

adelin-b avatar adelin-b commented on August 18, 2024

@Aloxaf it also goes beyond the scope of this issues which is getting the $tag name of the ongoing preview which is still needed for cleaner previews

from fzf-tab.

Aloxaf avatar Aloxaf commented on August 18, 2024

@adelin-b Please take a look at #126.

from fzf-tab.

Related Issues (20)

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.