Have I told you about fzf?

Non release banter
User avatar
M. Eerie
Moderator
Moderator
Posts: 620
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce/MATE 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'
:)
> Does not compute_ πŸ––

https://forum.porteus.org/viewtopic.php?p=94310#p94310
https://forum.porteus.org/viewtopic.php?p=84002#p84002
https://forum.porteus.org/viewtopic.php?p=77174#p77174
https://forum.porteus.org/viewtopic.php?f=39&t=8584

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

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
Moderator
Moderator
Posts: 620
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce/MATE 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:
> Does not compute_ πŸ––

https://forum.porteus.org/viewtopic.php?p=94310#p94310
https://forum.porteus.org/viewtopic.php?p=84002#p84002
https://forum.porteus.org/viewtopic.php?p=77174#p77174
https://forum.porteus.org/viewtopic.php?f=39&t=8584

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

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
Moderator
Moderator
Posts: 620
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce/MATE 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)"
> Does not compute_ πŸ––

https://forum.porteus.org/viewtopic.php?p=94310#p94310
https://forum.porteus.org/viewtopic.php?p=84002#p84002
https://forum.porteus.org/viewtopic.php?p=77174#p77174
https://forum.porteus.org/viewtopic.php?f=39&t=8584

User avatar
M. Eerie
Moderator
Moderator
Posts: 620
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce/MATE 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
> Does not compute_ πŸ––

https://forum.porteus.org/viewtopic.php?p=94310#p94310
https://forum.porteus.org/viewtopic.php?p=84002#p84002
https://forum.porteus.org/viewtopic.php?p=77174#p77174
https://forum.porteus.org/viewtopic.php?f=39&t=8584

User avatar
M. Eerie
Moderator
Moderator
Posts: 620
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce/MATE x64

Have I told you about fzf?

Post#7 by M. Eerie » 22 Oct 2021, 08:20

This could be a great resource of fzf use cases.

:)
> Does not compute_ πŸ––

https://forum.porteus.org/viewtopic.php?p=94310#p94310
https://forum.porteus.org/viewtopic.php?p=84002#p84002
https://forum.porteus.org/viewtopic.php?p=77174#p77174
https://forum.porteus.org/viewtopic.php?f=39&t=8584

User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

Have I told you about fzf?

Post#8 by Rava » 23 Oct 2021, 00:19

^
Nice find M. Eerie. Oneliners are one of my favourites when it comes to using the terminal. :)

Added in 2 minutes 14 seconds:
requirements: zsh is your shell
oh well, probably there is a need to convert to bash, then.

@M. Eerie: Do you use zsh?

Added in 16 minutes 14 seconds:
After looking into https://raw.githubusercontent.com/majam ... liners.txt (that's the raw text the reddit refers to) I only found a mere two instances where fzf is found:
{{{sh
SOURCE=$(pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2 | fzf --prompt="Select source >")
SINK=$(pactl list | grep -A2 'Sink #' | grep 'Name: ' | cut -d" " -f2 | fzf --prompt="Select sink >")
PULSE_SOURCE="$SOURCE" PULSE_SINK="$SINK" ffplay "https://holiday.stream.publicradio.org/holiday_yc.aac"
}}}
(highlighting by me)

What am I missing?
Cheers!
Yours Rava

User avatar
M. Eerie
Moderator
Moderator
Posts: 620
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce/MATE x64

Have I told you about fzf?

Post#9 by M. Eerie » 23 Oct 2021, 07:59

Rava wrote: ↑
23 Oct 2021, 00:38
What am I missing?
From the original link:

"These are (mostly) oneliner commands that I've collected over a year or so. The lines that start with (*) are oneliners (grep them, or whatever, and pipe to fzf, for example)."

I guess the OP suggest to use a combo of his oneliners collection with fzf where appropiate. Not all examples will turn into fzf targets, but I think the resource is worthwhile.

There is a prettier .html version contributed by another user as well.
> Does not compute_ πŸ––

https://forum.porteus.org/viewtopic.php?p=94310#p94310
https://forum.porteus.org/viewtopic.php?p=84002#p84002
https://forum.porteus.org/viewtopic.php?p=77174#p77174
https://forum.porteus.org/viewtopic.php?f=39&t=8584

Post Reply