Comments (17)
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.
- 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'
- (&3) It has nothing to do with zstyle.
--preview
will spawn a new zsh process withzsh -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 thereply
variable.
- I don't understand... Can you give me a example?
from fzf-tab.
@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.
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.
Ummm, there may need a way to extract the group name.
from fzf-tab.
Indeed with extracted group name and tag and context string we could really leverage a lot of interesting preview easily
from fzf-tab.
@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.
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.
@adelin-b Thanks a lot!
Unfortunately, that link gave me: "We couldn’t find any files to show."
from fzf-tab.
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.
@adelin-b WOW! Thank you very much!
That works perfectly!
@Aloxaf Any chance to make this a part of fzf-tab?
from fzf-tab.
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.
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 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.
@Aloxaf Ok, fair enough.
from fzf-tab.
@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.
@adelin-b Please take a look at #126.
from fzf-tab.
Related Issues (20)
- [FR] Could fzf-tab builds the binary without zsh source code like past? HOT 1
- [BUG] TAB key presses are reversed in specific scenarios when using `ftb-tmux-popup` HOT 6
- [Q] how to get color git Tab as shown in the Readme? HOT 1
- [BUG] source directory name confliction on case-insensitive filessytem such as APFS for macos HOT 3
- [Q] How to set the sort of all commands to most frequently used, not alphabetical?
- [BUG] completion is mess when _describe use alternative array HOT 4
- [BUG] Smart Case Prefix Completion HOT 1
- [Q] How to sort directory first on completion? HOT 2
- [BUG] Faulty completion when completing `networkctl` HOT 1
- [Q] Custom Height HOT 3
- [BUG] No completion for some builtin commands? HOT 4
- [Q] How to change the suggestion color? HOT 2
- [Q] How to change "same_word" color? HOT 1
- [Q] How to sort by proximity?
- [FR] Preview completion
- Ctrl J-K movement [Q] HOT 1
- [BUG] Syntax highlighting disappears when completion is cancelled HOT 2
- [Q] Error when using fzf-tab's preview feature HOT 3
- [Q] How can I let fzf-tab use these configs I set for fzf HOT 1
- [BUG] Breaks nix completion when quotes are used instead of \ HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fzf-tab.