Earnestly / sx

Start an xorg server
MIT License
231 stars 16 forks source link

sx: only create $datadir if $XAUTHORITY is unset #34

Closed 62832 closed 5 months ago

62832 commented 5 months ago

In case of an alternative location for $XAUTHORITY, there isn't much need to keep creating a potentially empty directory.

Earnestly commented 5 months ago

This would be better done by creating the datadir if XAUTHORITY maintains its default value. E.g.


cfgdir=${XDG_CONFIG_HOME:-$HOME/.config}/sx
datadir=${XDG_DATA_HOME:-$HOME/.local/share}/sx

mkdir -p -- "$cfgdir"

export XAUTHORITY="${XAUTHORITY:-$datadir/xauthority}"

if [ "$XAUTHORITY" = "$datadir"/xauthority ]; then
    mkdir -p -- "$datadir"
fi

touch -- "$XAUTHORITY"

However, while this feature is not unreasonable, I want to avoid these sorts of complications. I may reconsidered this in the future so I'm only closing for now.

62832 commented 5 months ago

Actually, now that I think about it, simpler yet would be something like this, eliminating the need for a conditional at all.

datadir=${XDG_DATA_HOME:-$HOME/.local/share}/sx
export XAUTHORITY="${XAUTHORITY:-$datadir/xauthority}"
mkdir -p -- "$(dirname "$XAUTHORITY")"
touch -- "$XAUTHORITY"
Earnestly commented 5 months ago

You can typically avoid the use of dirname by using parameter expansions (caveat values of / or those ending with /), e.g. mkdir -p -- "${XAUTHORITY%/*}". In this case it could then also be combined with "$cfgdir", i.e. mkdir -p -- "$cfgdir" "${XAUTHORITY%/*}".