Zsh Environment

about | blog | config | notes | github

This is the environment file for Zsh. It is saved in the home directory as ~/.zshenv. It is sourced everytime and first of all the configuration files.

1. Environment Configuration

First lets make sure to set the $ZDOTDIR environment variable. This will be where the rest of our Zsh configuration files will be.

export ZDOTDIR="$HOME/.config/zsh"

Need to source this file which contains locations for all my repos

source $HOME/org/config/lib/repos

Update path the $PATH variable to use some local bin directories.

export PATH="$HOME/org/config/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.config/bin:$PATH"

Set the distro name. Sometimes some distros don't have a environment variable for this already so I just have a generic solution for this.

export DISTRO=$(grep --color=none ^ID= /etc/os-release \
    | sed -e 's/^ID=//g' \
    | tr -d '"')

We should also figure out if we are in the Windows Susbsytem for Linux (WSL) which will be used to configure how certain programs will behave later on.

export WSL=$(uname -r | grep "microsoft")

The less program does not behave correctly when using windows. Some of these arguments are not supported for some reason.

if [ -z "$WSL" ]; then
    export LESS='-R --mouse --wheel-lines=3 --no-init --quit-if-one-screen'
    export LESS='-R --no-init --quit-if-one-screen'

Set the location of the journal file for Ledger to use.

export LEDGER_FILE="$LEDGER_DIR/main.journal"

When using zsh inside GNU/Emacs, we also need to update the editor. The default system editor will be vim as its a good fallback, but we definetly do not want it opening inside GNU/Emacs. Be sure to set the Zsh Aliases for vi.

if [ -n "$INSIDE_EMACS" ]; then
    export VISUAL="emacsclient --socket-name=xorg-emacs-daemon"
    export VISUAL="nvim"

Configure Zsh command history

export HISTFILE=$ZDOTDIR/history
export HISTSIZE=10000
export SAVEHIST=5000

This is sort of a weird hack. Basically, we're setting the pinentry program here before we even get to the ~/.zshrc file. The reason is that we want pinentry to default to GUI based applications instead of the tty. But if we enter an interactive shell environment (where ~/.zshrc would be invoked), then we set it back to tty.

Update: This is madness… commenting it out for now.

#export PINENTRY_USER_DATA='rofi'

Created: 2021-11-13

Emacs 26.1 (Org mode 9.5)