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

6
.config/shell/bin/calc Executable file
View file

@ -0,0 +1,6 @@
#!/bin/zsh
# Note: this is compatible with `sh`, but because
# `sh` does not handle floats, I'm choosing `zsh`.
# Believe it or not, zsh makes for a fine calculator
echo $(($*))

View file

@ -1,7 +1,13 @@
#!/bin/sh
# Blake's environment variables # Blake's environment variables
# This file should be compatible with standard sh # This file should be compatible with standard sh
# shellcheck disable=SC2034 # shellcheck disable=SC2034
export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-$HOME/.config}/shell"}"
if ! [ -d "$SHELL_CONFIG_DIR" ]; then
echo "FATAL ERROR: \$SHELL_CONFIG_DIR is not set to a real directory: $SHELL_CONFIG_DIR"
fi
# Intelligently set $EDITOR # Intelligently set $EDITOR
if command -v nvim > /dev/null;then if command -v nvim > /dev/null;then
export EDITOR=nvim export EDITOR=nvim
@ -10,46 +16,60 @@ elif command -v vim > /dev/null;then
elif command -v vi > /dev/null;then elif command -v vi > /dev/null;then
export EDITOR=vi export EDITOR=vi
fi fi
export SHELL_CONFIG_DIR="${SHELL_CONFIG_DIR:-"${XDG_CONFIG_HOME:-$HOME/.config}/shell"}"
export PATH="$PATH:${XDG_DATA_HOME:-$HOME/.local}/bin:$SHELL_CONFIG_DIR/bin"
export SYSTEMD_EDITOR="$EDITOR" export SYSTEMD_EDITOR="$EDITOR"
export PATH="$PATH:${XDG_DATA_HOME:-$HOME/.local}/bin:$SHELL_CONFIG_DIR/bin"
export LSCOLORS="Gxfxcxdxbxegedabagacad" export LSCOLORS="Gxfxcxdxbxegedabagacad"
export ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/zsh" export ZSH_CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/zsh"
# Don't add extra space to the right side of the prompt # Don't add extra space to the right side of the prompt
export ZLE_RPROMPT_INDENT=0 export ZLE_RPROMPT_INDENT=0
export ZINIT_HOME_DIR="${XDG_DATA_HOME:-$HOME/.local}/share/zinit" export ZINIT_HOME_DIR="${XDG_DATA_HOME:-$HOME/.local}/share/zinit"
# Set documents directory (auto set to the repo the file ~/todo points to is in) # Set documents directory (auto set to the repo the file ~/todo points to is in)
# shellcheck disable=SC2155 # shellcheck disable=SC2155
[ -h ~/todo ] && export DOCS_DIR="$(git -C "$(dirname "$(realpath ~/todo)" 2>&1)" rev-parse --show-toplevel | head -1)" [ -h ~/todo ] && export DOCS_DIR="$(git -C "$(dirname "$(realpath ~/todo)" 2>&1)" rev-parse --show-toplevel | head -1)" || DOCS_DIR="$HOME/Documents/docs/"
## Working directory save settings (see things at bottom of zshrc)
WORKING_DIR_SAVE_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/last-working-dir" WORKING_DIR_SAVE_FILE="${XDG_CACHE_HOME:-$HOME/.cache}/zsh/last-working-dir"
# make the dir for the file if needed # make the dir for the file if needed
! test -d "$(dirname "$WORKING_DIR_SAVE_FILE")" && mkdir -p "$(dirname "$WORKING_DIR_SAVE_FILE")" test -d "$(dirname "$WORKING_DIR_SAVE_FILE")" || mkdir -p "$(dirname "$WORKING_DIR_SAVE_FILE")"
# Plugin setting >>> # ZSH plugin settings >>>
# ZSH Vi Mode # ZSH Vi Mode
export ZVM_VI_HIGHLIGHT_FOREGROUND=#BBC2CF export ZVM_VI_HIGHLIGHT_FOREGROUND=#BBC2CF
export ZVM_VI_HIGHLIGHT_BACKGROUND=#515860 export ZVM_VI_HIGHLIGHT_BACKGROUND=#515860
# ZVM_VI_HIGHLIGHT_EXTRASTYLE=bold,underline # bold and underline # 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 # OMZ Completion
export COMPLETION_WAITING_DOTS=true export COMPLETION_WAITING_DOTS=true
# Powerlevel 10k # Powerlevel 10k
export POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD="${POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD:-true}" export POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD="${POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD:-true}"
export POWERLEVEL9K_INSTANT_PROMPT=quiet 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="$SHELL_CONFIG_DIR/p10k/current" export P10K_CONFIG_LOCATION="$SHELL_CONFIG_DIR/p10k/current"
# <<< # <<<
########################################### ###########################################
### Directory and file quick access ### ### Directory and file quick access ###
########################################### ###########################################
SCD="$SHELL_CONFIG_DIR" S="$SHELL_CONFIG_DIR"
DD="/home/blake/Documents/docs/" DD="$DOCS_DIR"
# vim:fdm=marker:fmr=>>>,<<<:et:ft=sh:sw=3 # vim:fdm=marker:fmr=>>>,<<<:et:ft=sh:sw=3:ts=3

View file

@ -0,0 +1,13 @@
#!/bin/sh
# make a directory and cd into it
mkcd() {
mkdir -p "$1" || error "$0" $LINENO
cd "$1" || error "$0" $LINENO
}
error() {
ERROR_CODE="$?"
>&2 echo "($1) An error occurred on line number $2"
return $ERROR_CODE
}

79
.zshrc
View file

@ -4,18 +4,21 @@
# shellcheck disable=SC1090,SC2296,SC1091,SC2154,SC2015 # shellcheck disable=SC1090,SC2296,SC1091,SC2154,SC2015
# Helper function to source files. # Helper function to source files.
# Usage: careful_source "file" \ # Usage:
# "Error message" \ # careful_source "file" \
# $LINENO \ # [optional: "Error message"] \
# [optional: test to run (-f, -x, -e)] \ # [optional: $LINENO] (use this if you have an error message) \
# ["optional: operation (source, exec, command or nothing)"] \ # [optional: test to run] (-f, -x, -e) \
# [optional: operation (source, exec, command or nothing)] \
careful_source() { careful_source() {
if test "${4:--f}" "$1"; then if test "${4:--f}" "$1"; then
${5:-source} "$1" ${5:-source} "$1"
else else
echo "$2" >&2 if test -n "${2+foo}"; then
echo -e "$2" >&2
echo "Line number: $3" >&2 echo "Line number: $3" >&2
fi fi
fi
} }
# for sending error messages from functions and whatnot # for sending error messages from functions and whatnot
@ -29,7 +32,7 @@ error() {
echo -ne '\e[5 q' echo -ne '\e[5 q'
### <<< ### <<<
### Basic shell configuration >>> ### Generic shell configuration >>>
### Environment variables >>> ### Environment variables >>>
# This has to go here because otherwise we don't know where the config files are :| # 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" \ ${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 "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 >>> ### Aliases >>>
# Source the alias file # Source the alias file
${SKIP_ALIASES:-false} || careful_source "$SHELL_CONFIG_DIR/aliases" \ ${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 "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 >>> ### Functions >>>
# Organization: functions that are really short should be put here, otherwise # Organization: functions that are really short should be put here, otherwise
@ -61,37 +68,17 @@ fnupdate() {
source "$FN" source "$FN"
done done
} }
fnupdate ${SKIP_FUNCTIONS:-false} || 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 $(($*))
}
# <<< # <<<
# <<< # <<<
### Apply breaking changes with the update script >>> ### 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" "Error: failed to run update script" $LINENO -x "command"
### <<< ### <<<
### Plugins >>> ### Plugins >>>
{ ${SKIP_PLUGINS:-false} || {
# 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"
# <<<
# Load zinit >>> # Load zinit >>>
{ {
# Install zinit if not installed # Install zinit if not installed
@ -143,37 +130,32 @@ ${SKIP_UPDATE:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \
## Theme ## Theme
# terminal colors # terminal colors
if [[ -f "$SHELL_CONFIG_DIR/colors.sh" ]];then careful_source "$SHELL_CONFIG_DIR/colors.sh" ||
# custom colors
source "$SHELL_CONFIG_DIR/colors.sh"
else
# onedark shell colors
zinit snippet 'https://github.com/chriskempson/base16-shell/blob/master/scripts/base16-onedark.sh' zinit snippet 'https://github.com/chriskempson/base16-shell/blob/master/scripts/base16-onedark.sh'
fi
# LS Colors # LS Colors
zinit ice atclone"dircolors -b ./src/dir_colors > colors.zsh" \ zinit ice atclone"dircolors -b ./src/dir_colors > colors.zsh" \
atpull'%atclone' pick"colors.zsh" nocompile'!' \ atpull'%atclone' pick"colors.zsh" nocompile'!' \
atload'zstyle ":completion:*" list-colors “${(s.:.)LS_COLORS}”' atload'zstyle ":completion:*" list-colors “${(s.:.)LS_COLORS}”'
zinit light arcticicestudio/nord-dircolors zinit light arcticicestudio/nord-dircolors
# prompt # prompt
zinit load "romkatv/powerlevel10k" zinit load "romkatv/powerlevel10k"
if [[ -e "$P10K_CONFIG_LOCATION" ]]; then careful_source "$P10K_CONFIG_LOCATION" \
source "$P10K_CONFIG_LOCATION" "No p10k theme selected. Please use \`p10k configure\` to make one or select an existing one like this:
else ln -s $SHELL_CONFIG_DIR/p10k/colorful-angular.p10k.zsh $SHELL_CONFIG_DIR/p10k/current" $LINENO
>&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
# clear plugin options set at the start of this block # clear plugin options set at the start of this block
unalias zinit 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 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) # This section is (mostly) From manjaro's "manjaro-zsh-config" (/usr/share/zsh/manjaro-zsh-config)
[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history" [ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
@ -225,7 +207,7 @@ ${SKIP_UPDATE:-false} || careful_source "$SHELL_CONFIG_DIR/updates" \
WORDCHARS=${WORDCHARS//\/[&.;]} # Don't consider certain characters part of the word WORDCHARS=${WORDCHARS//\/[&.;]} # Don't consider certain characters part of the word
} }
# <<< # <<<
## Keybindings >>> ## Keybinds >>>
bindkey -v # Enable Vi mode bindkey -v # Enable Vi mode
bindkey '^[[7~' beginning-of-line # Home key bindkey '^[[7~' beginning-of-line # Home key
bindkey '^[[H' 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 # Optionally source another zshrc
[ -f "$SHELL_CONFIG_DIR/zshrc.local" ] && source "$SHELL_CONFIG_DIR/zshrc.local" || true ${SKIP_LOCAL_ZSHRC:-false} || careful_source "$SHELL_CONFIG_DIR/local/zshrc"
# vim:fdm=marker:fmr=>>>,<<<:et:ft=bash:sw=3
# vim:fdm=marker:fmr=>>>,<<<:et:ft=bash:sw=3:ts=3