Have I told you about fzf?

Non release banter
Post Reply
User avatar
M. Eerie
Shogun
Shogun
Posts: 365
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

Have I told you about fzf?

Post#1 by M. Eerie » 08 Oct 2021, 19:23

Now that we know btop, meet fzf

Image

See some samples of what can it do for us...


'Fuzzy activate module'

Code: Select all

activate $(find $PORTDIR/ -iname '*.xzm' | fzf)
Fuzzy install package (alias pacfinder)

Code: Select all

alias pacfinder='pacman -Slq | fzf --multi --preview '\''pacman -Si {1}'\'' | xargs -ro sudo pacman -S'
:)
Cheers!

User avatar
Rava
Contributor
Contributor
Posts: 3076
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0rc3 x86_64 + 4.0 i586
Location: Forests of Germany
Contact:

Have I told you about fzf?

Post#2 by Rava » 10 Oct 2021, 20:55

The fzf I made out of fzf-0.17.0-x86_64-1_slonly.txz looks nothing like your screen shot:

Code: Select all

> btop-static-1.0.13-x86_64.xzm/usr/share/btop/themes/kyli0x.theme              
  btop-static-1.0.13-x86_64.xzm/usr/share/btop/themes/gruvbox_dark.theme        
  btop-static-1.0.13-x86_64.xzm/usr/share/btop/themes/greyscale.theme           
  btop-static-1.0.13-x86_64.xzm/usr/share/btop/themes/flat-remix.theme          
  btop-static-1.0.13-x86_64.xzm/usr/share/btop/themes/flat-remix-light.theme    
  btop-static-1.0.13-x86_64.xzm/usr/share/btop/themes/dusklight.theme           
  btop-static-1.0.13-x86_64.xzm/usr/share/btop/themes/dracula.theme             
  btop-static-1.0.13-x86_64.xzm/usr/share/btop/themes/adapta.theme              
  btop-static-1.0.13-x86_64.xzm/usr/bin/btop                                    
  fzf-0.17.0-x86_64-1_slonly.xzm/var/log/packages/fzf-0.17.0-x86_64-1_slonly    
  fzf-0.17.0-x86_64-1_slonly.xzm/var/lib/pkgtools/packages/fzf-0.17.0-x86_64-.. 
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/share/zsh/site-functions/_fzf              
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/share/vim/vimfiles/plugin/fzf.vim          
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/share/bash-completion/completions/fzf      
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/man/man1/fzf.1                             
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/doc/fzf-0.17.0/key-bindings.zsh            
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/doc/fzf-0.17.0/key-bindings.bash           
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/doc/fzf-0.17.0/fzf.SlackBuild              
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/doc/fzf-0.17.0/README.md                   
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/doc/fzf-0.17.0/README-VIM.md               
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/doc/fzf-0.17.0/LICENSE                     
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/doc/fzf-0.17.0/CHANGELOG.md                
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/doc/fzf-0.17.0/BUILD.md                    
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/bin/fzf-tmux                               
  fzf-0.17.0-x86_64-1_slonly.xzm/usr/bin/fzf                                    
- 25688/25720                                                                   
>                          

When I select a file, fzf just prints the file name.

Is fzf-0.17.0-x86_64-1_slonly.txz not the fzf you meant?

Or is there a trick in starting it that I miss?
Cheers!
Yours Rava

User avatar
M. Eerie
Shogun
Shogun
Posts: 365
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

Have I told you about fzf?

Post#3 by M. Eerie » 11 Oct 2021, 07:48

Rava wrote:
10 Oct 2021, 20:55
When I select a file, fzf just prints the file name.
After all, fzf is a finder... :)

You can do things like:

Code: Select all

xdg-open $(fzf)
in your $HOME, then start typing some video name, then hit return, then watch it (as xdg-open relies on your system mimetypes). Pretty fast if you set a terminal tab or attach a tmux session.

Also, as I showed above, you can activate a module following the same approach.

Code: Select all

activate $(find $PORTDIR/ -iname '*.xzm' | fzf)
Or if using nemesis, query the database to see package info then hit return, and selected package will be installed at your will. Maybe you can easily create a wrapper to build slack packages from there.

There's even a fuzzy youtuber

Here is a tutorial.


Regarding the color scheme (if this is what matters), this snippet (borrowed from fzfx) may put you on track. Set your FZF_DEFAULT_OPTS in your .bashrc and change it to suit your taste. (I don't know if the version is relevant here, but slackware seems to be in 0.17 while the Archlinux one I'm using on Nemesis is 0.27 by now.

Code: Select all

# DEFAULTS
# f1 opens with xdg-open, f2 opens with text editor, f3 copy path to console clipboard,
# f4 echoes path to stdout, alt+shift+d move file to trash.
defaultBind="\
f1:execute-silent(xdg-open {} 2>/dev/null)+cancel,\
f2:execute($editor {})+cancel,\
f3:execute-silent(xclip <<< {})+cancel,\
f4:accept,\
enter:execute(echo $searchPath/{})+abort"
defaultHeader="f1 → default, f2 → editor, f3 → clipboard, f4 → terminal, alt+shift+d → delete"

if [ "$(command -v bat)" ]; then
    defaultPreview="bat --style=numbers --color=always --line-range :500 {}"
else
    defaultPreview="cat {}"
fi

defaultOpts="--preview-window=right:50%:wrap"

defaultOpts="--preview-window=right:50%:wrap"

#defaultColors="
#dark,\
#bg+:#373e47,\
#bg:#2d333b,\
#spinner:#6bac00,\
#hl:#0087e9,\
#fg:#adbac7,\
#header:#009385,\
#info:#d9b600,\
#pointer:#b37eff,\
#marker:#cf2424,\
#fg+:#dddddd,\
#prompt:#d40059,\
#hl+:#ff5c00"

# Export Defaults
export FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --bind '$defaultBind' --header '$defaultHeader' --preview '$defaultPreview' $defaultOpts" #--colors $defaultColors
Happy ffsaaafasdzxfasafasfasdfzzzingg!! :roll:
Cheers!

User avatar
Rava
Contributor
Contributor
Posts: 3076
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0rc3 x86_64 + 4.0 i586
Location: Forests of Germany
Contact:

Have I told you about fzf?

Post#4 by Rava » 11 Oct 2021, 08:25

^
Thanks I check out.

Still, how do I get it to look like the screenshot you provided?

I presume https://www.youtube.com/watch?v=tB-AgxzBmH8 might explain it.
Cheers!
Yours Rava

User avatar
M. Eerie
Shogun
Shogun
Posts: 365
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

Have I told you about fzf?

Post#5 by M. Eerie » 11 Oct 2021, 09:08

Rava wrote:
11 Oct 2021, 08:25
how do I get it to look like the screenshot you provided?
I'm just using a xfce4-terminal drop-down:

Code: Select all

xfce4-terminal --drop-down --hide-borders --hide-menubar --hide-scrollbar --geometry=80x25+400+150 -I=org.xfce.terminal-settings --active-tab -T 'System Monitor' -x btop
The other tabs, I had to open manually. This is not working for me: :no: (Pretty sure escape sequences involved)

Code: Select all

xfce4-terminal --drop-down --hide-borders --hide-menubar --hide-scrollbar --geometry=80x25+400+150 -I=org.xfce.terminal-settings --active-tab -T 'System Monitor' -x btop --tab -T 'fuzzy activate' -e activate "$(find $PORTDIR -iname '*.xzm' | fzf)"
Cheers!

User avatar
M. Eerie
Shogun
Shogun
Posts: 365
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce x64

Have I told you about fzf?

Post#6 by M. Eerie » 12 Oct 2021, 18:01

M. Eerie wrote:
11 Oct 2021, 09:08
The other tabs, I had to open manually.
Got it working:

Inserted as a function into .bashrc

Code: Select all

function fuzzyactivate() { activate $(find "$PORTDIR"/ -name "*.xzm" | fzf --multi ); }; export -f fuzzyactivate
Then attach this to F12 keyboard shortcut:

Code: Select all

xfce4-terminal --drop-down --hide-borders --hide-menubar --hide-scrollbar --geometry=80x25+400+150 -I=org.xfce.terminal-settings --active-tab -T 'System Monitor' -e btop --tab -T 'fuzzyactivate' -x bash -ic fuzzyactivate
More than one module can be activated by selecting via TAB key, (i.e. start typing firef then hit TAB then select another module, hit TAB again then RETURN)

However the tab closes as the function ends
Cheers!

Post Reply