From 7a668fb17edb0d6ce39893684016054a5e45adb2 Mon Sep 17 00:00:00 2001 From: Carl Andersson Date: Wed, 7 May 2025 21:00:15 +0200 Subject: [PATCH] Unset SYSTEMD_COLORS for systemd completion Fixes an issue where systemctl and other systemd commands completions are prefixed by ANSI color escape codes --- share/functions/__fish_systemctl.fish | 3 +++ share/functions/__fish_systemctl_services.fish | 3 +++ share/functions/__fish_systemd_machine_images.fish | 3 +++ share/functions/__fish_systemd_machines.fish | 3 +++ 4 files changed, 12 insertions(+) diff --git a/share/functions/__fish_systemctl.fish b/share/functions/__fish_systemctl.fish index b6aee1a5b..2e9e52d7a 100644 --- a/share/functions/__fish_systemctl.fish +++ b/share/functions/__fish_systemctl.fish @@ -1,4 +1,7 @@ function __fish_systemctl --description 'Call systemctl with some options from the current commandline' + # We don't want to complete with ANSI color codes + set -lu SYSTEMD_COLORS + # These options are all global - before or after subcommand/arguments. # There's a bunch of long-only options in here, so we need to be creative with the mandatory short version. set -l opts t/type= s-state= p/property= a/all diff --git a/share/functions/__fish_systemctl_services.fish b/share/functions/__fish_systemctl_services.fish index d422e67ac..8e956f12b 100644 --- a/share/functions/__fish_systemctl_services.fish +++ b/share/functions/__fish_systemctl_services.fish @@ -1,4 +1,7 @@ function __fish_systemctl_services + # We don't want to complete with ANSI color codes + set -lu SYSTEMD_COLORS + if type -q systemctl if __fish_contains_opt user systemctl --user list-unit-files --full --no-legend --no-pager --plain --type=service 2>/dev/null $argv | string split -f 1 ' ' diff --git a/share/functions/__fish_systemd_machine_images.fish b/share/functions/__fish_systemd_machine_images.fish index c14865a0a..0b40434a6 100644 --- a/share/functions/__fish_systemd_machine_images.fish +++ b/share/functions/__fish_systemd_machine_images.fish @@ -1,6 +1,9 @@ # Like for running machines, I'm assuming machinectl doesn't allow spaces in image names # This does not include the special image ".host" since it isn't valid for most operations function __fish_systemd_machine_images + # We don't want to complete with ANSI color codes + set -lu SYSTEMD_COLORS + machinectl --no-legend --no-pager list-images | while read -l a b echo $a end diff --git a/share/functions/__fish_systemd_machines.fish b/share/functions/__fish_systemd_machines.fish index a4ab375f7..09f49dc08 100644 --- a/share/functions/__fish_systemd_machines.fish +++ b/share/functions/__fish_systemd_machines.fish @@ -1,5 +1,8 @@ # It seems machinectl will eliminate spaces from machine names so we don't need to handle that function __fish_systemd_machines + # We don't want to complete with ANSI color codes + set -lu SYSTEMD_COLORS + machinectl --no-legend --no-pager list --all | while read -l a b echo $a end