20
850
Fork
You've already forked fuzzel
83

Add support for file based configuration #3

Closed
opened 2020年06月17日 20:03:50 +02:00 by dnkl · 18 comments
Owner
Copy link

Currently, all configuration is done using command line options. This is fine as long as you only use fuzzel in a single context.

But, as we add more options, this approach falls apart.

So, let's add file based configuration (using normal Unix conf syntax). The existing command line options will remain, and if present will override the file based "default" configuration.

Currently, all configuration is done using command line options. This is fine as long as you only use fuzzel in a single context. But, as we add more options, this approach falls apart. So, let's add file based configuration (using normal Unix conf syntax). The existing command line options will remain, and if present will override the file based "default" configuration.
Contributor
Copy link

My solution to this is a fuzzel.sh script in my path which holds my configuration and passes along stdin and any arguments to fuzzel.

#!/bin/sh
fuzzel -f cozette:size=10 -T footclient -w 64 -b 002b36ff -t 839496ff \
	-m dc322fff -s 073642ff -B 2 -r 0 -C 839496ff $@ <&0

then the script can either be invoked directly, or used in a dmenu like fashion with

$ ls -l | fuzzel.sh -d

For me at least, this makes file-based configuration unecessary.

My solution to this is a `fuzzel.sh` script in my path which holds my configuration and passes along stdin and any arguments to fuzzel. ``` #!/bin/sh fuzzel -f cozette:size=10 -T footclient -w 64 -b 002b36ff -t 839496ff \ -m dc322fff -s 073642ff -B 2 -r 0 -C 839496ff $@ <&0 ``` then the script can either be invoked directly, or used in a dmenu like fashion with ``` $ ls -l | fuzzel.sh -d ``` For me at least, this makes file-based configuration unecessary.
Author
Owner
Copy link

@ifreund thanks! Perhaps it is time I added a wiki for fuzzel; that script would certainly be worth mentioning there.

Oh, and I see cozette is a bitmap font! That I have never heard of. Going to have to try it out :)

@ifreund thanks! Perhaps it is time I added a wiki for fuzzel; that script would certainly be worth mentioning there. Oh, and I see cozette is a bitmap font! That I have never heard of. Going to have to try it out :)

I would suggest using an environment variable (for example FUZZLE_DEFAULT_OPTS) like fzf to define a default setting. Those can be overwritten by the the user if fuzzel is run with options that were defined inside the variable.
That can be another nice choice too, besides having a proper config file.

I would suggest using an environment variable (for example FUZZLE_DEFAULT_OPTS) like `fzf` to define a default setting. Those can be overwritten by the the user if `fuzzel` is run with options that were defined inside the variable. That can be another nice choice too, besides having a proper config file.
Collaborator
Copy link

I want to expand on the idea of the wrapper that @ifreund posted. I keep my configuration in a shell script I named fuzzel-configured that passes through additional arguments, like above:

fuzzel-configured

#!/bin/sh
fuzzel \
 --dpi-aware=no\
 --width=25\
 --font='Hack:weight=bold:size=36'\
 --background-color='282a36fa'\
 --selection-color='3d4474fa'\
 --line-height=50\
 --border-radius=20\
 $@

Then I have two more wrapper scripts-- one with args specific to dmenu mode and one with argumement specific to launcher mode.

fuzzel-dmenu

#!/bin/sh
fuzzel-configured --dmenu --no-run-if-empty

This dmenu script serves a second purpose as well. With it, I can create a symlink from dmenu to this binary, so it can handle scripts that expect dmenu to exist.

Fuzzel could make this smoother by recognizing when it has been called as a binary named dmenu and automatically enabled --dmenu mode in that case. This is a feature of Rofi.

fuzzel-launcher

#!/bin/sh
fuzzel-configured --show-actions

Working with and without configuration

In scripts, it's possible to check to see if there's a fuzzel wrapper present and if so use it:

_fuzzel_exec=fuzzel
if which fuzzel-configured &>/dev/null; then
 _fuzzel_exec=fuzzel-configured
fi

But a config file would still be nicer

The above pattern allows you to keep fuzzel configs in a single file, the wrapper file. But if the configuration could be loaded from ~/.config/fuzzel/fuzzel.conf, that would be a welcome convenience and standization.

I want to expand on the idea of the wrapper that @ifreund posted. I keep my configuration in a shell script I named `fuzzel-configured` that passes through additional arguments, like above: ## fuzzel-configured ```sh #!/bin/sh fuzzel \ --dpi-aware=no\ --width=25\ --font='Hack:weight=bold:size=36'\ --background-color='282a36fa'\ --selection-color='3d4474fa'\ --line-height=50\ --border-radius=20\ $@ ``` Then I have two more wrapper scripts-- one with args specific to dmenu mode and one with argumement specific to launcher mode. ## fuzzel-dmenu ```sh #!/bin/sh fuzzel-configured --dmenu --no-run-if-empty ``` This dmenu script serves a second purpose as well. With it, I can create a symlink from `dmenu` to this binary, so it can handle scripts that expect `dmenu` to exist. Fuzzel could make this smoother by recognizing when it has been called as a binary named `dmenu` and automatically enabled `--dmenu` mode in that case. This is a feature of Rofi. ## fuzzel-launcher ```sh #!/bin/sh fuzzel-configured --show-actions ``` ## Working with and without configuration In scripts, it's possible to check to see if there's a fuzzel wrapper present and if so use it: ```sh _fuzzel_exec=fuzzel if which fuzzel-configured &>/dev/null; then _fuzzel_exec=fuzzel-configured fi ``` ## But a config file would still be nicer The above pattern allows you to keep fuzzel configs in a single file, the wrapper file. But if the configuration could be loaded from `~/.config/fuzzel/fuzzel.conf`, that would be a welcome convenience and standization.
Collaborator
Copy link

For me at least, this makes file-based configuration unecessary.

With file-based configuration it would be easier themes, especially if there was an include-file syntax, so you could import a theme file that might be published by a third party and add some personal overrides.

Imagine a WM or DE that wanted to ship a themed version of Fuzzel

> For me at least, this makes file-based configuration unecessary. With file-based configuration it would be easier themes, especially if there was an include-file syntax, so you could import a theme file that might be published by a third party and add some personal overrides. Imagine a WM or DE that wanted to ship a themed version of Fuzzel

I'm trying to support fuzzel for tessen and the lack of a file based configuration is a problem. The same issue is present in bemenu.

For some context, some users prefer to use different options for their dmenu operations when used with different programs. This isn't easy to implement using wrapper shell scripts and seems like an ugly hack. Environment variables don't really help either. Yeah, a user can do something like env FUZZEL_FONT=... FUZZEL_BG=... tessen -b fuzzel but that is even more ugly and messy. As @dnkl wrote in the very first comment, when multiple contexts are involved, wrapper shell scripts and environment variables don't work.

The support for environment variables in bemenu feels like a hack and completely unneccesary so I'd suggest not to go down that route with fuzzel, unless someone fancies having monstrosity like this in their wrapper shell scripts or in their .profile file.

If fuzzel would support using a configuration file for its configuration, that would go a long way in wayland having a decent dmenu program. Allowing users to do fuzzel -c $XDG_CONFIG_HOME/fuzzel/whatever-you-want-depending-on-the-context.ini solves this issue.

I'm trying to support fuzzel for [tessen](https://github.com/ayushnix/tessen) and the lack of a file based configuration is a problem. The same issue is present in [bemenu](https://github.com/Cloudef/bemenu/issues/15). For some context, some users prefer to use different options for their dmenu operations when used with different programs. This isn't easy to implement using wrapper shell scripts and seems like an ugly hack. Environment variables don't really help either. Yeah, a user can do something like `env FUZZEL_FONT=... FUZZEL_BG=... tessen -b fuzzel` but that is even more ugly and messy. As @dnkl wrote in the very first comment, when multiple contexts are involved, wrapper shell scripts and environment variables don't work. The support for environment variables in bemenu feels like a hack and completely unneccesary so I'd suggest not to go down that route with fuzzel, unless someone fancies having [monstrosity like this](https://github.com/ayushnix/dotfiles/blob/a65472d1ea80e350c9bff56df3a58a730f8e9127/dot_bash_profile#L37) in their wrapper shell scripts or in their `.profile` file. If fuzzel would support using a configuration file for its configuration, that would go a long way in wayland having a decent dmenu program. Allowing users to do `fuzzel -c $XDG_CONFIG_HOME/fuzzel/whatever-you-want-depending-on-the-context.ini` solves this issue.
Author
Owner
Copy link

There weren't that many options when this ticket was opened. Today, there are quite a few more, and that has made my start to tip over in favor of file-based configuration.

There weren't _that_ many options when this ticket was opened. Today, there are quite a few more, and that has made my start to tip over in favor of file-based configuration.
Collaborator
Copy link

Until this gets implemented in C, a workaround is to create a shell script called fuzzel-configured, which reads ~/.config/fuzzel/fuzzel.ini then transforms the arguments into CLI arguments that are passed to fuzzel.

It's still ugly, but will be close to 100% forward-compatible with a proper fix. For example, consider a ~/.config/fuzzel/fuzzel.inithat exactly mirrors the command line args:

width=25
font='Hack:weight=bold:size=36'

That can be parsed and convered into arguments for fuzzel like this:

❯ awk 'BEGIN{ORS=" "; print "fuzzel"} /=/ { print "--"0ドル }' ~/.config/fuzzel/fuzzel.ini 
fuzzel --width=25 --font='Hack:weight=bold:size=36' ⏎ 

To avoid having a wrapper named "fuzzel-configured", you could also name the binary ~/.local/bin/fuzzel" and make sure this "bin" directory comes first in $PATH. Then have your awk script print out /usr/bin/fuzzel to call the "real" fuzzel.

In this way, it will appear to other apps that fuzzel supports file-based configuration.

Until this gets implemented in C, a workaround is to create a shell script called `fuzzel-configured`, which reads `~/.config/fuzzel/fuzzel.ini` then transforms the arguments into CLI arguments that are passed to `fuzzel`. It's still ugly, but will be close to 100% forward-compatible with a proper fix. For example, consider a `~/.config/fuzzel/fuzzel.ini`that exactly mirrors the command line args: ``` width=25 font='Hack:weight=bold:size=36' ``` That can be parsed and convered into arguments for `fuzzel` like this: ``` ❯ awk 'BEGIN{ORS=" "; print "fuzzel"} /=/ { print "--"0ドル }' ~/.config/fuzzel/fuzzel.ini fuzzel --width=25 --font='Hack:weight=bold:size=36' ⏎ ``` To avoid having a wrapper named "fuzzel-configured", you could also name the binary ~/.local/bin/fuzzel" and make sure this "bin" directory comes first in $PATH. Then have your awk script print out `/usr/bin/fuzzel` to call the "real" fuzzel. In this way, it will appear to other apps that fuzzel supports file-based configuration.

Thanks for suggesting this but I don't think a lack of workarounds is an issue at this moment. I can use them personally but I can't recommend them in a README page or add support for them in another project.

Thanks for suggesting this but I don't think a lack of workarounds is an issue at this moment. I can use them personally but I can't recommend them in a README page or add support for them in another project.

I suggest that this feature will include a logic that will fall back to a global system config file before loading the compiled defaults. That's in case that a config file wasn't detected in the user's home.

I suggest that this feature will include a logic that will fall back to a global system config file before loading the compiled defaults. That's in case that a config file wasn't detected in the user's home.
Author
Owner
Copy link

Based on the input here, my plan moving forward is:

  • ini-file syntax (like foot)
  • look for fuzzel/fuzzel.ini in:
    • $XDG_CONFIG_HOME (~/.config if unset)
    • XDG_CONFIG_DIRS (/etc if unset)
    • builtin defaults
  • Have config file sections and options match the command line options, both in name and syntax, as far as possible.
  • Command line options obviously override the config file
  • Add an include "option" (similar to foot's)

Did I miss something?

Based on the input here, my plan moving forward is: * ini-file syntax (like foot) * look for `fuzzel/fuzzel.ini` in: - `$XDG_CONFIG_HOME` (`~/.config` if unset) - `XDG_CONFIG_DIRS` (`/etc` if unset) - builtin defaults * Have config file sections and options match the command line options, both in name and syntax, as far as possible. * Command line options obviously override the config file * Add an `include` "option" (similar to foot's) Did I miss something?

Did I miss something?

Nope, sounds good to me. The include option would be very useful as well.

> Did I miss something? Nope, sounds good to me. The `include` option would be very useful as well.
Contributor
Copy link

Not sure if this should be a separate issue because keybindings are only possible in a config file, but custom keybindings please - arrow keys are hard to reach on laptop keyboards

Edit: found out C-n and C-p, don't know how to select an entry other than RET though

In any case, I use C-j/k and C-h for completion in neovim so having a single set of keybindings would be nice (especially as I use fuzzel for vim.ui.select)

Not sure if this should be a separate issue because keybindings are only possible in a config file, but custom keybindings please - arrow keys are hard to reach on laptop keyboards Edit: found out C-n and C-p, don't know how to select an entry other than RET though In any case, I use C-j/k and C-h for completion in neovim so having a single set of keybindings would be nice (especially as I use fuzzel for [vim.ui.select](https://neovim.io/doc/user/lua.html#vim.ui.select()))
Author
Owner
Copy link

Not sure if this should be a separate issue because keybindings are only possible in a config file, but custom keybindings please - arrow keys are hard to reach on laptop keyboards

I'd say it's a separate issue, and one that I agree should be implemented.

don't know how to select an entry other than RET though

Right, there isn't one (except tab when there's only a single match).

In any case, I use C-j/k and C-h for completion in neovim so having a single set of keybindings would be nice (especially as I use fuzzel for vim.ui.select)

As long as they don't collide with the existing bindings, I'd be happy to add vim-like bindings.

> Not sure if this should be a separate issue because keybindings are only possible in a config file, but custom keybindings please - arrow keys are hard to reach on laptop keyboards I'd say it's a separate issue, and one that I agree should be implemented. > don't know how to select an entry other than RET though Right, there isn't one (except <kbd>tab</kbd> when there's only a single match). > In any case, I use C-j/k and C-h for completion in neovim so having a single set of keybindings would be nice (especially as I use fuzzel for vim.ui.select) As long as they don't collide with the existing bindings, I'd be happy to add vim-like bindings.
Contributor
Copy link

I'd say it's a separate issue, and one that I agree should be implemented.

Opened #117

As long as they don't collide with the existing bindings, I'd be happy to add vim-like bindings.

vim defaults are C-n/C-p too (and C-y for selecting) so nvm

> I'd say it's a separate issue, and one that I agree should be implemented. Opened #117 > As long as they don't collide with the existing bindings, I'd be happy to add vim-like bindings. vim defaults are C-n/C-p too (and C-y for selecting) so nvm
Author
Owner
Copy link

vim defaults are C-n/C-p too (and C-y for selecting) so nvm

We can add C-y immediately, as an alternative to Return. Then, when we implement custom key bindings, we'll keep it in the default set of bindings.

> vim defaults are C-n/C-p too (and C-y for selecting) so nvm We can add C-y immediately, as an alternative to Return. Then, when we implement custom key bindings, we'll keep it in the default set of bindings.
Contributor
Copy link

Thanks!

Thanks!
Author
Owner
Copy link
https://codeberg.org/dnkl/fuzzel/pulls/118
dnkl referenced this issue from a commit 2022年04月22日 19:58:52 +02:00
Sign in to join this conversation.
No Branch/Tag specified
master
gnome-support
releases/1.14
issue-319-window-switching
issue-561-nord-theme-only
resvg-filtering-take-2
resvg-filtering
releases/1.13
rehanzo-dont-ignore-execute-648
keybinds-overwrite
issue-561-refresh-theme
ci-automated-testing
reenable-legacy-icons
releases/1.12
test-coverage-for-fzf-caching
releases/1.11
releases/1.10
releases/1.9
releases/1.8
releases/1.7
releases/1.6
releases/1.5
releases/1.4
releases/1.3
releases/1.2
releases/1.1
releases/1.0
1.14.1
1.14.0
1.13.1
1.13.0
1.12.0
1.11.1
1.11.0
1.10.2
1.10.1
1.10.0
1.9.2
1.9.1
1.9.0
1.8.2
1.8.1
1.8.0
1.7.0
1.6.5
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.2
1.4.1
1.4.0
1.3.0
1.2.0
1.1.0
1.0.1
1.0.0
0.9.0
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
7 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dnkl/fuzzel#3
Reference in a new issue
dnkl/fuzzel
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?