Skip to content
Myr

✨ Add {cmd} in --terminal command, like Rofi. (#600)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

{cmd} may appear more than once. If it appears at all, it it not also appended. Fixes #564 ## QA Log Tested with: ``` /pkg/fuzzel/usr/bin/fuzzel --config=test_terminal.ini ``` Where test_terminal.ini contains: ``` [main] terminal=foot -a '{cmd}' -T '{cmd}' {cmd} ``` Then I checked the title and app_id to confirm that they were both set to the command. For terminals like foot that allow setting the app_id and title, this is a nicer default.

authored by Mark Stosberg · committed by markstos · parent 0baffbd · Browse files · 4 files+82 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Reviewed-on: https://codeberg.org/dnkl/fuzzel/pulls/600
  • Co-authored-by: Mark Stosberg <mark@stosberg.com>
  • Co-committed-by: Mark Stosberg <mark@stosberg.com>

Diff stats

4 files+82 added−4 removed

  • other:+82 added−4 removed

4 files+82 added−4 removed

modified:doc/fuzzel.1.scd+14 added-1 removed
176 unmodified lines
177 _CHARACTER_ is omitted, a *\** will be used.178179*-T*,*--terminal*=_TERMINAL ARGS_180 Command to launch XDG applications with the property181 *Terminal=true* (_htop_, for example). Example: _xterm -e_.181 *Terminal=true* (_htop_, for example).182183 The command may contain the placeholder _{cmd}_ which will be184 replaced with the actual command to be run. When _{cmd}_ is present,185 the command is **only** substituted in those locations and is **not**186 appended at the end.187188 Examples:189 - _foot -a '{cmd}' -T '{cmd}' {cmd}_ sets app-id and title to the190 command name, then executes it191 - _xterm -e {cmd}_ executes the command in xterm192 - _xterm -e_ (no {cmd}) uses old behavior: appends command after193 terminal args194195 Default: _not set_.196197*-a*,*--anchor*=_ANCHOR_198 Set window anchor, i.e. where on screen the window will be
381 unmodified lines
modified:doc/fuzzel.ini.5.scd+15 added-2 removed
225 unmodified lines
226 etc. When this option is enabled, those actions will be listed by227 fuzzel. Default: _no_.228229*terminal*230 terminal command to use when launching 'terminal' programs,231 e.g. \"xterm -e\". Default: _$TERMINAL -e_.230 terminal command to use when launching 'terminal' programs.231232 The command may contain the placeholder _{cmd}_ which will be233 replaced with the actual command to be run. When _{cmd}_ is present,234 the command is **only** substituted in those locations and is **not**235 appended at the end.236237 Examples:238 - _foot -a '{cmd}' -T '{cmd}' {cmd}_ sets app-id and title to the239 command name, then executes it240 - _xterm -e {cmd}_ executes the command in xterm241 - _xterm -e_ (no {cmd}) uses old behavior: appends command after242 terminal args243244 Default: _$TERMINAL -e_.245246*list-executables-in-path*247 Boolean. When enabled, the list will include executables248 from the PATH environment variable. Default: _no_.249
446 unmodified lines
modified:CHANGELOG.md+5 added
46 unmodified lines
47* `--minimal-lines` command line and config option, causing fuzzel to48 adjust the number of displayed lines to the minimum of `--lines` and49 the number of input lines ([#144][144])50* Touchscreen support ([#594][594])51* `{cmd}` placeholder support in the `terminal` option. When `{cmd}` is52 present in the terminal command string, it will be replaced with the53 application command instead of appending the command at the end. Useful54 for setting the title or app_id. ([#600][600])5556[504]: https://codeberg.org/dnkl/fuzzel/pulls/50457[512]: https://codeberg.org/dnkl/fuzzel/pulls/51258[546]: https://codeberg.org/dnkl/fuzzel/issues/54659[553]: https://codeberg.org/dnkl/fuzzel/issues/55360[144]: https://codeberg.org/dnkl/fuzzel/issues/14461[594]: https://codeberg.org/dnkl/fuzzel/issues/59462[600]: https://codeberg.org/dnkl/fuzzel/issues/6006364### Changed6566* Scrolling speed is now line-by-line instead of page-by-page ([#586][586])
957 unmodified lines
modified:xdg.c+48 added-1 removed
1#include "xdg.h"23#include <assert.h>4#include <ctype.h>5#include <errno.h>6#include <limits.h>7#include <locale.h>
394 unmodified lines
402 if (a->name == NULL)403 a->name = ambstoc32("<no title>");404405 if (a->use_terminal && terminal != NULL && a->exec != NULL) {405 char *exec_with_terminal = xstrjoin3(terminal, " ", a->exec);406 char *exec_with_terminal;407408 // Check if terminal command contains {cmd} placeholder409 if (strstr(terminal, "{cmd}") != NULL) {410 // Replace all occurrences of {cmd} with the actual command411 const char *placeholder = "{cmd}";412 const size_t placeholder_len = 5; // strlen("{cmd}")413 const size_t exec_len = strlen(a->exec);414 const size_t terminal_len = strlen(terminal);415416 // Count occurrences of {cmd}417 size_t occurrences = 0;418 const char *pos = terminal;419 while ((pos = strstr(pos, placeholder)) != NULL) {420 occurrences++;421 pos += placeholder_len;422 }423424 // Calculate final string size425 assert(terminal_len >= occurrences * placeholder_len); // should be true, so let's assert it is426 size_t final_len = terminal_len - occurrences * placeholder_len + occurrences * exec_len + 1;427 exec_with_terminal = xmalloc(final_len);428429 // Replace all {cmd} occurrences430 const char *src = terminal;431 char *dst = exec_with_terminal;432 while ((pos = strstr(src, placeholder)) != NULL) {433 // Copy part before {cmd}434 size_t prefix_len = pos - src;435 memcpy(dst, src, prefix_len);436 dst += prefix_len;437438 // Copy the exec command439 memcpy(dst, a->exec, exec_len);440 dst += exec_len;441442 // Move past {cmd}443 src = pos + placeholder_len;444 }445446 // Copy remaining part447 strcpy(dst, src);448 } else {449 // Use the old behavior: "terminal command exec"450 exec_with_terminal = xstrjoin3(terminal, " ", a->exec);451 }452453 free(a->exec);454 a->exec = exec_with_terminal;455 }456
405 unmodified lines