BIG UPDATE: zsh: moved lots of things out of the zshrc

This commit is contained in:
PowerUser64 2022-04-06 13:08:42 -07:00
parent a96c4215ed
commit 1eae827160
4 changed files with 81 additions and 61 deletions

83
.zshrc
View file

@ -4,17 +4,20 @@
# shellcheck disable=SC1090,SC2296,SC1091,SC2154,SC2015
# Helper function to source files.
# Usage: careful_source "file" \
# "Error message" \
# $LINENO \
# [optional: test to run (-f, -x, -e)] \
# ["optional: operation (source, exec, command or nothing)"] \
# Usage:
# careful_source "file" \
# [optional: "Error message"] \
# [optional: $LINENO] (use this if you have an error message) \
# [optional: test to run] (-f, -x, -e) \
# [optional: operation (source, exec, command or nothing)] \
careful_source() {
if test "${4:--f}" "$1"; then
${5:-source} "$1"
else
echo "$2" >&2
echo "Line number: $3" >&2
if test -n "${2+foo}"; then
echo -e "$2" >&2
echo "Line number: $3" >&2
fi
fi
}
@ -29,7 +32,7 @@ error() {
echo -ne '\e[5 q'
### <<<
### Basic shell configuration >>>
### Generic shell configuration >>>
### Environment variables >>>
# This has to go here because otherwise we don't know where the config files are :|
@ -39,12 +42,16 @@ export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-$HOME/.config}/
${SKIP_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/env" \
"Error: could not locate env file. Things could be messed up. Check that \$SHELL_CONFIG_DIR/env exists." $LINENO
${SKIP_LOCAL_ENV:-false} || careful_source "$SHELL_CONFIG_DIR/local/env" \
# <<<
### Aliases >>>
# Source the alias file
${SKIP_ALIASES:-false} || careful_source "$SHELL_CONFIG_DIR/aliases" \
"Error: could not locate alias file. You may not have any aliases. Check that \$SHELL_CONFIG_DIR points to the right place." $LINENO
${SKIP_LOCAL_ALIASES:-false} || careful_source "$SHELL_CONFIG_DIR/local/aliases"
# <<<
### Functions >>>
# Organization: functions that are really short should be put here, otherwise
@ -61,37 +68,17 @@ fnupdate() {
source "$FN"
done
}
fnupdate
# shellcheck disable=SC2016
mkcd() {
mkdir -p "$1" || error $LINENO
cd "$1" || error $LINENO
}
# believe it or not, zsh makes for a fine calculator
calc() {
echo $(($*))
}
${SKIP_FUNCTIONS:-false} || fnupdate
# <<<
# <<<
### Apply breaking changes with the update script >>>
${SKIP_UPDATE:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \
${SKIP_UPDATES:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \
"Error: failed to run update script" $LINENO -x "command"
### <<<
### Plugins >>>
{
# plugin config >>>
# 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"
# <<<
${SKIP_PLUGINS:-false} || {
# Load zinit >>>
{
# Install zinit if not installed
@ -143,37 +130,32 @@ ${SKIP_UPDATE:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \
## Theme
# terminal colors
if [[ -f "$SHELL_CONFIG_DIR/colors.sh" ]];then
# custom colors
source "$SHELL_CONFIG_DIR/colors.sh"
else
# onedark shell colors
careful_source "$SHELL_CONFIG_DIR/colors.sh" ||
zinit snippet 'https://github.com/chriskempson/base16-shell/blob/master/scripts/base16-onedark.sh'
fi
# LS Colors
zinit ice atclone"dircolors -b ./src/dir_colors > colors.zsh" \
atpull'%atclone' pick"colors.zsh" nocompile'!' \
atload'zstyle ":completion:*" list-colors “${(s.:.)LS_COLORS}”'
zinit light arcticicestudio/nord-dircolors
# prompt
zinit load "romkatv/powerlevel10k"
if [[ -e "$P10K_CONFIG_LOCATION" ]]; then
source "$P10K_CONFIG_LOCATION"
else
>&2 echo "No p10k theme selected. Please use \`p10k configure\` to make one or select an existing one like this:"
>&2 echo " ln -s $SHELL_CONFIG_DIR/p10k/colorful-angular.p10k.zsh $SHELL_CONFIG_DIR/p10k/current"
fi
careful_source "$P10K_CONFIG_LOCATION" \
"No p10k theme selected. Please use \`p10k configure\` to make one or select an existing one like this:
ln -s $SHELL_CONFIG_DIR/p10k/colorful-angular.p10k.zsh $SHELL_CONFIG_DIR/p10k/current" $LINENO
# clear plugin options set at the start of this block
unalias zinit
# just gonna sneak this in here, too
# just gonna sneak this in here too
alias zi > /dev/null && unalias zi zpl zini zplg which-command run-help fsh-alias
}
# <<<
}
# <<<
### General ZSH configuration >>>
### ZSH-specific configuration >>>
# This section is (mostly) From manjaro's "manjaro-zsh-config" (/usr/share/zsh/manjaro-zsh-config)
[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
@ -183,7 +165,7 @@ ${SKIP_UPDATE:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \
# setopt correct # Auto correct mistakes
setopt extendedglob # Extended globbing. Allows using regular expressions with *
[ -z "$TERMUX_VERSION" ] &&
setopt nocaseglob # Case insensitive globbing (and fix for termux)
setopt nocaseglob # Case insensitive globbing (and fix for termux)
setopt rcexpandparam # Array expension with parameters
setopt checkjobs # Warn about running processes when exiting
setopt numericglobsort # Sort filenames numerically when it makes sense
@ -225,7 +207,7 @@ ${SKIP_UPDATE:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \
WORDCHARS=${WORDCHARS//\/[&.;]} # Don't consider certain characters part of the word
}
# <<<
## Keybindings >>>
## Keybinds >>>
bindkey -v # Enable Vi mode
bindkey '^[[7~' beginning-of-line # Home key
bindkey '^[[H' beginning-of-line # Home key
@ -315,7 +297,6 @@ load_working_dir && cd - > /dev/null || echo -n
# <<<
# Optionally source another zshrc
[ -f "$SHELL_CONFIG_DIR/zshrc.local" ] && source "$SHELL_CONFIG_DIR/zshrc.local" || true
# vim:fdm=marker:fmr=>>>,<<<:et:ft=bash:sw=3
${SKIP_LOCAL_ZSHRC:-false} || careful_source "$SHELL_CONFIG_DIR/local/zshrc"
# vim:fdm=marker:fmr=>>>,<<<:et:ft=bash:sw=3:ts=3