37 comments

[ 3.5 ms ] story [ 72.5 ms ] thread
Looks like a useful tool, thanks for sharing!
I'm continually impressed at how many uses fzf has. Yet I still feel like we're only scratching the surface of its utility.
I use it for browsing documentation and code files, e.g. to browse syscall manpages:

apropos -s 2 '.*' | fzf --height=100% --preview-window=down:wrap --preview='man -s 2 {1}' --bind='alt-v:execute(man -s 2 {1}),enter:execute(man -s 2 {1})'

You can also use it with rlwrap for browsing commandline history of arbitrary REPLs (https://github.com/hanslub42/rlwrap/blob/fb60c9aa7579d6b68f2...)

Does anyone know of a way or how to go about making a way to get <tab> and <tab><tab> to bash autocomplete "systemctl status " with service names? It seems like remembering where the service name has dashes, matches the package name, has a "d" at the end, and so on is half the battle for me when working with systemctl.

This achieves something similar but it also does a whole lot more than just help complete the name.

Edit: Helps to have bash-completion working properly for the user :).

(comment deleted)
Does it suffice with systemd's bash completion? On debian it's bundled with systemd.

  systemd: /usr/share/bash-completion/completions/systemctl
This works for me out of the box. Your bash profile might not be sourcing systemd's /usr/share/bash-completion/completions/systemctl or equivalent path.

This host has bash 4.4.23 and systemd 247.6

Thanks for the confirmation I cleaned a few things up and the user profile is now loading it properly and auto-completion works.
Honestly I don't understand why some distros still don't ship with completions for this sort of thing. Debian and Ubuntu have had this for the entire time they've been using systemd, as far as I recall. (And they've supported completion on other tools for even longer!)
what distros don't? (honest question)
I'm not sure, to be quite honest. I know I've worked with a few systems in the last ~3.5 years that were missing completions that are present in Ubuntu 18.04, but I can't find any of them now.

(It looks like the person I replied to had an issue with his own profile files rather than a distro issue.)

It doesn't appear to be on RHEL8 boxes I've been working on recently.
The crazy thing about this is how simple the code is.

    _sysz_list_units |
      fzf \
        --exact \
        --multi \
        --ansi \
        --reverse \
        --no-sort \
        --history="$SYSZ_HISTORY" \
        --prompt="Units: " \
        --bind "ctrl-v:preview('${BASH_SOURCE[0]}' _fzf_cat {})" \
        --preview="'${BASH_SOURCE[0]}' _fzf_preview {}" \
        --preview-window=70% |
  readarray -t PICKS
This is the whole UI. Just give it a list of things to search through, a prompt, and a command for previewing the thing and fzf handles literally all the rest of the UI for you.
I have not heard of fzf - but anything that makes cli interactions with systemd is welcome by me. I love it as a tool - but it is kinda verbose with cli args.
If you have trouble running this, try updating fzf. TIL that my package manager's version of fzf is 4 years old, and that did not play nicely with some of the features used by Sysz.
(comment deleted)
Off-topic: how do you call a prompt that looks like the one in the video? I'd like to have one in my fish terminal.

(I tried installing an oh-my-fish theme with such a prompt, but it required Powerline fonts, which I can't get to work.)

Can anyone compare/contrast fzf and pick[1]? I use pick for all sorts of things, but especially as a replacement in vim for CtrlP. Wondering if I'm missing out on something :-)

[1] https://github.com/mptre/pick

This is the first I've heard of "pick", but it looks like it's missing a lot of the interactive features of fzf. Those features are what make fzf good for building UIs.
I love fzf but somehow I can never find a way to naturally make it a part of my workflow.
The zag ctrl-r integration for fuzzy searching terminal history is amazing. Also you can do * and hit tab and use fzf to grab a file to use as a command line argument.

Fzf is wonderful.

My biggest tip is to use the '**' shortcut from bash/zsh. My most frequent use case is for running tests, I can type:

   $ be rspec spec/**{tab}

Fzf will open inline, select the file(s) you want and run them (like this https://asciinema.org/a/mYTmT908gvVxZTMAsfPxltULx)

To get this to work I had to add this line to my .zshrc

source /usr/share/zsh/site-functions/fzf

If you don't have the globstar optional behavior enabled in bash this won't work.

From the manual:

If set, the pattern ‘*’ used in a filename expansion context will match all files and zero or more directories and subdirectories. If the pattern is followed by a ‘/’, only directories and subdirectories match.

To enable:

    $ shopt -s globstar
To disable:

    $ shopt -u globstar
Why does it use "sudo" in the first place when systemd uses PolicyKit for proper fine-grained/action-specific privilege acquisition out-of-the-box?
Wait, does that mean I'm supposed to use systemctl without sudo, and just type my password when it prompts me?
If PolicyKit is functioning correctly on your system, then yes. In my experience, though, a working PolicyKit is not something you can count on with server installs and minimal installs.
This is a really interesting example of the virtue of small general tools that can be combined in useful ways. Kudos.
> Runs sudo automatically and only if necessary

So never? Because systemctl by default triggers a PolicyKit prompt when run without sufficient privileges. sudo is entirely unnecessary.

Is polkit a hard requirement? I seem to recall systems where sudo was always needed for systemd stuff. Polkit was either not installed or somehow disabled.
Now that I looked, Debian lists it under ‘Suggests’, so apparently it’s not mandatory. Still, I get the impression it’s at least preferred.
(comment deleted)
Polkit is compile-time optional in systemd, debian has it disabled by default.