You are not logged in.

#1 2022-10-25 16:17:15

Gill Bates
Member
Registered: 2022-10-19
Posts: 28

[SOLVED] .zshrc automatic message on login

I read the correct archwiki pages, but please feel free to send me the enlightening article.

I use

root:x:0:0:root:/root:/usr/bin/zsh

in /etc/passwd for zsh to be default shell. If there is a better way please let me know.

I created a service.d for automatic login

[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --skip-login --nonewline --noissue --autologin root --noclear %I $TERM
 

in /etc/systemd/system/getty@tty2.service.d

Now I setup .zshrc

# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="agnoster"
#ZSH_THEME="powerlevel10k/powerlevel10k"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME="archcraft"
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
zstyle ':omz:update' mode disabled  # disable automatic updates
# zstyle ':omz:update' mode auto      # update automatically without asking
# zstyle ':omz:update' mode reminder  # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='mvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# On-demand rehash
zshcache_time="$(date +%s%N)"

autoload -Uz add-zsh-hook

rehash_precmd() {
  if [[ -a /var/cache/zsh/pacman ]]; then
    local paccache_time="$(date -r /var/cache/zsh/pacman +%s%N)"
    if (( zshcache_time < paccache_time )); then
      rehash
      zshcache_time="$paccache_time"
    fi
  fi
}

add-zsh-hook -Uz precmd rehash_precmd

# omz
alias zshconfig="geany ~/.zshrc"
alias ohmyzsh="thunar ~/.oh-my-zsh"

# ls
alias l='ls -lh'
alias ll='ls -lah'
alias la='ls -A'
alias lm='ls -m'
alias lr='ls -R'
alias lg='ls -l --group-directories-first'

# git
alias gcl='git clone --depth 1'
alias gi='git init'
alias ga='git add'
alias gc='git commit -m'
alias gp='git push origin master'

neofetch

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
#[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

set -gx EDITOR "nano"
set -gx VISUAL "nano" 

.zprofile has just "neofetch" in it,
I understand .zshrc is for everytime a terminal is opened and
.zprofile everytime the user logs in, however there is never a "neofetch" on login, or when the terminal opens.

~neofetch

works as usual,
Really just trying to figure out the smartest way to autologin and auto one, or multiple commands.
Any workarrounds are much appreciated.

Any help is much appreciate, thanks for reading.

Last edited by Gill Bates (2022-10-25 17:25:34)

Offline

#2 2022-10-25 16:41:21

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] .zshrc automatic message on login

Getting rid of OMZ would be a good first step.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#3 2022-10-25 16:43:39

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [SOLVED] .zshrc automatic message on login

1) why are you autologing in as root?  Do you really want this all for the root user?
2) Is that .zshrc you posted under /root, not your user's home directory?
3) Don't use OMZ.  Really.  It breaks everything it can get it's hands on.
4) If you use OMZ in your root shell, it gat get it's hands on everything.
5) Don't run graphical programs as root (e.g., thunar).
6) If you realize that .zprofile is read on login and not .zshrc, why did you only post the latter?  What's in your /root/.zprofile?

Last edited by Trilby (2022-10-25 16:46:02)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2022-10-25 16:55:44

Gill Bates
Member
Registered: 2022-10-19
Posts: 28

Re: [SOLVED] .zshrc automatic message on login

Thanks for pointing that out, new .zshrc

# ls
alias l='ls -lh'
alias ll='ls -lah'
alias la='ls -A'
alias lm='ls -m'
alias lr='ls -R'
alias lg='ls -l --group-directories-first'

neofetch

set -gx EDITOR "nano"
set -gx VISUAL "nano" 

is the /etc/passwd the best way to change zsh to default shell?

There is the getty@tty1.service.d, to login root on tty1, why isn't

neofetch

executed when it's in .zprofile and .zshrc, what am I missing?

Offline

#5 2022-10-25 17:02:30

tucuxi
Member
From: Switzerland
Registered: 2020-03-08
Posts: 291

Re: [SOLVED] .zshrc automatic message on login

You are a brave person, all the way from automatically logging in as root to using OMZ.

.zshrc does not only run when you open a new terminal. It runs whenever a new shell starts. It can be interactive (in a terminal) or not.

If you want to do something only in an interactive shell, you can write something like this:

...
# If not running interactively, stop here
[[ $- != *i* ]] && return

neofetch

Offline

#6 2022-10-25 17:04:12

Gill Bates
Member
Registered: 2022-10-19
Posts: 28

Re: [SOLVED] .zshrc automatic message on login

Trilby wrote:

1) why are you autologing in as root?  Do you really want this all for the root user?
2) Is that .zshrc you posted under /root, not your user's home directory?
3) Don't use OMZ.  Really.  It breaks everything it can get it's hands on.
4) If you use OMZ in your root shell, it gat get it's hands on everything.
5) Don't run graphical programs as root (e.g., thunar).
6) If you realize that .zprofile is read on login and not .zshrc, why did you only post the latter?  What's in your /root/.zprofile?

1) Yes, that's my goal to autolog root on tty,
2) It's in /root dir
3,4) thanks, I appreciate sharing your experience
5) thanks, I know, the goal is to use only CLI and TUI
6) .zprofile only has

neofetch

I use archiso to build the .iso, and the problem is that I put the .zshrc and .zprofile in /airootfs and not /airootfs/root, thanks for pointing me in the right direction.

That leads me to my next point, with archiso I use /archlive/airootfs/etc/skel but p.E. /testfolder is in neither home/user nor /root.

Offline

#7 2022-10-25 17:06:39

Gill Bates
Member
Registered: 2022-10-19
Posts: 28

Re: [SOLVED] .zshrc automatic message on login

tucuxi wrote:

You are a brave person, all the way from automatically logging in as root to using OMZ.

.zshrc does not only run when you open a new terminal. It runs whenever a new shell starts. It can be interactive (in a terminal) or not.

If you want to do something only in an interactive shell, you can write something like this:

...
# If not running interactively, stop here
[[ $- != *i* ]] && return

neofetch

Kein Risiko, kein Spass ...

Thanks for explaining me

[[ $- != *i* ]] && return

I don't understand why OMZ is not liked, but I guess you OG's have your reasons.

Offline

#8 2022-10-25 17:09:16

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] .zshrc automatic message on login

Gill Bates wrote:

I don't understand why OMZ is not liked, but I guess you OG's have your reasons.

Experience.
Out of all the threads regarding zsh issues on these forums the vast majority have been caused by OMZ.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#9 2022-10-25 17:22:11

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,648

Re: [SOLVED] .zshrc automatic message on login

GillBates wrote:

is the /etc/passwd the best way to change zsh to default shell?

Kein Risiko, kein Spass ...

Well, if you enjoy taking risks that much, editing /etc/passwd is fine. The "chsh" command is safer.

Offline

#10 2022-10-25 17:30:32

Gill Bates
Member
Registered: 2022-10-19
Posts: 28

Re: [SOLVED] .zshrc automatic message on login

2ManyDogs wrote:
GillBates wrote:

is the /etc/passwd the best way to change zsh to default shell?

Kein Risiko, kein Spass ...

Well, if you enjoy taking risks that much, editing /etc/passwd is fine. The "chsh" command is safer.

I'm setting up an .iso with archiso. The only way I can think of, to have zsh as default shell would be to run chsh in .bash_login, .bash_profile, which is like 'doppelgemoppelt'

Offline

#11 2022-10-26 12:16:25

Gill Bates
Member
Registered: 2022-10-19
Posts: 28

Re: [SOLVED] .zshrc automatic message on login

etc/motd

The contents of /etc/motd are displayed by login(1) after a successful login but just before it executes the login shell.


The abbreviation "motd" stands for "message of the day", and this file has been traditionally used for exactly that (it requires much less disk space than mail to all users).

Last edited by Gill Bates (2022-10-26 12:16:41)

Offline

#12 2022-10-27 06:39:49

lfitzgerald
Member
Registered: 2021-07-16
Posts: 175

Re: [SOLVED] .zshrc automatic message on login

Gill Bates wrote:

I don't understand why OMZ is not liked, but I guess you OG's have your reasons.

It's a security risk, the overall quality of their scripts is low, it's overcomplicated due to supporting every use case instead of just yours. You can just copy bits of their code into your own config and get the same benefit without the drawbacks. It's nothing to do with OG's being prejudiced, they're just trying to give you some good advice.

Offline

Board footer

Powered by FluxBB