diff --git a/README.md b/README.md index 51e2510..71e584f 100644 --- a/README.md +++ b/README.md @@ -13,24 +13,16 @@ Execute `firestarter` in your `.xinitrc`, either by replacing the file or by `ex On first run and when invoked with `firestarter -g`, Firestarter will generate a series of configuration files in `~/.config/firestarter`. These files consist of several lines that look somewhat like the following: ```bash +#.fsdefaults command -v i3 i3 +command -v openbox +openbox ``` -Every odd line is a command that must succeed in order for the following even line to be executed. Once an even command is executed, parsing stops. When Firestarter is invoked with no arguments, every configuration file is parsed this way. +Every first uncommented line is a "check" command that must succeed in order for the following "target" line to be executed. Once a target command is selected, parsing stops and the target is executed. When Firestarter is invoked with no arguments, any file with a first line of `#.fsdefaults` is parsed this way. -This approach allows for a single file to contain very many alternatives while still being readable and supporting arbitrary launch requirements (such as in the case of Polybar, which requires a `launch.sh` script by default). - -By setting a dummy execution line, one can effectively prevent an entire configuration file from being parsed in certain environments. As an example, the following configuration file will only attempt to start an X infobar in an X environment: - -```bash -[ -z "$DISPLAY" ] -: -command -v polybar -polybar bar -command -v lemonbar -~/.bin/lemonbar.sh | lemonbar -``` +Any file that does *not* have the initial "crunchdot" is executed normally. You can keep shell scripts or symlinks in here and they will be executed without issue. After all these programs have been started, firestarter starts XDG autostart applications and executes `~/.firestarterrc` if it exists. diff --git a/firestarter b/firestarter index 0d75088..f22180b 100755 --- a/firestarter +++ b/firestarter @@ -60,7 +60,19 @@ gettarget() { [ -r "$1" ] || return 1 # Every odd line is the check line # Every even one is the exec line + local firstline while read -r checkline; do + if [ -z "$firstline" ]; then + if [ "$checkline" = "#.fsdefaults" ]; then + firstline=1 + continue + else + return 50 + fi + fi + if [ "${checkline#"#"}" != "$checkline" ]; then + continue + fi read -r execline if bash -c "$checkline" > /dev/null 2>&1; then _return="$execline" @@ -78,11 +90,13 @@ step_generate() { log "See firestarter -h for more information" # Audio daemon cat << EOF > "$_configdir/audio-daemon" +#.fsdefaults command -v pulseaudio pulseaudio EOF # Information bars cat << EOF > "$_configdir/bar" +#.fsdefaults command -v tint2 tint2 command -v polybar && [ -r "$HOME/.config/polybar/launch.sh" ] @@ -98,6 +112,7 @@ xfce4-panel EOF # Blue light filter cat << EOF > "$_configdir/blue-light-filter" +#.fsdefaults command -v redshift-gtk redshift-gtk command -v redshift @@ -105,6 +120,7 @@ redshift EOF # Compositor cat << EOF > "$_configdir/compositor" +#.fsdefaults [ -z "\$DISPLAY" ] : command -v unagi @@ -116,6 +132,7 @@ xcompmgr EOF # Polkit authentication agents cat << EOF > "$_configdir/polkit-agent" +#.fsdefaults command -v lxqt-policykit-agent lxqt-policykit-agent command -v lxpolkit @@ -141,6 +158,7 @@ polkit-efl-authentication-agent-1 EOF # Hotkey daemon cat << EOF > "$_configdir/hotkey-daemon" +#.fsdefaults [ -z "\$DISPLAY" ] : command -v sxhkd @@ -148,11 +166,13 @@ sxhkd EOF # Network daemon cat << EOF > "$_configdir/network-daemon" +#.fsdefaults command -v nm-applet nm-applet EOF # Notification daemon cat << EOF > "$_configdir/notification-daemon" +#.fsdefaults [ -z "\$DISPLAY" ] : command -v dunst @@ -162,6 +182,7 @@ notificationd EOF # Power daemons cat << EOF > "$_configdir/power-daemon" +#.fsdefaults command -v batterymon batterymon command -v cbatticon @@ -178,11 +199,13 @@ EOF # Runners # Note that rofi is not a daemon and is not included here cat << EOF > "$_configdir/runner" +#.fsdefaults command -v krunner krunner EOF # Settings daemons cat << EOF > "$_configdir/settings-daemon" +#.fsdefaults command -v xsettingsd xsettingsd command -v xsettings-kde @@ -198,6 +221,7 @@ EOF # Note: the dumb sleep hack is because Conky crashes with window_type override if the WM hasn't loaded yet # This gives the Wm ample time to load up cat << EOF > "$_configdir/stat-glances" +#.fsdefaults [ -z "\$DISPLAY" ] : command -v conky && [ -r "\${XDG_CONFIG_HOME:-$HOME/.config}/conky/conky.conf" ] @@ -205,6 +229,7 @@ sleep 5 && conky EOF # Wallpaper setters cat << EOF > "$_configdir/wallpaper" +#.fsdefaults [ -z "\$DISPLAY" ] : command -v feh && [ -r "$HOME/.fehbg" ] @@ -214,6 +239,7 @@ nitrogen --restore EOF # Window managers cat << EOF > "$_configdir/wm" +#.fsdefaults [ -z "\$DISPLAY" ] : command -v 2bwm @@ -422,6 +448,7 @@ step_execute() { local logfile="$_logdir/$filename" [ -n "$FS_NOLOG" ] && logfile="/dev/null" if gettarget "$file"; then + # It's a defaults file with a selected target target="$_return" log "Found target for \"$filename\": \"$target\"" if [ -z "$_dryrun" ]; then @@ -431,6 +458,12 @@ step_execute() { fi bash -c "$target" > "$logfile" 2>&1 & fi + elif [ $? = 50 ] && [ -x "$file" ]; then + # It's a shell script or something + log "Executing file straight out: \"$filename\"" + if [ -z "$_dryrun" ]; then + "$file" > "$logfile" 2>&1 & + fi fi done }