# 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. # Not bash? [ -n "${BASH_VERSION:-}" ] || return 0 # If we're on a "dumb" terminal, do not install the prompt. # Treat missing $TERM same as "dumb". [ "${TERM:-dumb}" = "dumb" ] && return 0 __systemd_osc_context_escape() { # Escape according to the OSC 3008 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() { if [ -f /etc/machine-id ]; then printf ";machineid=%s" "$(/dev/null)" ] || PROMPT_COMMAND+=('') # Whenever a new prompt is shown, close the previous command, and prepare new command PROMPT_COMMAND+=(__systemd_osc_context_precmdline) # PS0 is shown right after a prompt completed, but before the command is executed PS0='$(__systemd_osc_context_ps0)'"${PS0:-}" fi