#!/bin/bash set -euo pipefail # This is a helper wrapper script for greetd. # # It will run the session / application using the appropriate shell configured for # this user. That way, we can make sure all of the environment variables are set # before the WM/DE session is started. # # This is very important, as without it, variables for things like qt theme # will not be set, and applications executed by the WM/DE will not be themed properly. script_name="$0" shell="$(getent passwd "$USER" | awk -F: '{print $NF}')" command=("$@") # This syntax might be a bit confusing at first. It works as follows: # 1. Replace this wrapper process with the user's login shell (through exec) # 2. The shell is told to run 'exec $@' replacing itself with another process # 3. The $@ in the exec above referrs to the arguments passed the shell (after -c '...') # 4. "$script_name" is passed to the shell as $0 (process name), not included in $@ # 5. The ${command[@]} matches the $@ which this script was called with # -> The command passed into this script as args is ran within the user's shell exec "$shell" -c 'exec "$@"' "$script_name" "${command[@]}"