Sample Header Ad - 728x90

startx function/alias has wrong arguments if not prefixed with exec

1 vote
0 answers
89 views
For context, my file/directory structure and contents are mostly copied from how it is in Luke Smith's dotfiles (voidrice ). Also, the "..." lines in the code blocks aren't code and represent omitted lines in the file. I have this in my ~/.zprofile:
#!/bin/zsh
...
export XINITRC="${XDG_CONFIG_HOME:-$HOME/.config}/x11/xinitrc"
And this in my aliases file that ~/.zshrc sources (~/.config/shell/aliasrc):
#!/bin/bash
...
esx() { exec startx "$XINITRC" "$@" -- -keeptty >~/xorg.log 2>&1; }
sx() { startx "$XINITRC" "$@" -- -keeptty >~/xorg.log 2>&1; }
(The "--" part of the functions' commands onwards is for logging ) This is what ~/.config/x11/xinitrc looks like:
#!/bin/sh
sysresources="/etc/X11/xinit/.Xresources"
userXprofile="${XDG_CONFIG_HOME:-$HOME/.config}/x11/xprofile" # empty file atm
[ -f "$sysresources" ] && xrdb -merge "$sysresources"
xrdb -merge ${XDG_CONFIG_HOME:-$HOME/.config}/x11/xresources & xrdbpid=$!
if [ -d /etc/X11/xinit/xinitrc.d ] ; then
 for f in /etc/X11/xinit/xinitrc.d/?*.sh ; do
  [ -x "$f" ] && . "$f"
 done
 unset f
fi
if [ -f "$userXprofile" ]; then
    . "$userXprofile"
else
    . "$HOME/.xprofile"
fi
[ -n "$xrdbpid" ] && wait "$xrdbpid"
case $1 in
   awesome|awesomeWM) exec awesome;;
   xfce|xfce4) exec startxfce4;;
   openbox) exec openbox;;
esac
Basically, the intention is to run either esx or sx with the name of whatever window manager or desktop environment I want to use for that particular session. It works properly with esx, but sx will pass the value of $XINITRC to ~/.config/x11/xinitrc as $1 instead of the WM/DE I picked. I tried "fixing" sx by excluding the first argument: sx() { startx "$XINITRC" "${@:2}" -- -keeptty >~/xorg.log 2>&1; } but xinitrc still has $1 as $XINITRC. As a band-aid fix, ~/.config/x11/xinitrc gets rid of the first positional argument if it's "$XINITRC":
[ "$1" = "$XINITRC" ] && shift
case $1 in
...
But I hate this solution and would much rather know why sx is screwing up in the first place. Does anyone know why this is happening?
Asked by zxcdv (11 rep)
Oct 3, 2022, 08:28 AM