Hacker News new | past | comments | ask | show | jobs | submit login
Sysz – An fzf terminal UI for systemctl (github.com/joehillen)
367 points by ducktective 36 days ago | hide | past | favorite | 34 comments



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.


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 :).


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.


Does it suffice with systemd's bash completion? On debian it's bundled with systemd.

  systemd: /usr/share/bash-completion/completions/systemctl


With fzf-tab [1], you can use fzf wherever your zsh completion is. Here is a screencast showing it[2].

[1] https://github.com/Aloxaf/fzf-tab

[2] https://asciinema.org/a/KhDMhtZ3J8ppO7B8L6jFSE1co


Seems nice but it gets slow with long lists. Should lazy-load


I'm continually impressed at how many uses fzf has. Yet I still feel like we're only scratching the surface of its utility.


Did you know we can make unix tools (like jq) interactive (lik a REPL) using fzf?

https://news.ycombinator.com/item?id=28577337

Checkout Daniel's other scripts: https://github.com/DanielFGray/fzf-scripts


Yes! I have that one in my ```~/.fzf.zsh```


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...)


Off-topic, but TIL about Unlicense License from this project’s license. Was wondering how it differed from MIT and found this interesting thread: https://softwareengineering.stackexchange.com/questions/1471...


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.


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.


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.


I love fzf but somehow I can never find a way to naturally make it a part of my workflow.


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


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.


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.)


> 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.


Polkit is compile-time optional in systemd, debian has it disabled by default.


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.


This is a really interesting example of the virtue of small general tools that can be combined in useful ways. Kudos.


Looks like a useful tool, thanks for sharing!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: