Last active
February 2, 2023 11:27
-
-
Save keuv-grvl/edd794db00b548cc5c1a to your computer and use it in GitHub Desktop.
My .zshrc file, with cool stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Lines configured by zsh-newuser-install | |
HISTFILE=~/.histfile | |
HISTSIZE=100000 | |
SAVEHIST=100000 | |
setopt extendedglob | |
unsetopt autocd | |
bindkey -e | |
# End of lines configured by zsh-newuser-install | |
# The following lines were added by compinstall | |
zstyle :compinstall filename '/home/kgravouil/.zshrc' | |
autoload -Uz compinit | |
compinit | |
# End of lines added by compinstall | |
#----------------- personal conf -----------------# | |
# Set VTE title | |
case $TERM in | |
xterm*) | |
print -Pn "\e]0;%n@%m: %~\a" | |
;; | |
esac | |
autoload -U colors && colors | |
# see https://github.com/keuv-grvl/.shellutils.d | |
for F in $(ls $HOME/.shellutils.d/*.sh); do | |
source $F | |
done | |
setopt HIST_VERIFY # dont execute line from history expansion direclty, print it first | |
setopt HIST_FIND_NO_DUPS # no duplicate in history while navigating using arrows | |
setopt HIST_REDUCE_BLANKS # Remove superfluous blanks from each command | |
setopt INC_APPEND_HISTORY # Appends every command to the history file once it is executed | |
setopt SHARE_HISTORY # Reloads the history whenever you use it | |
setopt CORRECT | |
setopt INTERACTIVE_COMMENTS # allow comment in interactive shell | |
bindkey "^[[1;5C" forward-word | |
bindkey "^[[1;5D" backward-word | |
bindkey "^[[3~" delete-char | |
bindkey "^[[H" beginning-of-line | |
bindkey "^[[F" end-of-line | |
bindkey '^[[1;5D' backward-word | |
bindkey '^[[1;5C' forward-word | |
bindkey '^R' history-incremental-pattern-search-backward | |
# prepend 'sudo' to a command using "Alt+s" | |
function zshbind_addsudo() { | |
echo $LBUFFER | | |
grep -Eqv '^[ ]*sudo' && LBUFFER="sudo $LBUFFER" | |
} | |
zle -N addsudo zshbind_addsudo | |
bindkey '^[s' addsudo | |
# (loadavg / nproc * 100) logo for RPROMPT | |
#- 0 to 79: green | |
#- 80 to 99 : yellow | |
#- 100 to 119 : red | |
#- 120+ : black | |
function _logo_load() { | |
LOGO="L" | |
PERC_LOAD=$(echo $(awk '{print $1}' /proc/loadavg)" "$(nproc) | awk '{printf "%02d\n", $1*100/$2}') | |
if test $PERC_LOAD -lt 80; then | |
LOGO="%{$fg[green]%}$LOGO%{$reset_color%}" | |
elif test $PERC_LOAD -lt 100; then | |
LOGO="%{$fg[yellow]%}$LOGO%{$reset_color%}" | |
elif test $PERC_LOAD -lt 120; then | |
LOGO="%{$fg[red]%}$LOGO%{$reset_color%}" | |
else | |
LOGO="%{$fg[black]%}$LOGO%{$reset_color%}" | |
fi | |
echo "$LOGO" | |
} | |
# memory usage (%) logo for RPROMPT | |
#- 0 to 85: green | |
#- 85 to 95 : yellow | |
#- 95 to 99 : red | |
#- 99+ : black | |
function _logo_mem() { | |
LOGO="M" | |
PERC_MEM=$(free | awk 'NR==2{print}' | sed -r 's/\s{2,}/\t/g' | awk -F "\t" '{printf "%02d\n", ($3*100/$2)}') | |
if test $PERC_MEM -lt 85; then | |
LOGO="%{$fg[green]%}$LOGO%{$reset_color%}" | |
elif test $PERC_MEM -lt 95; then | |
LOGO="%{$fg[yellow]%}$LOGO%{$reset_color%}" | |
elif test $PERC_MEM -lt 99; then | |
LOGO="%{$fg[red]%}$LOGO%{$reset_color%}" | |
else | |
LOGO="%{$fg[black]%}$LOGO%{$reset_color%}" | |
fi | |
echo "$LOGO" | |
} | |
# disk usage (%) logo for RPROMPT | |
#- 0 to 85: green | |
#- 85 to 95 : yellow | |
#- 95 to 99 : red | |
#- 99+ : black | |
function _logo_disk() { | |
LOGO="D" | |
PERC_DISK=$(df / | awk 'NR==2{printf("%d", $3*100/$2)}') | |
if test $PERC_DISK -lt 85; then | |
LOGO="%{$fg[green]%}$LOGO%{$reset_color%}" | |
elif test $PERC_DISK -lt 95; then | |
LOGO="%{$fg[yellow]%}$LOGO%{$reset_color%}" | |
elif test $PERC_DISK -lt 99; then | |
LOGO="%{$fg[red]%}$LOGO%{$reset_color%}" | |
else | |
LOGO="%{$fg[black]%}$LOGO%{$reset_color%}" | |
fi | |
echo "$LOGO" | |
} | |
# FROM: https://github.com/tupton/compact-path | |
function _compact_path() { | |
local compactpat="$HOME/.bin/compact_path.py" | |
if [[ -e "${compactpat}" ]]; then | |
echo $("${compactpat}" --trigger=20 "$1") | |
else | |
echo "$1" | |
fi | |
} | |
PROMPT="[%n@%M:%.] %# " | |
preexec() { | |
# Note the date when the command started, in unix time. | |
CMD_START_DATE=$(date +%s) | |
# Store the command that we're running. | |
CMD_NAME=$1 | |
} | |
precmd() { | |
print -Pn "\e]0;%n@%m: $(_compact_path "${PWD/#$HOME/~}" -t 20)\a" | |
RPROMPT="$(_compact_path "${PWD/#$HOME/~}" -t 20) [$(_logo_load)$(_logo_mem)$(_logo_disk)] [%D %*]" | |
# Proceed only if we've ran a command in the current shell. | |
if ! [[ -z $CMD_START_DATE ]]; then | |
# Note current date in unix time | |
CMD_END_DATE=$(date +%s) | |
# Store the difference between the last command start date vs. current date. | |
CMD_ELAPSED_TIME=$(($CMD_END_DATE - $CMD_START_DATE)) | |
# Store an arbitrary threshold, in seconds. | |
CMD_NOTIFY_THRESHOLD=300 | |
if [[ $CMD_ELAPSED_TIME -gt $CMD_NOTIFY_THRESHOLD ]]; then | |
# Beep or visual bell if the elapsed time (in seconds) is greater than threshold | |
print -n '\a' | |
# Send a notification | |
notify-send 'Job finished' "The job \"$CMD_NAME\" has finished." | |
fi | |
fi | |
} | |
# 'time' command output format | |
TIMEFMT=$'\nreal\t%E\nuser\t%U\nsys\t%S' | |
# enable color support of ls and also add handy aliases | |
if [ -x /usr/bin/dircolors ]; then | |
test -r $HOME/.dircolors && eval "$(dircolors -b $HOME/.dircolors)" || eval "$(dircolors -b)" | |
alias ls='ls --color=auto' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
fi | |
### PATH & VARIABLES ### | |
export LESS=' -R ' | |
export PATH="$HOME/.bin:$PATH" | |
zstyle ':completion:*' menu select | |
fpath+=~/.zfunc | |
source $HOME/.opt/zsh-autoenv/autoenv.zsh | |
alias ipython='python -m IPython --no-banner --classic --no-confirm-exit --no-autoindent --nosep --no-automagic --pprint' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment