236 lines
6.4 KiB
Bash
236 lines
6.4 KiB
Bash
###############################################################################
|
|
#
|
|
# ~/.zshrc
|
|
#
|
|
# Dot file git:
|
|
# https://
|
|
#
|
|
# Maintainer:
|
|
# TheFlyingFool - tff@theflyingfool.com
|
|
# http://theflyingfool.com
|
|
#
|
|
#
|
|
###############################################################################
|
|
|
|
# Skip erything for non-interactive shell
|
|
[[ -z "$PS1" ]] && return
|
|
|
|
##History
|
|
HISTFILE=~/.zsh_history
|
|
HISTSIZE=100000
|
|
SAVEHIST=50000
|
|
setopt INC_APPEND_HISTORY
|
|
setopt incappendhistory
|
|
setopt sharehistory
|
|
setopt HIST_REDUCE_BLANKS
|
|
setopt HIST_IGNORE_ALL_DUPS
|
|
setopt appendhistory
|
|
setopt autocd
|
|
setopt beep
|
|
setopt nomatch
|
|
setopt correct
|
|
setopt noclobber
|
|
setopt prompt_subst
|
|
setopt notify
|
|
unsetopt extendedglob
|
|
bindkey -v
|
|
|
|
|
|
|
|
# make history searchable with ctrl-r
|
|
bindkey "^r" history-incremental-search-backward
|
|
|
|
##Variables
|
|
export EDITOR="code"
|
|
export USE_EDITOR=$EDITOR
|
|
export VISUAL=$EDITOR
|
|
#export BROWSWER="vivaldi"
|
|
# fixes issue with atom
|
|
#export ELECTRON_TRASH="kioclient5 atom"
|
|
# export GITEA_TOKEN=a2a8542ad8fcf4de4156e9b5a83c09f826e53dc0
|
|
# export GITEA_TOKEN=55fa045ffdc1ffabbabcdc429e353e4883b04b17
|
|
##Alias
|
|
export SSH_AUTH_SOCK=/home/nick/.bitwarden-ssh-agent.sock
|
|
source ~/.alias
|
|
|
|
|
|
zstyle :compinstall filename '/home/nick/.zshrc'
|
|
|
|
autoload -Uz compinit
|
|
compinit
|
|
|
|
|
|
zstyle ':completion:*' rehash true
|
|
fpath+=~/.zfunc
|
|
|
|
##Colored man pages
|
|
|
|
man() {
|
|
env \
|
|
LESS_TERMCAP_mb=$(printf "\e[1;31m") \
|
|
LESS_TERMCAP_md=$(printf "\e[1;31m") \
|
|
LESS_TERMCAP_me=$(printf "\e[0m") \
|
|
LESS_TERMCAP_se=$(printf "\e[0m") \
|
|
LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
|
|
LESS_TERMCAP_ue=$(printf "\e[0m") \
|
|
LESS_TERMCAP_us=$(printf "\e[1;32m") \
|
|
man "$@"
|
|
}
|
|
|
|
|
|
##Command not found
|
|
##Requires extra/pkgfile -- Arch Linux
|
|
if [ -f "/usr/share/doc/pkgfile/command-not-found.zsh" ]; then
|
|
source /usr/share/doc/pkgfile/command-not-found.zsh
|
|
fi
|
|
|
|
|
|
# The following lines were added by compinstall
|
|
|
|
zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
|
|
zstyle ':completion:*' format ''\''Completing %d'\'''
|
|
zstyle ':completion:*' max-errors 3 numeric
|
|
zstyle ':completion:*' prompt 'Errors '\''%e'\'''
|
|
zstyle :compinstall filename '/home/nick/.zshrc'
|
|
|
|
autoload -Uz compinit
|
|
compinit
|
|
|
|
|
|
|
|
# #eval 'keychain --eval id_ed25519'
|
|
# if [[ -f /usr/bin/keychain ]]; then
|
|
# keychain --agents gpg,ssh id_ed25519 31936033 github_rsa
|
|
# [ -z "$HOSTNAME" ] && HOSTNAME=`uname -n`
|
|
# [ -f $HOME/.keychian/$HOSTNAME-sh ]
|
|
# source $HOME/.keychain/$HOSTNAME-sh ]
|
|
# [ -f $HOME/.keychain/$HOSTNAME-sh-gpg ]
|
|
# source $HOME/.keychain/$HOSTNAME-sh-gpg
|
|
# fi
|
|
|
|
##Prompt
|
|
|
|
#Load Colors for Prompt
|
|
autoload -U colors && colors
|
|
#Enables a quick prompt switch, can be used with
|
|
# %prompt -l #Lists Prompts
|
|
# %prompt name #Selects Prompt
|
|
|
|
if [[ -n $SSH_CLIENT ]]; then
|
|
PROMPT="[%{$fg[yellow]%}%n%{$reset_color%}@%B%{$fg[red]%}%M%{$reset_color%}]%{$reset_color%}-%{$reset_color%}[%{$fg[green]%}%~%{$reset_color%}]
|
|
%#"
|
|
else
|
|
PROMPT="[%{$fg[yellow]%}%n%{$reset_color%}@%{$fg[cyan]%}%M%{$reset_color%}]%{$reset_color%}-%{$reset_color%}[%{$fg[green]%}%~%{$reset_color%}]
|
|
%#"
|
|
fi
|
|
|
|
|
|
|
|
# Modify the colors and symbols in these variables as desired.
|
|
GIT_PROMPT_SYMBOL="%{$fg[blue]%}±"
|
|
GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$reset_color%}"
|
|
GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}"
|
|
GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}"
|
|
GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}"
|
|
GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎%{$reset_color%}"
|
|
GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}●%{$reset_color%}"
|
|
GIT_PROMPT_MODIFIED="%{$fg_bold[yellow]%}●%{$reset_color%}"
|
|
GIT_PROMPT_STAGED="%{$fg_bold[green]%}●%{$reset_color%}"
|
|
|
|
# Show Git branch/tag, or name-rev if on detached head
|
|
parse_git_branch() {
|
|
(git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null
|
|
}
|
|
|
|
# Show different symbols as appropriate for various Git repository states
|
|
parse_git_state() {
|
|
|
|
# Compose this value via multiple conditional appends.
|
|
local GIT_STATE=""
|
|
|
|
local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
|
|
if [ "$NUM_AHEAD" -gt 0 ]; then
|
|
GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}
|
|
fi
|
|
|
|
local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
|
|
if [ "$NUM_BEHIND" -gt 0 ]; then
|
|
GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}
|
|
fi
|
|
|
|
local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
|
|
if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
|
|
GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING
|
|
fi
|
|
|
|
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
|
|
GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED
|
|
fi
|
|
|
|
if ! git diff --quiet 2> /dev/null; then
|
|
GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED
|
|
fi
|
|
|
|
if ! git diff --cached --quiet 2> /dev/null; then
|
|
GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED
|
|
fi
|
|
|
|
if [[ -n $GIT_STATE ]]; then
|
|
echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX"
|
|
fi
|
|
|
|
}
|
|
|
|
# If inside a Git repository, print its branch and state
|
|
git_prompt_string() {
|
|
local git_where="$(parse_git_branch)"
|
|
[ -n "$git_where" ] && echo "$(parse_git_state)$GIT_PROMPT_PREFIX%{$fg[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX"
|
|
}
|
|
|
|
## alt-s inserts "sudo" at start of line
|
|
insert_sudo() { zle beginning-of-line; zle -U "sudo " }
|
|
zle -N insert-sudo insert_sudo
|
|
bindkey "^[s" insert-sudo
|
|
|
|
|
|
# Set the right-hand prompt
|
|
RPS1='$(git_prompt_string)'
|
|
|
|
# Created by `pipx` on 2025-03-03 18:34:12
|
|
export PATH="$PATH:/home/nick/.local/bin"
|
|
|
|
# show_venv() {
|
|
# if [[ -n "$VIRTUAL_ENV" && -n "$DIRENV_DIR" ]]; then
|
|
# echo "($(basename $VIRTUAL_ENV))"
|
|
# fi
|
|
# }
|
|
#PS1='$(show_venv)'$PS1
|
|
|
|
# requires direnv to be installed
|
|
eval "$(direnv hook zsh)"
|
|
|
|
## UNTESTED NEEDS REVIEW
|
|
# SHOULD Allow > / >> to auto create directories
|
|
# # This function will be called before executing any command
|
|
# preexec() {
|
|
# # Match something like > ~/path/to/file or >> ~/path/to/file
|
|
# if [[ "$1" =~ '>>?\s*(~?/.+)' ]]; then
|
|
# local outfile=${match[1]}
|
|
# # Expand ~ to full path
|
|
# outfile=${outfile/#\~/$HOME}
|
|
# local outdir=$(dirname "$outfile")
|
|
|
|
# if [[ ! -d "$outdir" ]]; then
|
|
# echo "Output redirection to: $outfile"
|
|
# echo -n "Directory '$outdir' does not exist. Create it? [Y/n]: "
|
|
# read -r reply
|
|
# if [[ -z "$reply" || "$reply" =~ ^[Yy] ]]; then
|
|
# mkdir -p "$outdir"
|
|
# echo "✅ Created $outdir"
|
|
# else
|
|
# echo "❌ Skipped creating directory. Command might fail."
|
|
# fi
|
|
# fi
|
|
# fi
|
|
# }
|