dotfiles/.config/shell/env

168 lines
5.3 KiB
Bash

#!/bin/sh
# Blake's environment variables
# This file should be compatible with standard sh
# shellcheck disable=SC2034
# path_append from https://superuser.com/questions/39751/add-directory-to-path-if-its-not-already-there
# checks if a path is already in the PATH and if it exists
path_append() {
if [ -d "$1" ]; then
# posix SH doesn't have [[, so we skip testing if the path is already in the PATH for simplicity
# shellcheck disable=SC3010
if command '[[' > /dev/null 2>&1 && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="${PATH:+"$PATH:"}$1"
else
PATH="$PATH:$1"
fi
fi
}
path_prepend() {
if [ -d "$1" ]; then
# posix SH doesn't have [[, so we skip testing if the path is in the PATH already for simplicity
# shellcheck disable=SC3010
if command '[[' > /dev/null 2>&1 && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="$1${PATH:+":$PATH"}"
else
PATH="$1:$PATH"
fi
fi
}
# these would be temp vars, but ZSH does something weird where it makes them evaluate at runtime instead of
export CONFIG_HOME="${XDG_DATA_HOME:-$HOME/.config}"
export CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export LOCAL_HOME="$HOME/.local"
export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"$CONFIG_HOME/shell"}"
if ! [ -d "$SHELL_CONFIG_DIR" ]; then
echo "FATAL ERROR: \$SHELL_CONFIG_DIR is not set to a real directory: $SHELL_CONFIG_DIR" >&2
fi
## PATH MODIFICATION
# add local bin path and shell bin path to PATH
path_prepend "$LOCAL_HOME/bin"
# add shell bin files
path_append "$SHELL_CONFIG_DIR/bin"
# add doom emacs bin folder to path if it exists
path_append "$CONFIG_HOME/emacs/bin"
export PATH
if [ -z "$PROFILE_LOADED" ] && [ -f ~/.profile ]; then
# shellcheck source=/home/blake/.profile
. ~/.profile
fi
# Intelligently set $EDITOR
if [ "${EDITOR:-}" = "" ] ||
[ "${EDITOR##*/}" = "nano" ] ||
! command -v "$EDITOR" > /dev/null
then
if command -v nvim > /dev/null;then
export EDITOR=nvim
elif command -v vim > /dev/null;then
export EDITOR=vim
elif command -v vi > /dev/null;then
export EDITOR=vi
elif command -v nano > /dev/null; then
export EDITOR=nano
else
echo "Error: couldn't find a valid candidate for \$EDITOR" >&2
fi
fi
export SYSTEMD_EDITOR="$EDITOR"
export VISUAL="$EDITOR"
# Tell zellij to auto attach by default instead of opening a new session
export ZELLIJ_AUTO_ATTACH=true
# Shell to use for commands like `nix-shell -p` (use zsh if using zsh)
if test -n "${ZSH_VERSION:-}"; then
export NIX_BUILD_SHELL=zsh
fi
# Launch zsh if we haven't yet
LAUNCH_ZSH="${LAUNCH_ZSH:-true}"
# Basic default LS colors
export LSCOLORS="Gxfxcxdxbxegedabagacad"
# `less` colors
# shellcheck disable=SC2016
export LESS='-R --use-color -Dd+g$Du+b'
export MANPAGER="less -R --use-color -Dd+g -Du+b"
# Theme for zsh and nvim (soon™)
COLOR_SCHEME=tokyonight
# move zsh cache to where it should go
export ZSH_CACHE_DIR="$CACHE_HOME/zsh"
# Don't add extra space to the right side of the prompt
export ZLE_RPROMPT_INDENT=0
# Move zinit to where it should go
export ZINIT_HOME_DIR="$DATA_HOME/zinit"
# Add cargo to PATH if it exists
path_append "$HOME/.cargo/bin"
# Set documents directory (auto set to the repo the file ~/todo points to is in)
if [ -h ~/todo ] && command -v git > /dev/null; then
# shellcheck disable=SC2155
export DOCS_DIR="$(git -C "$(dirname "$(realpath ~/todo)" 2>&1)" rev-parse --show-toplevel | head -1)"
elif [ -d "$HOME/Documents/docs" ]; then
export DOCS_DIR="$HOME/Documents/docs/"
else
echo "Error: couldn't find the documents repo" > /dev/null
fi
if [ -d "/etc/nixos" ]; then
export NIXOS_DIR=/etc/nixos
fi
## Working directory save settings (see things at bottom of zshrc)
WORKING_DIR_SAVE_FILE="$CACHE_HOME/zsh/last-working-dir"
# make the dir for the file if needed
test -d "$(dirname "$WORKING_DIR_SAVE_FILE")" || mkdir -p "$(dirname "$WORKING_DIR_SAVE_FILE")"
# ZSH plugin settings >>>
# ZSH Vi Mode
export ZVM_VI_HIGHLIGHT_FOREGROUND=#BBC2CF
export ZVM_VI_HIGHLIGHT_BACKGROUND=#515860
# ZVM_VI_HIGHLIGHT_EXTRASTYLE=bold,underline # bold and underline
# vim-mode cursor
# syntax: "[color] [blinking] [style]" see: https://github.com/softmoth/zsh-vim-mode#mode-in-prompt
export MODE_CURSOR_VIINS="blinking bar"
export MODE_CURSOR_REPLACE="steady bar"
export MODE_CURSOR_VICMD="steady block"
export MODE_CURSOR_SEARCH="blinking underline"
export MODE_CURSOR_VISUAL="steady block"
export MODE_CURSOR_VLINE="steady block"
# OMZ Completion
export COMPLETION_WAITING_DOTS=true
# Powerlevel 10k
export POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD="${POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD:-true}"
export POWERLEVEL9K_INSTANT_PROMPT="${POWERLEVEL9K_INSTANT_PROMPT:-quiet}"
# TODO?: maybe add a bit of code to select a random theme if none is detected (make sure to disable instant prompt if this happens)
export P10K_CONFIG_LOCATION="${P10K_CONFIG_LOCATION:-"$SHELL_CONFIG_DIR/p10k/current"}"
# <<<
###########################################
### Directory and file quick access ###
###########################################
S="$SHELL_CONFIG_DIR"
SS="$S/shrc"
DD="$DOCS_DIR"
C=~/code/spu/ds2/src
N="${NIXOS_DIR:-}"
DP=~/'Documents/0 D'i'gi'P'e'n
DPC="$DP/classes"
export S SS # this makes it easier to load the shrc while in posix sh
# vim:fdm=marker:fmr=>>>,<<<:et:ft=sh:sw=3:ts=3