# Filename: $ZDOTDIR/.zprofile # Purpose: config file for zsh (z shell) # Authors: Dennis Eriksen # Bug-Reports: Email # License: This file is licensed under the BSD-3-Clause license. ################################################################################ # This file is sourced only for interactive shells. It # should contain commands to set up aliases, functions, # options, key bindings, etc. # # Global Order: zshenv, zprofile, zshrc, zlogin, zlogout # Specific order: /etc/zshenv, $ZDOTDIR/.zshenv, /etc/zprofile, # $ZDOTDIR/.zprofile, /etc/zshrc, $ZDOTDIR/.zshrc, /etc/zlogin, # $ZDOTDIR/.zlogin, $ZDOTDIR/.zlogout, /etc/zlogout ################################################################################ # Make sure directories defined in .zshenv exists # XDG mkdir -m 700 -p $XDG_CONFIG_HOME $XDG_CACHE_HOME $XDG_DATA_HOME $XDG_STATE_HOME $TMPDIR $XDG_RUNTIME_DIR # ZDIRs mkdir -m 700 -p "$ZCACHEDIR"/completion_cache "$ZDATADIR"/completion "$ZSTATEDIR" # Double-check XDG_RUNTIME_DIR, since it might be created in /tmp, where someone else might own it [[ -d $XDG_RUNTIME_DIR && -O $XDG_RUNTIME_DIR && -w $XDG_RUNTIME_DIR ]] || \ XDG_RUNTIME_DIR=$(mktemp -d $TMPDIR/$UID-runtime-XXXXXX) # # ### Helper functions ######################## # # # check if command exists have() { (( $+commands[$1] )) } # # ### Env ######################## # # # locale () { local LOC locs timelocs all_locs s if [[ $OSTYPE == (openbsd|darwin)* ]]; then # These come with all locales pre-installed. Just set the correct locale. LOC=no_NO.UTF-8 LC_TIME=en_GB.UTF-8 elif [[ $OSTYPE == linux* ]]; then # Not all locales are available everywhere on linux. Check which are available, and select the most preferred one. # (utf|UTF-)8 is appended automatically. Preferred order. First match is picked. locs=(nb_NO no_NO en_IE en_DK da_DK en_US C) timelocs=(en_GB C) all_locs=(${(f)"$(locale -a)"}) # Create array of available locales # https://unix.stackexchange.com/a/710369 for s in ${locs[@]}; { s=${all_locs[(I)${s}.(utf|UTF-)8]}; (( s )) && LOC=$all_locs[$s] && break } # https://zsh.sourceforge.io/Doc/Release/Parameters.html#Subscript-Flags for s in ${timelocs[@]}; { s=${all_locs[(I)${s}.(utf|UTF-)8]}; (( s )) && LC_TIME=$all_locs[$s] && break } fi # Fallback, in case we couldn't find any matches [[ -n $LOC ]] || LOC=C [[ -n $LC_TIME ]] || LC_TIME=C # https://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html#tag_002_002 unset LC_ALL export LANG=en_US.UTF-8 # en_US.UTF-8 is available pretty much everywhere. And linux doesn't care if suffix is utf8 or UTF-8. Both work. export LC_COLLATE=C export LC_CTYPE=$LOC export LC_MESSAGES=$LANG export LC_MONETARY=$LOC export LC_NUMERIC=$LOC export LC_TIME=$LC_TIME export LC_ADDRESS=$LOC export LC_IDENTIFICATION=$LOC export LC_MEASUREMENT=$LOC export LC_NAME=$LOC export LC_PAPER=$LOC export LC_TELEPHONE=$LOC } # report about cpu-/system-/user-time of command if running longer than 5 seconds export REPORTTIME=5 # Set EDITOR to be vim export EDITOR=vi have vim && EDITOR=vim #have nvim && EDITOR=nvim export VISUAL="$EDITOR" export SUDO_EDITOR="$EDITOR" # PAGER export PAGER=less # -i case-insensitive search unless search string contains uppercase letters # -g highlight only first match, instead of all matches # -w highlight first unread line when moving a full page # -R color # -F exit if there is less than one page of content # -X keep content on screen after exit # -M show more info at the bottom prompt line # -x4 tabs are 4 instead of 8 # -c On OpenBSD - draw from bottom up. On other systems - draw from top down. [[ $OSTYPE == openbsd* ]] && \ export LESS='-cFgiMRwXx4' || \ export LESS='-FgiMRwXx4' # MANPAGER [[ $OSTYPE == openbsd* ]] && \ # openbsd man handles MANPAGER differently, and does not work when vim uses stdin. export MANPAGER='view -M +MANPAGER --not-a-term' || \ export MANPAGER='view -M +MANPAGER --not-a-term -' # Disable the ansible-cow have ansible && export ANSIBLE_NOCOWS=True # fzf & rg have rg && export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow -g "!{.git,node_modules}/*" 2> /dev/null' have rg && export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" have fzf && export FZF_DEFAULT_OPTS='--layout=reverse --scroll-off=2 --tabstop=4 --margin=0,10,1,5' # Lynx conf have lynx && export LYNX_CFG="$XDG_CONFIG_HOME"/lynx/lynxrc # ripgreprc have rg && export RIPGREP_CONFIG_PATH="$XDG_CONFIG_HOME"/ripgrep/ripgreprc # Keeps systemctl from outputing status and other things to PAGER. have systemctl && export SYSTEMD_PAGER='' # Set TERM if it is unset. This should *not* happen. (( $+TERM )) || TERM=dumb # Set COLORTERM to truecolor if we're on a supported TERM. Can also be reset in $ZDOTDIR/.zshrc.local if (( ! $+COLORTERM )); then case $TERM in iterm |\ linux-truecolor |\ screen-truecolor |\ tmux-truecolor |\ xterm-truecolor |\ xterm-kitty ) export COLORTERM=truecolor ;; *) export COLORTERM=256 ;; esac fi # See https://github.com/termstandard/colors for some documentation on terminal and colors # macOS-specifics if [[ "$OSTYPE" == darwin* ]]; then # browser export BROWSER=open # Drop analytics in homebrew # https://github.com/Homebrew/brew/blob/master/docs/Analytics.md#opting-out have brew && export HOMEBREW_NO_ANALYTICS=1 # icloud folder export ICLOUD="${HOME}/Library/Mobile Documents/com~apple~CloudDocs" # Man-pages on macOS have brew && manpath=( "/opt/homebrew/share/man"(-/N:A) ${^manpath}(-/N:A) : ) # : inserts default manpath here export MANPATH fi # exa have exa && export EXA_COLORS="sn=37:sb=37:uu=37:un=37:gu=37:gn=37:da=37" # set CLICOLOR and LSCOLORS on bsd. [[ $OSTYPE == *bsd* ]] && export CLICOLOR=1 LSCOLORS="exgxfxfxcxFxFaxbxfedeC" # LS_COLORS [[ -r ~/.config/dircolors/LS_COLORS.sh ]] && source "$XDG_CONFIG_HOME"/dircolors/LS_COLORS.sh # OS RELEASE ID AND TYPE for Linux - OSRELID & OSRELTYPE if [[ $OSTYPE == linux* ]]; then typeset -g OSRELID OSRELTYPE if [[ -r /etc/os-release ]]; then OSRELID=$(grep "^ID=" /etc/os-release | sed 's/^ID=//') grep -qs "^ID_LIKE=" /etc/os-release && \ OSRELTYPE=$(grep "^ID_LIKE=" /etc/os-release | sed 's/^ID_LIKE=//') || \ OSRELTYPE=$OSRELID else OSRELID=unknown OSRELTYPE=unknown fi fi # Go have go && export GOPATH="$XDG_DATA_HOME"/go GOMODCACHE="$XDG_CACHE_HOME"/go/mod # Rust - Cargo have cargo && export CARGO_HOME="$XDG_DATA_HOME"/cargo # psql have psql && export PSQLRC="$XDG_CONFIG_HOME"/psql/psqlrc # END OF FILE #################################################################