Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Comments on How to append commands to startx from console

Parent

How to append commands to startx from console

+2
−0

MWE

startx && xrandr-invert-colors

Problem

It seems that anything after startx does not get issued in the resulting X session. I'd like to make a bash function that sets up my monitors based on which office I'm working out of. Assuming the *-display commands are xrandr commands, that can be substituted with xrandr-invert-colors:

office-one()
{
    startx
    office-one-display
}

office-two()
{
    startx
    office-two-display
}

Both of these are accessible from the console on startup, and both successfully startx, but everything after that has no effect.

Tried

Spinning until in an X session:

in_xsession()
{
    xhost &> /dev/null

    return !$?
}

office-one()
{
    startx
    until [ in_xsession ]; do done
    office-one-display
}

office-two()
{
    startx
    until [ in_xsession ]; do done
    office-two-display
}

but it has the same behavior.

Question

How do I "append" commands to startx such that they issue in the resulting X session? For convenience, I'd like to be able to do this from a bash function as shown.

Notes

I used xrandr-invert-colors for a visual effect, but you can replace that with any application launch like emacs, firefox, etc..

I am using zsh.

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+1
−1

From what I understand, you can pass a command to the xinit program that will be executed instead of .xinitrc. So you might be able to use

startx sh -c 'xrandr-invert-colors; exec "$HOME/.xinitrc"'
History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Didn't work for me (1 comment)
Didn't work for me
Quasímodo‭ wrote over 1 year ago · edited over 1 year ago

Perhaps there is something wrong on my side, but if I try startx sh -c 'true; exec $HOME/.xinitrc' 2>logfile, I get some error with xterm and Xorg fails to start:

[...cropped...]
(II) modeset(0): Initializing kms color map for depth 24, 8 bpc.
(II) modeset(G0): Initializing kms color map for depth 24, 8 bpc.
/usr/bin/xterm: ambiguous option "-cr" vs "-cc"
/usr/bin/xterm: Explicit shell already was /usr/bin/sh
/usr/bin/xterm: bad command line option "exec"

usage:  /usr/bin/xterm [-/+132] [-C] [-Sccn] [-T string] [-/+ah] [-/+ai]
[...cropped...]
xinit: connection to X server lost

waiting for X server to shut down (II) Server terminated successfully (0). Closing log file.