Files
dotfiles/i3/i3/genconfig.bash
Hannes Körber 263efe3000 Added dynamic config generation for i3.
The script genconfig.bash concatenates the main configuration file with
a host specific one to create a session-specific configration file that
is then passed to i3. It therefore has to be called in .xinitrc or
something comparable before starting i3. If no host specific
configuration is found, a default file will be used instead. This is
useful for providing default that should not go into the main
configuration file, maybe because they are incompatible with some host
specific settings. For example a default bar{} block goes there, as if
this was in the main config, two i3bar instances would be started when a
host specific config specifies its own.
2013-09-18 19:57:01 +02:00

32 lines
1.0 KiB
Bash

#!/bin/bash
# main configuration file that is always used
MAIN_CONF="$HOME/.i3/config"
# temporary configuration file used for this session
SESSION_CONF="$HOME/.i3/session.config"
# directory that contains host specific configuration
CONF_DIR="$HOME/.i3/config.d"
# file that should be used when no host specific configuration present
DEFAULT_CONF="$CONF_DIR/default"
host_specific_conf="$CONF_DIR/$(hostname).config"
# if it's a symlink to $MAIN_CONF, cat will fail
[[ -f "$SESSION_CONF" ]] && rm "$SESSION_CONF"
if [[ ! -f "$host_specific_conf" ]] && [[ ! -f "$DEFAULT_CONF" ]]; then
# if there is no host-specific configuration and no default one, just use
# the main config
ln -sf "$MAIN_CONF" "$SESSION_CONF"
else
# either use the host specific config if present, or the default if not
if [[ -f "$host_specific_conf" ]]; then
conf_to_use="$host_specific_conf"
else
conf_to_use="$DEFAULT_CONF"
fi
cat "$MAIN_CONF" "$conf_to_use" > "$SESSION_CONF"
fi
echo "$SESSION_CONF"