zsh: fully committed to performing shell crimes

This commit is contained in:
Erin 2022-10-15 21:22:42 -04:00
parent 9322d6bbe8
commit b25aa8dffb
9 changed files with 122 additions and 119 deletions

View file

@ -0,0 +1,8 @@
# Detect if the current session is running on a remote server
# Runs first because multiple other things rely on this
if [ -n "$IS_REMOTE_SESSION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
is_remote=1
else
is_remote=
fi
export IS_REMOTE_SESSION=$is_remote

View file

@ -0,0 +1,20 @@
# Aliases for color support
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias diff='diff --color=auto'
fi
# Functional aliases
alias ll='ls -laFh'
alias la='ls -aFh'
alias l='ls -CFh'
alias clip='xclip -selection clipboard'
alias copy='clip'
alias code='code -r'
function mkcd { mkdir -p $1 && cd $1 }

View file

@ -0,0 +1,18 @@
# Completion settings
# The following lines were added by compinstall
zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
zstyle ':completion:*' format '%B%U%d%u%b'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' insert-unambiguous true
zstyle ':completion:*' list-colors ${(@s.:.)LS_COLORS}
zstyle ':completion:*' matcher-list '+' '+m:{[:lower:]}={[:upper:]}' '+r:|[._-]=** r:|=**' '+'
zstyle ':completion:*' max-errors 3
zstyle ':completion:*' menu select=0 yes=0
zstyle ':completion:*' select-prompt '%SScroll to view more completions (%l, %p)%s'
zstyle ':completion:*' verbose true
zstyle :compinstall filename '/home/erin/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall

View file

@ -0,0 +1,6 @@
# History management
HISTSIZE=1000
SAVEHIST=1000
HISTFILE="$HOME/.zhistory"
setopt INC_APPEND_HISTORY
setopt HIST_IGNORE_DUPS

View file

@ -0,0 +1,5 @@
# If on WSL, define DISPLAY with the local system address from /etc/resolv.conf
# to enable GUI applications via an X server running under Windows
if [ -n "$WSL_DISTRO_NAME" ]; then
export DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0"
fi

View file

@ -0,0 +1,6 @@
# Set named directories to shorten path display on non-remote systems
if [ -z "$is_remote" ]; then
hash -d gh=~/src/github.com
hash -d gl=~/src/gitlab.com
hash -d gist=~/src/gist.github.com
fi

View file

@ -0,0 +1,12 @@
# Prompt stuff
setopt PROMPT_SUBST
# vcs_info - used for displaying VCS information in prompt
zstyle ':vcs_info:*' actionformats '%F{5}(%f%s%F{5})%F{3}-%F{5}[%F{2}%b%F{3}|%F{1}%a%F{5}]%f '
zstyle ':vcs_info:*' formats '(%b) '
zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat '%b%F{1}:%F{3}%r'
autoload -Uz vcs_info
precmd_functions+=vcs-info
# Prompt shows hostname if connected to a remote or if root
PROMPT="%B$([ -n "$is_remote" ] || [ "$EUID" = 0 ] && echo "%F{magenta}%m%f ")%F{$([ "$EUID" = 0 ] && echo "red" || echo "cyan")}%n%f %F{blue}%~%f%b \${vcs_info_msg_0_}%B%#%b "

View file

@ -0,0 +1,42 @@
# Hook preexec/precmd to dynamically set rprompt with useful info
function preexec {
# Store command execution start time
timer="${timer:-"$(date +%s.%N)"}"
}
function precmd {
vcs_info
# Start with a fresh prompt
RPROMPT=""
some_line=""
if [ -z $new_session ]; then
# If this is the first prompt in a session, there's not much to say
RPROMPT="%B%F{cyan}new session%f%b"
new_session=1
else
# Show exit code + more info about the last command run as a separate line
some_line="exited %B%(?.%F{green}%?%f.%F{red}%?%f)%b"
if [ -z $timer ]; then
# If we never set $timer, preexec was never run (e.g. ^C at prompt)
some_line="$(print -P "%B%F{cyan}no exec%f%b, $some_line")"
else
# Calculate elapsed real time for last command
now="$(date +%s.%N)"
if [[ $(($now - $timer)) > 0.5 ]]; then
timer_show=$(($now - $timer))
timer_show=$(printf '%.*f\n' 3 $timer_show)
some_line="took %B%F{cyan}${timer_show}s%f%b, $some_line"
fi
fi
fi
# add current time, including timezone if remote, and collapse it if we're out of room
RPROMPT="%<#<$RPROMPT at %D{%T$([ -n "$is_remote" ] && echo ' %Z')}"
# that's an RPROMPT!
export RPROMPT
# always unset $timer for the next run
unset timer
}
preexec_functions+=preexec
precmd_functions+=precmd

View file

@ -1,122 +1,8 @@
# Completion settings # Load seperated config files
# The following lines were added by compinstall for conf in "$HOME/.config/zsh/config.d/"*.zsh; do
source "${conf}"
zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate done
zstyle ':completion:*' format '%B%U%d%u%b' unset conf
zstyle ':completion:*' group-name ''
zstyle ':completion:*' insert-unambiguous true
zstyle ':completion:*' list-colors ${(@s.:.)LS_COLORS}
zstyle ':completion:*' matcher-list '+' '+m:{[:lower:]}={[:upper:]}' '+r:|[._-]=** r:|=**' '+'
zstyle ':completion:*' max-errors 3
zstyle ':completion:*' menu select=0 yes=0
zstyle ':completion:*' select-prompt '%SScroll to view more completions (%l, %p)%s'
zstyle ':completion:*' verbose true
zstyle :compinstall filename '/home/erin/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstall
# History management
HISTSIZE=1000
SAVEHIST=1000
HISTFILE="$HOME/.zhistory"
setopt INC_APPEND_HISTORY
setopt HIST_IGNORE_DUPS
# If on WSL, define DISPLAY with the local system address from /etc/resolv.conf
# to enable GUI applications via an X server running under Windows
if [ -n "$WSL_DISTRO_NAME" ]; then
export DISPLAY="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0"
fi
# Aliases for color support
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias diff='diff --color=auto'
fi
# Functional aliases
alias ll='ls -laFh'
alias la='ls -aFh'
alias l='ls -CFh'
alias clip='xclip -selection clipboard'
alias copy='clip'
alias code='code -r'
function mkcd { mkdir -p $1 && cd $1 }
# Set named directories to shorten path display on non-remote systems
if [ -z "$is_remote" ]; then
hash -d gh=~/src/github.com
hash -d gl=~/src/gitlab.com
hash -d gist=~/src/gist.github.com
fi
# Prompt stuff
setopt PROMPT_SUBST
# Detect if the current session is running on a remote server
if [ -n "$IS_REMOTE_SESSION" ] || [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
is_remote=1
else
is_remote=
fi
export IS_REMOTE_SESSION=$is_remote
# Function to get the current branch name
function parse_git_branch {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' -e 's/((/(/' -e 's/))/)/'
}
# Prompt shows hostname if connected to a remote or if root
PROMPT="%B$([ -n "$is_remote" ] || [ "$EUID" = 0 ] && echo "%F{magenta}%m%f ")%F{$([ "$EUID" = 0 ] && echo "red" || echo "cyan")}%n%f %F{blue}%~%f%b\$(parse_git_branch) %B%#%b "
# Hook preexec/precmd to dynamically set rprompt with useful info
function preexec {
# Store command execution start time
timer="${timer:-"$(date +%s.%N)"}"
}
function precmd {
# Start with a fresh prompt
RPROMPT=""
if [ -z $new_session ]; then
# If this is the first prompt in a session, there's not much to say
RPROMPT="%B%F{cyan}new session%f%b"
new_session=1
else
# Show exit code + more info about the last command run
RPROMPT="exited %B%(?.%F{green}%?%f.%F{red}%?%f)%b"
if [ -z $timer ]; then
# If we never set $timer, preexec was never run (e.g. ^C at prompt)
RPROMPT="%B%F{cyan}no exec%f%b, $RPROMPT"
else
# Calculate elapsed real time for last command
now="$(date +%s.%N)"
if [[ $(($now - $timer)) > 0.5 ]]; then
timer_show=$(($now - $timer))
timer_show=$(printf '%.*f\n' 3 $timer_show)
RPROMPT="took %B%F{cyan}${timer_show}s%f%b, $RPROMPT"
fi
fi
fi
# add current time, including timezone if remote, and collapse it if we're out of room
RPROMPT="%<#<$RPROMPT at %D{%T$([ -n "$is_remote" ] && echo ' %Z')}"
# that's an RPROMPT!
export RPROMPT
# always unset $timer for the next run
unset timer
}
preexec_functions+=preexec
precmd_functions+=precmd
# mostly just adding stuff to $PATH now # mostly just adding stuff to $PATH now