Skip to content

Use systemd-style Environment files to pass variables via session.sh and assign-cgroups.py #27

@snakeroot

Description

@snakeroot

Another run at #6 .

Would you consider modifying session.sh so that it looks for an "Environment" file in a pre-defined location, and, if the file exists, sources the variables in that file and then adds them to the $VARIABLES list alongside the default variables hardcoded in the script and those passed in via -E?

This has the advantage of leveraging a broadly-used format (i.e, you can crib from people using .profile or /etc/environment.d). It also should mean that the file won't get overwritten when sway-systemd is upgraded (unlike changes to -E in 10-systemd-session.conf).

I stuck this language into my session.sh and, while it's not pretty it does seem to work:

set_var(){
        . ${1}
        while read -r line; do
                if [[ $(echo $line | grep -v ^#) ]]; then
                        line=${line%=*}
                        export ${line}
                        VARIABLES="${VARIABLES} ${line}"
                fi
        done < ${1}
}

if [[ -e ~/.config/sway-systemd/env ]]; then
        set_var ~/.config/sway-systemd/env
fi

Similarly, would it be possible to do something similar for the transient scope units created by assign-cgroups.py? It seems one could parse an Environment file and submit the name/value pairs via the systemd d-bus API's SetEnvironment() method. Since a lot of the commonly-used environment variables are used to persuade GUI programs to use wayland, this might prove useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions