From 660a6e8eb5ea1a31b502ec3001cd1e4409bd1968 Mon Sep 17 00:00:00 2001 From: Daniel McKnight Date: Thu, 29 May 2025 21:20:03 -0700 Subject: [PATCH] Add zshrc and refactor shell configration --- .bash_aliases | 5 +++ .bashrc | 15 ++----- .profile | 33 ++++++++++++++++ .zshrc | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+), 11 deletions(-) create mode 100644 .bash_aliases create mode 100644 .profile create mode 100644 .zshrc diff --git a/.bash_aliases b/.bash_aliases new file mode 100644 index 0000000..21f9eee --- /dev/null +++ b/.bash_aliases @@ -0,0 +1,5 @@ +alias k9=k9s +alias rsync="rsync -e 'ssh -o RemoteCommand=none'" +alias sudosu="sudo bash --rcfile ~/.bashrc" +alias bell="echo -e '\a'" + diff --git a/.bashrc b/.bashrc index 7bf0b99..f471061 100644 --- a/.bashrc +++ b/.bashrc @@ -147,6 +147,10 @@ fi # Customizations +if [ -f ~/.profile ]; then + . ~/.profile +fi + # Use tmux for local unelevated shells if [ -z "${SUDO_USER}" ] && [ -z "${SSH_CONNECTION}" ] && [ -z "${TERM_PROGRAM}" ]; then tmux new -A -s local_tmux @@ -161,15 +165,10 @@ if [ $(which nvim) ]; then fi # Kubernetes -alias k9=k9s which kubectl 1> /dev/null && source <(kubectl completion bash) which helm 1> /dev/null && source <(helm completion bash) -[ -d "${KREW_ROOT:-$HOME/.krew}/bin" ] && export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" # Helpful Aliases -alias rsync="rsync -e 'ssh -o RemoteCommand=none'" -alias sudosu="sudo bash --rcfile ~/.bashrc" - if [ -n "${SUDO_USER}" ]; then alias nano="nano --rcfile \"/home/${SUDO_USER}/.nanorc\"" fi @@ -178,12 +177,6 @@ fi shopt -s histverify PROMPT_COMMAND="${PROMPT_COMMAND};history -a" -# Cargo binary path -[ -d "${HOME}/.cargo/bin" ] && export PATH="${PATH}:${HOME}/.cargo/bin" - -# Funciton to notify after a long-running command -alias bell="echo -e '\a'" - # Apply local .bashrc to remote ssh session ssh-custom() { remote_file=$(mktemp) diff --git a/.profile b/.profile new file mode 100644 index 0000000..f1ff09c --- /dev/null +++ b/.profile @@ -0,0 +1,33 @@ +# ~/.profile: executed by the command interpreter for login shells. +# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login +# exists. +# see /usr/share/doc/bash/examples/startup-files for examples. +# the files are located in the bash-doc package. + +# the default umask is set in /etc/profile; for setting the umask +# for ssh logins, install and configure the libpam-umask package. +#umask 022 + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/bin" ] ; then + PATH="$HOME/bin:$PATH" +fi + +# set PATH so it includes user's private bin if it exists +if [ -d "$HOME/.local/bin" ] ; then + PATH="$HOME/.local/bin:$PATH" +fi + +if [ -d "$HOME/.cargo/bin" ] ; then + PATH="$HOME/.cargo/bin:$PATH" +fi + +if [ -d "${KREW_ROOT:-$HOME/.krew}/bin" ] ; then + PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH" +fi + +# Set nvim as the preferred editor if available +if [ $(which nvim) ]; then + export EDITOR=nvim +fi + diff --git a/.zshrc b/.zshrc new file mode 100644 index 0000000..1d04ca5 --- /dev/null +++ b/.zshrc @@ -0,0 +1,107 @@ +# Lines configured by zsh-newuser-install +HISTFILE=~/.histfile +HISTSIZE=1000 +SAVEHIST=1000 +setopt autocd notify +unsetopt beep +bindkey -v +# End of lines configured by zsh-newuser-install + +# SSH completion +zstyle ':completion:*:(ssh|scp|ftp|sftp|rsync):*' hosts $hosts + +# The following lines were added by compinstall +zstyle :compinstall filename '/home/d_mcknight/.zshrc' + +autoload -Uz compinit +compinit +# End of lines added by compinstall + +# Source common envvars +[ -f ~/.profile ] && source ~/.profile + +# Prompt +function precmd { + # Check previous command output and notify + if [[ $? != 0 && $? != 130 ]];then + echo -e "⚠️\a" + else + echo -e "\a" + fi + + if [ "$EUID" -eq 0 ];then + chrome_color="{red}" + else + chrome_color="{magenta}" + fi + + # Static prefix + prefix="%F$chrome_color┌──[%F{cyan}%n%F$chrome_color@%F{cyan}%m%F$chrome_color]-" + + # Calculate extra path + if [[ ${debian_chroot} ]]; then + path_extra="(%F{red}${debian_chroot}%F$chrome_color)-" + elif [[ ${VIRTUAL_ENV} ]]; then + rel_venv=$(realpath $VIRTUAL_ENV --relative-to $PWD --relative-base /home) + path_extra="[%F{blue}${rel_venv}%F$chrome_color]-" + else; + path_extra="" + fi + + # Static suffix + suffix="(%F{blue}%~%F${chrome_color})"$'\n'"└%F{cyan}%#%F{white} " + + PROMPT=$prefix$path_extra$suffix + PS2="%F$chrome_color└%F{cyan}>%F{white} " +} + +# Aliases +alias .=source +alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"' +alias k9=k9s +alias rsync="rsync -e 'ssh -o RemoteCommand=none'" +alias sudosu="sudo ZDOTDIR=$(dirname ${0:a}) zsh" +alias ll='ls -alFh' +alias ls="ls --color=auto" +alias lsl="ls --color=auto -lah" +alias ssh=ssh +# Use tmux for local unelevated shells +if [ -z "${SUDO_USER}" ] && [ -z "${SSH_CONNECTION}" ] && [ -z "${TERM_PROGRAM}" ]; then + tmux new -A -s local_tmux +fi + +# Custom dircolors +[ -f ~/.dircolors ] && eval "$(dircolors ~/.dircolors)" + +# Kubernetes Completion +which kubectl 1> /dev/null && source <(kubectl completion zsh) +which helm 1> /dev/null && source <(helm completion zsh) + +# Start in the home directory +cd ~ + +# Ensure zinit is installed +ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git" +[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)" +[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME" +source "${ZINIT_HOME}/zinit.zsh" + +# Load zinit plugins +zinit snippet OMZP::extract +zinit snippet OMZP::colored-man-pages +zinit snippet OMZP::encode64 +zinit snippet OMZP::gh +zinit snippet OMZP::pip +zinit snippet OMZP::sudo + +zinit light zsh-users/zsh-autosuggestions +zinit light zsh-users/zsh-syntax-highlighting + +# Key bindings config +KEYTIMEOUT=5 +# ^[ for esc; ^I for tab +bindkey '^[' autosuggest-accept + +## Explicitly exit ok +#echo "" > /dev/null +