0

I want zsh to start x automatically on the first login.

After I added

if systemctl -q is-active graphical.target && [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then exec startx fi 

to the file ~/.zprofile. however I need to login twice until xinit starts i3.

BTW I use Arch

my .xinitrc looks like

#!/bin/sh userresources=$HOME/.Xresources usermodmap=$HOME/.Xmodmap sysresources=/etc/X11/xinit/.Xresources sysmodmap=/etc/X11/xinit/.Xmodmap # merge in defaults and keymaps if [ -f $sysresources ]; then xrdb -merge $sysresources fi if [ -f $sysmodmap ]; then xmodmap $sysmodmap fi if [ -f "$userresources" ]; then xrdb -merge "$userresources" fi if [ -f "$usermodmap" ]; then xmodmap "$usermodmap" fi # start some nice programs 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 twm & xclock -geometry 50x50-1+1 & xterm -geometry 80x50+494+51 & xterm -geometry 80x20+494-0 & # exec xterm -geometry 80x66+0+0 -name login xrandr --output DP-3 --same-as LVDS-1 exec i3 
5
  • I don't know what you have, But if you have kali, you can use startx, and with other distros, you can start gdm or kdm. Commented Oct 17, 2019 at 14:00
  • So do you mean I can just omit the if block. BTW I use arch Commented Oct 17, 2019 at 14:20
  • You only need start gdm3 service via service gdm3 start Commented Oct 17, 2019 at 14:40
  • Please explain your requirements in the question. On your system X should not be started until a user logs in who happens to use zsh? Do you want to run a display manager that requires a graphical login or do you want to directly associate the X server with the user who started it? Commented Oct 17, 2019 at 14:41
  • I don't understand what you're trying to do here. Do you want a login prompt in text mode or graphical mode? If you have a text mode prompt, systemctl -q is-active graphical.target would be false. Commented Oct 17, 2019 at 19:47

2 Answers 2

2

Very late response, but just stumbled upon the same problem and wanted to give a quick solution for my use case, which I suspect is the same as the OP's. Just to clarify though, this is for starting Xorg right after having logged in using "text mode". So no display managers like gdm or lightdm.

All you need to is to add these lines to the end of your .zshrc :

if [[ -z $DISPLAY ]] && [[ $(tty) = /dev/tty1 ]]; then exec startx &>/dev/null fi 

Essentially, all this does is run Xorg (without all the annoying output...) if it isn't started yet and if you're on tty1. The latter is just in case Xorg fails on startup and you need to change some configuration files (very useful in my opinion....).

Hope this helps.

Note: you can use the same code in bash.

1

I reformulate slightly, hopefully keeping the Q's spirit:

How to start X by a shell command? How to do it at system startup?

I ignore your systemctl and much of your .xinitrc.

The most basic user command is xinit. It is hard to say what it does, exactly. It has a special semantic and syntax. To answer the Q:

xinit fvwm does start x server.

It defaults to xinit fvwm -- X :0 which means as much as:

Initialize X SERVER "X" on DISPLAY "0" with window MANAGER fvwm

It has to be so complicated, because it is powerful. X server and a window manager turn a TTY into a so-called DISPLAY.

If you go only xinit, you get that special xclock-only environment. (without any "hidden" defaults, of course. See man xinit. Also man startx. Compare!).

Of course you need xorg.conf configured! (gpu card, input devices for x)

Of course you need a window manager`, (minimally) configured! (fvwm, twm, ...)

To start X via xinit automatically, it takes some of planning and negotiating with systemd and your distro. Out of scope, but only for now.

"start x on the first login" needs (much) more precision; if it means have x running on tty1 I can understand what it means, at least. I don't see much connection with a certain shell like zsh.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.