aboutsummaryrefslogtreecommitdiffstats
path: root/modules/by-name/ly/ly/setup.sh
blob: 6e8bed2b74ddd67385fcb256902aae051dc48180 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/env bash

# Shared environment setup for graphical sessions.

# shellcheck disable=1091
. /etc/profile

cd "$HOME" || {
    echo 1>&2 "No HOME :("
    exit 1
}

if [ -z "$_DID_SYSTEMD_CAT" ]; then
  export _DID_SYSTEMD_CAT=1
  exec systemd-cat -t xsession "$0" "$@"
fi


# Import environment variables into the systemd user environment.
/run/current-system/systemd/bin/systemctl --user import-environment DBUS_SESSION_BUS_ADDRESS DISPLAY XAUTHORITY XDG_SESSION_ID

# Speed up application start by 50-150ms according to
# https://kdemonkey.blogspot.com/2008/04/magic-trick.html
compose_cache="${XCOMPOSECACHE:-$HOME/.compose-cache}"
mkdir -p "$compose_cache"
# To avoid accidentally deleting a wrongly set up XCOMPOSECACHE directory,
# defensively try to delete cache *files* only, following the file format specified in
# https://gitlab.freedesktop.org/xorg/lib/libx11/-/blob/master/modules/im/ximcp/imLcIm.c#L353-358
# sprintf (*res, "%s/%c%d_%03x_%08x_%08x", dir, _XimGetMyEndian(), XIM_CACHE_VERSION, (unsigned int)sizeof (DefTree), hash, hash2);
find "$compose_cache" -maxdepth 1 -regextype posix-extended -regex '.*/[Bl][0-9]+_[0-9a-f]{3}_[0-9a-f]{8}_[0-9a-f]{8}' -delete
unset compose_cache

# Work around KDE errors when a user first logs in and
# .local/share doesn't exist yet.
mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}"

unset _DID_SYSTEMD_CAT


if test "$1"; then
    # Run the supplied session command.
    exec "$@"
else
    # TODO: Do we need this? Should not the session always exist?
    echo "error: unknown session $1" 1>&2
    exit 1
fi