You are not logged in.

#1 2019-12-26 18:41:47

riddle00
Member
From: Lithuania
Registered: 2015-05-26
Posts: 81

[SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

For a long time I have used this ".zshrc" setup and it was doing everything I needed:

 cat ~/.zshrc 
###########
# VARIABLES
###########

# MAIN USER SETTINGS
export MAIN_USER=riddle
export MAIN_HOME=/home/$MAIN_USER
export DOTFILES_DIR=$MAIN_HOME/.dotfiles

# DOTFILES VARS
export VIMCOLOR=miro8
export DIRCOLORS=.dircolors
export AUTOMATION_DIR=$DOTFILES_DIR/automation
export SHELL_SCRIPTS_DIR=$DOTFILES_DIR/shell-scripts
export ACTIVATE=$SHELL_SCRIPTS_DIR/activate.sh
export ACTIVATE_BY_CLASS=$SHELL_SCRIPTS_DIR/activate_by_class.sh
export FOCUS=$SHELL_SCRIPTS_DIR/focus.sh
export VIMNOTES='$SHELL_SCRIPTS_DIR/vimnotes.sh'
export LESSOPEN='|$DOTFILES_DIR/cmd/.lessfilter %s'
export LD_LIBRARY_PATH=$MAIN_HOME/mylibs

# MAIN USER VARS
export VIMRC=$MAIN_HOME/.vimrc
export DOWNLOADS=$MAIN_HOME/Downloads
export DW=$MAIN_HOME/Downloads
export DROPBOX=$MAIN_HOME/Dropbox
export TMP1=$MAIN_HOME/tmp1
export TMP2=$MAIN_HOME/tmp2
export PRO=$MAIN_HOME/pro
export SYNC=$DROPBOX/sync
export CANDY=$SYNC/candy
export NOTES=$SYNC/gtd/
export KEEP=$SYNC/keepass
export VENV=$MAIN_HOME/venvs/sql_app
export SENV=$MAIN_HOME/venvs/subscription_demo
export HDMI_SCREEN=HDMI-1-1
export LAPTOP_SCREEN=eDP-1-1

# CURRENT USER VARS
## there has been no need so far

# SYSTEMWIDE VARS
export TERM=rxvt-unicode-256color
export LSCOLORS=ExFxCxDxBxegedabagacad
export LESS='-R'
export EDITOR=vim
export LC_ALL='en_US.UTF-8'
export THEME=riddle

#########
# ALIASES
#########

...
...
...
...
...

##################
# STARTUP COMMANDS
##################

FREETYPE_PROPERTIES='truetype:interpreter-version=35'


## If not running interactively, don't do anything
[[ $- != *i* ]] && return

if [ -f $MAIN_HOME/$DIRCOLORS ]; then
    eval $(dircolors $MAIN_HOME/$DIRCOLORS )
fi

## check if X is running
if xset q &>/dev/null; then

    ## launch tmux
    tmux > /dev/null 2>&1

    ## remap keys with setxkbmap (if installed)
    if type setxkbmap >/dev/null 2>&1; then
        setxkbmap -option grp:setxkbmap -option grp:alt_shift_toggle us,lt  2>/dev/null
        setxkbmap -option caps:escape 2>/dev/null
    fi

    ## launch xscreensaver (if installed && not running)
    ps cax | grep xscreensaver > /dev/null 2>&1
    if [ $? -eq 0 ]; then
        :
    else
        xscreensaver -no-splash > /dev/null 2>&1 &
    fi

else
    if [ $TTY = "/dev/tty1"  ]; then
        ## if tty1, startx
        startx
    else
        ## remap Caps Lock to escape (in command line environment (without X))
        sudo echo "keycode 58 = Escape" | sudo loadkeys
    fi
fi

## launch dropbox (if installed && not running)
if ! type "dropbox" > /dev/null 2>&1; then
    :
else
    ps cax | grep dropbox > /dev/null 2>&1
    if [ $? -eq 0 ]; then
      :
    else
        /usr/bin/dropbox > /dev/null 2>&1;
    fi
fi

## avoid Ctrl-s freezing the terminal
stty -ixon

## Vi keybindings in terminal
set -o vi

## Launch 'Archey' (if installed). Otherwise launch 'Screenfetch' (if installed)
if ! type "alsi" > /dev/null 2>&1; then
    if ! type "archey3" > /dev/null 2>&1; then
        if ! type "screenfetch" > /dev/null 2>&1; then
        :
        else
            screenfetch
        fi
    else
        archey3
    fi
else
    alsi -a
fi


export ZSH=$DOTFILES_DIR/cmd/.oh-my-zsh

ZSH_THEME="robbyrussell"

bindkey '^R' history-incremental-search-backward

plugins=(git)

source $ZSH/oh-my-zsh.sh

set -o vi

However, it always felt a little awkward to execute these same commands every time .zshrc is sourced, since quite a few of them are needed only on startup. My question would be, which lines can I move to .xinitrc or ~/.config/openbox/.autostart.sh, and which lines must sadly remain there, to be sourced every time.

I will update this thread with what I've done so far, so this is sort-of a question being answered by me as well right now.

Last edited by riddle00 (2019-12-26 20:52:34)

Offline

#2 2019-12-26 18:44:32

riddle00
Member
From: Lithuania
Registered: 2015-05-26
Posts: 81

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

Ok, starting from the top - EXPORT statements with various variables. I think I can move them safely to autostart.sh. I am also trying to think of any cases where that would be not such a good option. Because the thing is, putting everything in .zshrc guarantees me that these commands will always be executed, for example when ssh'ing into server and putting my .zshrc there, and there won't be autostart.sh file. It seems to be a weird tradeoff between comfortability and freeing the machine from executing repetitive code every time I open a terminal. Checking if these variables are already defined and only defining them if they are not, as I understand, will not decrease the computation time.

Last edited by riddle00 (2019-12-26 18:49:55)

Offline

#3 2019-12-26 18:54:23

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

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

riddle00 wrote:

However, it always felt a little awkward to execute these same commands every time .zshrc is sourced, since quite a few of them are needed only on startup...

Use your shell profile for these parts, not the shellrc.

https://wiki.archlinux.org/index.php/Zs … down_files

Although a lot of the X related stuff is nonsensical from start to finish.  You do not need to rebind keys every time you open a terminal emulator.

But most of this is just a drop in the bucket when you are using / sourcing OMZ every time.  There is no sane way to use that - just get rid of it.

Last edited by Trilby (2019-12-26 18:57:06)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2019-12-26 18:54:46

riddle00
Member
From: Lithuania
Registered: 2015-05-26
Posts: 81

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

Hm, I think I can safely remove the script starting "dropbox", since it is already in my ~/.config/autostart/ folder

Offline

#5 2019-12-26 18:55:21

riddle00
Member
From: Lithuania
Registered: 2015-05-26
Posts: 81

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

@Trilby, thanks, gonna look into it now!

Offline

#6 2019-12-26 19:00:11

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

Environment variables belong in zshenv

Forcing a TERM belongs nowhere: it is a terrible idea.

Starting X should be in .zprofile

Starting random apps in .xinitrc if they depend on X, otherwise in autostart.sh

You set vi mode in .zshrc

All of these are documented in the Zsh man pages, which are clear and helpfully broken up into legible categories.

OMZ, on the other hand, is a steaming ratmangle of bad ideas, horribly executed. It takes a modern shell and turns it into a bloated, buggy embarrassment. You can continue to use it, but it is right up there with forcing your TERM...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#7 2019-12-26 19:59:35

riddle00
Member
From: Lithuania
Registered: 2015-05-26
Posts: 81

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

Thank you for answers!

I have put some commands in .zshenv and .zprofile, also put " setxkbmap" commands in .xinitrc, and "xscreensaver -no-splash &" in autostart.sh

I am not sure I understand the line
"Starting random apps in .xinitrc if they depend on X, otherwise in autostart.sh", the autostart.sh part, since it is bound to openbox, which requires X as I understand.

So far I am left with this code in .zshrc that I also want to transfer elsewhere (UPDATED):

FREETYPE_PROPERTIES='truetype:interpreter-version=35'

## If not running interactively, don't do anything
[[ $- != *i* ]] && return

## check if X is running
if xset q &>/dev/null; then

    ## launch tmux
    tmux > /dev/null 2>&1

else
    ## remap Caps Lock to escape (in command line environment (without X))
    sudo echo "keycode 58 = Escape" | sudo loadkeys
fi

## avoid Ctrl-s freezing the terminal
stty -ixon

## Launch 'Archey' (if installed). Otherwise launch 'Screenfetch' (if installed)
if ! type "alsi" > /dev/null 2>&1; then
    if ! type "archey3" > /dev/null 2>&1; then
        if ! type "screenfetch" > /dev/null 2>&1; then
        :
        else
            screenfetch
        fi
    else
        archey3
    fi
else
    alsi -a
fi

Last edited by riddle00 (2019-12-26 20:09:24)

Offline

#8 2019-12-26 20:14:37

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

`set -o vi` is a readline command. The equivalent in Zsh is `bindkey -v`

Do you really want to launch a new tux instance for every shell you spawn?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#9 2019-12-26 20:16:32

riddle00
Member
From: Lithuania
Registered: 2015-05-26
Posts: 81

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

Ok, changed to `bindkey -v`, thanks.

No, I do not, rather with a new terminal window

Offline

#10 2019-12-26 20:25:53

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

Up to you. But you could consider testing whether tmux is already running, and attaching to the existing session, whether as a new window or pane... I mean, the whole point of tmux is the server/client model.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#11 2019-12-26 20:28:48

riddle00
Member
From: Lithuania
Registered: 2015-05-26
Posts: 81

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

Ok, will try to do that with tmux.

Now I've left with these lines still unclear:

## If not running interactively, don't do anything
[[ $- != *i* ]] && return

## if X is not running
if ! xset q &>/dev/null; then
    ## remap Caps Lock to escape (in command line environment (without X))
    sudo echo "keycode 58 = Escape" | sudo loadkeys
fi

About running interactively, not really sure if that line is needed at all (I remember I had this line in .bashrc)

And about loadkeys, I would of course very much like to avoid "sudo" here as well as checking whether X is running, and, obviously, executing it everytime I source .zshrc.
I sometimes tinker in TTY without X and I am just very used to using CapsLock instead of Esc.

Last edited by riddle00 (2019-12-26 20:34:19)

Offline

#12 2019-12-26 20:43:08

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

You can just use a custom keymap and set that in /etc/vconsole.conf to map CapsLock to Escape.

And, no you don't need the interactive test.

Side note: there is no reason to take verything out of .zshrc - it does have a legitimate role to play in the shell initialisation sequence. You can poke around my Zsh files if it helps: https://hg.sr.ht/~jasonwryan/shiv/browse


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#13 2019-12-26 20:50:32

riddle00
Member
From: Lithuania
Registered: 2015-05-26
Posts: 81

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

Thank you!

Now my .zshrc looks like this:

. $HOME/.aliases

bindkey '^R' history-incremental-search-backward
bindkey -v

if [ -f $MAIN_HOME/$DIRCOLORS ]; then
        eval $(dircolors $MAIN_HOME/$DIRCOLORS)
fi

## avoid Ctrl-s freezing the terminal
stty -ixon

## system information tool for Arch Linux
alsi -a

Where .$HOME/.aliases contain aliases and functions.

I guess I will have to customize Zsh prompt now, after having dumped oh-my-zsh.

And thank you for your dotfiles repo, I think I was poking around in (maybe) your older one: https://bitbucket.org/jasonwryan/shiv/src/

Last edited by riddle00 (2019-12-26 20:51:24)

Offline

#14 2019-12-26 21:27:24

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

Yeah. Atlassian are so fucking incompetent that they have been unable to delete that account, despite at least a dozen emails confirming that is what I had explicitly requested... tongue


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#15 2019-12-26 21:35:51

riddle00
Member
From: Lithuania
Registered: 2015-05-26
Posts: 81

Re: [SOLVED] startup scripts: .zshrc, .autostart.sh and .xinitrc

Oh, okay, got it. I just had it bookmarked some years ago. Will check out the new files in hg smile

Offline

Board footer

Powered by FluxBB