bookmark_borderFZF: a general-purpose command-line fuzzy finder.

I wanted to share with everybody how I use this amazing tool on my day to day on the terminal.

First of all, what exactly is fzf?

As you can see on the title of this post and on the fzf website:

fzf is a general-purpose command-line fuzzy finder.

And what does that exactly mean? Well, in short, it searches through a list without needing to be 100% accurate. You type a couple of letters and it will give you results based on likelihood:

Fedora Setup

To have a basic setup just install the software:

sudo dnf install fzf

And add these lines to your .bashrc:

if [ -f /usr/share/fzf/shell/key-bindings.bash ];then
source /usr/share/fzf/shell/key-bindings.bash
fi

if [ -f /etc/bash_completion.d/fzf ];then
source /etc/bash_completion.d/fzf
fi

The bash_completion will help you with:

  • whenever you want to use parameters whenever you call fzf by pressing tab:
  • Trigger fzf on another command with **

And the key-bindings:

  • CTRL-T – Paste the selected files and directories onto the command-line:
  • CTRL-R – Paste the selected command from history onto the command-line:
  • ALT-C – cd into the selected directory:

Customization

By default, fzf uses find but I’ve found ripgrep to be faster, let’s use it:

export FZF_DEFAULT_COMMAND='rg --files \
                           --no-ignore \
                           --hidden --follow \
                           --glob "!.git/*"'

Explanation:

  • --files to search for files instead of searching inside the files.
  • --no-ignore to not respect ignore files (.gitignore, .ignore, etc.).
  • --hidden to also search for hidden files and directories as they are ignored by default.
  • --glob '!.git/*'to no look inside the .git folders.

Now to customize fzf‘s behavior:

export FZF_DEFAULT_OPTS="--border-label-pos=1 \
                         --border=rounded \
                         --height 50% \
                         --select-1 \
                         --multi \
                         --bind ctrl-j:down,ctrl-k:up \
                         --bind '?:toggle-preview' \
                         --preview='[[ \$(file --mime {}) =~ binary ]] \
                         && echo {} is a binary file \
                           || (bat --style=numbers --color=always {} \
                           || cat {}) 2> /dev/null | head -300'"

Explanation:

  • --border-label-pos=1 to set where our label will show (the default is in the center).
  • --border=rounded to use nice rounded borders for our window.
  • --height 50% use 50% of the available space for our window.
  • --select-1 don’t bother showing a window when there’s only one result and select it.
  • --multi allow selection of multiple elements (useful to run a command on multiple files).
  • --bind ctrl-j:down,ctrl-k:up to move up and down (note: conflicts with my tmux conf).
  • --bind '?:toggle-preview'to use ? to toggle the preview window.
  • --preview=... to get a nice preview of non-binary files. Note: warning here.

Specific configuration for history:

export FZF_CTRL_R_OPTS="--no-sort \
                        --layout=reverse \
                        --border-label='History '"

Explanation:

  • --no-sort to not the result.
  • --layout=reverse to display from the top of the screen.
  • --border-lablel='History 'to add a nice label to our window.

Specific configuration for files:

export FZF_CTRL_T_OPTS="--select-1 --exit-0 --border-label='Files '"

Explanation:

  • --select-1 don’t bother showing a window when there’s only one result and select it.
  • --exit-0 exit without error even when there are no results.
  • --border-label='Files ' to add a nice label to our window.

Specific configuration for directory:

export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200' \
                       --border-label='Directories '"

I think this one doesn’t need any explaining 😉

Extras

I will explain more in a future post but for now I will give you a taste of what’s to come.

Fancy git log:

Vim integration:

References

bookmark_borderKDE Plasma 5.27.0 on Fedora (via our COPR)

After the announcement upstream, Fedora’s @kde-sig follows up by making KDE Plasma 5.27.0 available on Fedora 36 and Fedora 37.

There’s a catch though: you will have to use our COPR.

The regular update on Fedora repositories will follow shortly, I will keep you all posted.

Feel free to join us at our Matrix room!.

bookmark_borderClipboard tricks

Clearing the clipboard every 15 minutes

A few days ago, a member of our matrix room shared with us a small systemd timer and systemd unit to clear the clipboard every 15 minutes.

You can find the source code here. (credits to @cipherseven)

Quick instructions:

  • Create .config/systemd/user/
mkdir -p ~/.config/systemd/user
  • Create clipclear.timer with the contents:
[Unit]
Description=Run clipclear service every 15 mins

[Timer]
Unit=clipclear.service
OnCalendar=*:0/15

[Install]
WantedBy=timers.target
  • Create clipclear.service with the contents:
[Unit]
Description=run clear clipboard command

[Service]
Type=oneshot
ExecStart=/usr/lib64/qt5/bin/qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory 

[Install]
WantedBy=graphical.target
  • Enable the timer: systemctl --user enable --now clipclear.timer

Now our clipboard will be cleared on the clock at 0, 15, 30 and 45 minutes 🙂

pbcopy

Mac users are probably used to having this little helper pbcopy so I decided to create my own.

  • Create /usr/local/bin/pbcopy with the contents:
#!/usr/bin/env python
"""Copy input to clipboard."""

import os
import subprocess

if os.getenv("WAYLAND_DISPLAY"):
    with subprocess.Popen(['wl-copy']) as proc:
        proc.wait()
else:
    with subprocess.Popen(['xsel', '--clipboard', '--input']) as proc:
        proc.wait()
  • Execute permissions: chmod a+rx /usr/local/bin/pbcopy

NOTE: it uses two little programs: wl-copy on wayland and xsel on X11

NOTE: I created it in python only because I am forcing myself to write pyton code to become more proficient on it

tmux vi style copy/paste

If you are a tmux and vi/nvim user, perhaps you will find this trick useful. Add this to your .tmux.conf file:

# Enable vi on copy-mode
set -g mode-keys vi

# vi style copy/paste
bind p paste-buffer
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle \
                             \; send-keys -X begin-selection
unbind -T copy-mode-vi Enter
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'pbcopy'
bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel 'pbcopy'
bind-key -T copy-mode-vi \
         MouseDragEnd1Pane send-keys -X copy-pipe-and-cancel 'pbcopy'

And now you can use vi copy/paste style on your tmux and get it both into the tmux buffer and into the clipboard!

selection by columns vi style 🙂

bookmark_borderKDE Gear 22.12.2 available on Fedora 37

After the announcement upstream, Fedora’s @kde-sig follows up by making KDE Gear 22.12.2 available on Fedora 37.

As per Fedora’s policy, the software will first land on updates-testing and after receiving feedback and karma it will land on the updates repository.

If you want to help, make sure to follow the instructions on the update. You only need to run:

sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2023-17c31eabf7

Feel free to join us at our Matrix room!.