diff --git a/meson.build b/meson.build index e87c8ea2ecd..0865c861ecf 100644 --- a/meson.build +++ b/meson.build @@ -233,6 +233,7 @@ if shellprofiledir == '' shellprofiledir = sysconfdir / 'profile.d' endif conf.set10('LINK_SHELL_EXTRA_DROPIN', shellprofiledir != 'no' and not shellprofiledir.startswith('/usr/')) +conf.set10('LINK_OSC_CONTEXT_DROPIN', shellprofiledir != 'no' and not shellprofiledir.startswith('/usr/')) conf.set('SHELLPROFILEDIR', shellprofiledir, description : 'shell profile directory') memory_accounting_default = get_option('memory-accounting-default') diff --git a/profile.d/80-systemd-osc-context.sh b/profile.d/80-systemd-osc-context.sh new file mode 100644 index 00000000000..59af2e1cde4 --- /dev/null +++ b/profile.d/80-systemd-osc-context.sh @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +# shellcheck shell=bash +# shellcheck disable=SC2016 +# shellcheck disable=SC1003 + +# This file is part of systemd. +# +# systemd is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. + +__systemd_osc_context_escape() { + # Escape according to the OSC 8003 spec. Since this requires shelling out + # to 'sed' we'll only do it where it's strictly necessary, and skip it when + # processing strings we are pretty sure we won't need it for, such as + # uuids, id128, hostnames, usernames, since they all come with syntax + # requirements that exclude \ and ; anyway. This hence primarily is about + # escaping the current working directory. + echo "$1" | sed -e 's/\\/\\x5x/g' -e 's/;/\\x3b/g' +} + +__systemd_osc_context_common() { + printf ";user=%s;hostname=%s;machineid=%s;bootid=%s;pid=%s" "$USER" "$HOSTNAME" "$(