dotfiles/shell/.basic.zshrc

415 lines
14 KiB
Bash
Raw Normal View History

2021-02-16 14:50:03 +00:00
#
# User configuration sourced by interactive shells
#
setopt LOCAL_OPTIONS # allow functions to have local options
setopt LOCAL_TRAPS # allow functions to have local traps
setopt CLOBBER
setopt RM_STAR_SILENT # dont ask for confirmation in rm globs
setopt CORRECT # auto-correct commands
setopt COMPLETE_IN_WORD # dont nice background tasks
setopt PROMPT_SUBST # expand prompt sequences
2018-10-02 21:41:43 +01:00
#
# .zshrc is sourced in interactive shells.
# It should contain commands to set up aliases,
# functions, options, key bindings, etc.
#
# Not all terminals support this and, of those that do,
# not all provide facilities to test the support, hence
# the user should decide based on the terminal type. Most
# terminals support the colours black, red, green,
# yellow, blue, magenta, cyan and white, which can be set
# by name. In addition. default may be used to set the
# terminal's default foreground colour. Abbreviations
# are allowed; b or bl selects black.
#
WORDCHARS="${WORDCHARS:s#/#}"
WORDCHARS="${WORDCHARS:s#.#}"
2022-08-21 23:35:43 +01:00
export EDITOR=$(which vim)
2018-10-02 21:41:43 +01:00
##############################################################
#key binding stuff to get the right keys to work
# key bindings
bindkey "\e[1~" beginning-of-line
bindkey "\e[4~" end-of-line
bindkey "\e[5~" beginning-of-history
bindkey "\e[6~" end-of-history
bindkey "\e[3~" delete-char
bindkey "\e[2~" overwrite-mode
bindkey "\e[5C" forward-word
bindkey "\eOc" emacs-forward-word
bindkey "\e[5D" backward-word
bindkey "\eOd" emacs-backward-word
bindkey "\ee[C" forward-word
bindkey "\ee[D" backward-word
#Ctrl-left/right
bindkey '\e[1;5C' forward-word # ctrl right
2021-02-16 14:50:03 +00:00
bindkey '\e[1;5D' backward-word # ctrl left
2018-10-02 21:41:43 +01:00
#alt-left/right
bindkey "\e[1;3C" forward-word
bindkey "\e[1;3D" backward-word
2021-02-16 14:50:03 +00:00
bindkey "^H" backward-delete-word
2018-10-02 21:41:43 +01:00
# for rxvt
bindkey "\e[8~" end-of-line
bindkey "\e[7~" beginning-of-line
# for non RH/Debian xterm, cant hurt for RH/Debian xterm
bindkey "\eOH" beginning-of-line
bindkey "\eOF" end-of-line
# for freebsd console
bindkey "\e[H" beginning-of-line
bindkey "\e[F" end-of-line
# completion in the middle of a line
bindkey '^i' expand-or-complete-prefix
2021-02-16 14:50:03 +00:00
setopt autocd nobeep extendedglob nomatch notify
2018-10-02 21:41:43 +01:00
setopt autolist auto_menu
2021-02-16 14:50:03 +00:00
2018-10-02 21:41:43 +01:00
## completion system
_force_rehash() {
(( CURRENT == 1 )) && rehash
return 1 # Because we didn't really complete anything
}
zstyle ':completion:*' completer _oldlist _expand _force_rehash _complete _approximate
zstyle ':completion:*:approximate:' max-errors 'reply=( $((($#PREFIX+$#SUFFIX)/3 )) numeric )' # allow one error for every three characters typed in approximate completer
zstyle ':completion:*:complete:-command-::commands' ignored-patterns '*\~' # don't complete backup files as executables
zstyle ':completion:*:correct:*' insert-unambiguous true # start menu completion only if it could find no unambiguous initial string
zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}' #
zstyle ':completion:*:correct:*' original true #
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS} # activate color-completion(!)
zstyle ':completion:*:descriptions' format $'%{\e[0;31m%}completing %B%d%b%{\e[0m%}' # format on completion
zstyle ':completion:*:*:cd:*:directory-stack' menu yes select # complete 'cd -<tab>' with menu
#zstyle ':completion:*:expand:*' tag-order all-expansions # insert all expansions for expand completer
zstyle ':completion:*:history-words' list false #
zstyle ':completion:*:history-words' menu yes # activate menu
zstyle ':completion:*:history-words' remove-all-dups yes # ignore duplicate entries
zstyle ':completion:*:history-words' stop yes #
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}' # match uppercase from lowercase
zstyle ':completion:*:matches' group 'yes' # separate matches into groups
zstyle ':completion:*' group-name ''
zstyle ':completion:*:messages' format '%d' #
zstyle ':completion:*:options' auto-description '%d' #
zstyle ':completion:*:options' description 'yes' # describe options in full
zstyle ':completion:*:processes' command 'ps -au$USER' # on processes completion complete all user processes
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters # offer indexes before parameters in subscripts
zstyle ':completion:*' verbose true # provide verbose completion information
zstyle ':completion:*:warnings' format $'%{\e[0;31m%}No matches for:%{\e[0m%} %d' # set format for warnings
zstyle ':completion:*:*:zcompile:*' ignored-patterns '(*~|*.zwc)' # define files to ignore for zcompile
zstyle ':completion:correct:' prompt 'correct to: %e' #
zstyle ':completion::(^approximate*):*:functions' ignored-patterns '_*' # Ignore completion functions for commands you don't have:
# complete manual by their section
zstyle ':completion:*:manuals' separate-sections true
zstyle ':completion:*:manuals.*' insert-sections true
zstyle ':completion:*:man:*' menu yes select
# Completion caching
zstyle ':completion::complete:*' use-cache on
zstyle ':completion::complete:*' cache-path .zcache
zstyle ':completion:*:cd:*' ignore-parents parent pwd
zstyle ':completion::complete:cd::' tag-order local-directories
zstyle ':completion:*' menu select=2
zstyle ':completion:*' squeeze-slashes true
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:kill:*' force-list always
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
CDPATH=.:~:~/git
#I want my umask 0002 if I'm not root
if [[ $(whoami) = root ]]; then
umask 0022
else
umask 0002
fi
#setup ~/.dir_colors if one doesn\'t exist
if [ ! -s ~/.dir_colors ]; then
dircolors -p > ~/.dir_colors
fi
eval `dircolors ~/.dir_colors`
#aliases
alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias vi=$(which vim)
alias -- -='cd -'
alias ...='../..'
alias ....='../../..'
alias .....='../../../..'
alias ll='ls -lah'
#alias sl='ls -lah'
#alias l='ls -la'
alias -g X='| xargs'
alias -g G='| egrep'
show-colors() {
for line in {0..17}; do
for col in {0..15}; do
code=$(( $col * 18 + $line ));
printf $'\e[38;05;%dm %03d' $code $code;
done;
echo;
done
}
#allow tab completion in the middle of a word
setopt COMPLETE_IN_WORD
setopt CORRECT
## keep background processes at full speed
#setopt NOBGNICE
## restart running processes on exit
#setopt HUP
2021-02-16 14:50:03 +00:00
# Save all history
# Incrementally write history to file
2018-10-02 21:41:43 +01:00
setopt INC_APPEND_HISTORY
2021-02-16 14:50:03 +00:00
# Save timestamp to history file too
setopt EXTENDED_HISTORY
# Import newly written commands from the history file
2018-10-02 21:41:43 +01:00
setopt SHARE_HISTORY
setopt nonomatch # do not print error on non matched patterns
## automatically decide when to page a list of completions
#LISTMAX=0
## disable mail checking
#MAILCHECK=0
autoload -U colors && colors
# set some colors
for COLOR in RED GREEN YELLOW WHITE BLACK CYAN BLUE PURPLE; do
eval PR_$COLOR='%{$fg[${(L)COLOR}]%}'
eval PR_BRIGHT_$COLOR='%{$fg_bold[${(L)COLOR}]%}'
done
PR_RESET="%{${reset_color}%}";
setopt prompt_subst
autoload -Uz vcs_info
zstyle ':vcs_info:*' enable git cvs svn
# set formats
# %b - branchname
# %u - unstagedstr (see below)
# %c - stangedstr (see below)
# %a - action (e.g. rebase-i)
# %R - repository path
# %S - path in the repository
## check-for-changes can be really slow.
## you should disable it, if you work with large repositories
zstyle ':vcs_info:*:prompt:*' check-for-changes true # slower, but lets us show changes to working/index
zstyle ':vcs_info:*:prompt:*' unstagedstr "${PR_BRIGHT_YELLOW}*${PR_RESET}" # unstaged changes string: red *
zstyle ':vcs_info:*:prompt:*' stagedstr "${PR_BRIGHT_YELLOW}+${PR_RESET}" # staged changes string: yellow +
zstyle ':vcs_info:*:prompt:*' formats " ${PR_GREEN}%s${PR_RESET}:${PR_BRIGHT_RED}(%b${PR_RESET}%c%u${PR_BRIGHT_RED})${PR_RESET}" "%a"
zstyle ':vcs_info:*:prompt:*' actionformats " ${PR_GREEN}%s${PR_RESET}:${PR_BRIGHT_RED}(%b|%a)${PR_RESET}" "%a"
zstyle ':vcs_info:*:prompt:*' nvcsformats "" "%~"
zstyle ':vcs_info:*:prompt:*' branchformat "%b:%r" ""
BLUE_DIAMOND="%B%F{blue}◆%f%b"
YELLOW_DIAMOND="%B%F{yellow}◆%f%b"
GREEN_DIAMOND="%B%F{green}◆%f%b"
RED_DIAMOND="%B%F{red}◆%f%b"
RED_RARROW="%B%F{red}▶%f%b"
RED_LARROW="%B%F{red}◀%f%b"
RED_STAR="%B%F{red}✱%b%f"
case $TERM in
*xterm*|rxvt|(dt|k|E)term)
preexec () {
if [[ $(basename ${1[(w)1]}) == "ssh" ]]; then
SHN=${1[(w)-1]}
SHN_ARRAY=( ${(s,.,)SHN})
print -Pn "\e]2;$SHN:%~\a"
else
print -Pn "\e]2;%n@%m:%~\a"
fi
}
;;
screen)
preexec () {
if [[ $(basename ${1[(w)1]}) == "ssh" ]]; then
SHN=${1[(w)-1]}
SHN=${SHN#*@}
SHN_ARRAY=( ${(s,.,)SHN})
case ${#SHN_ARRAY} in
2)
print -Pn "\033k$SHN\033\\"
;;
4)
print -Pn "\033k$SHN_ARRAY[1].$SHN_ARRAY[2]\033\\"
;;
5)
#print -Pn "\033k$SHN_ARRAY[1].$SHN_ARRAY[2].$SHN_ARRAY[3]\033\\"
print -Pn "\033k$SHN_ARRAY[1].$SHN_ARRAY[3]\033\\"
;;
*)
print -Pn "\033k$SHN_ARRAY[1]\033\\"
;;
esac
fi
}
#set up precmd to draw the screen title
function set_screen_title {
print -Pn "\033k%m\033\\"
}
precmd_functions=( set_screen_title )
;;
}
if [[ -n $SSH_CONNECTION ]]; then
SSH_IP=$(echo $SSH_CLIENT | awk '{print $1}')
HOST_OUTPUT=$(host $SSH_IP)
if [[ $? -eq 0 ]]; then
SSH_HOST=$(echo $HOST_OUTPUT | awk '{print $NF}' | sed 's/.$//')
else
SSH_HOST=$SSH_IP
fi
SSH_PROMPT="${RED_STAR}%F{yellow}SSH from: %f%B%F{green}$SSH_HOST%f%b${RED_STAR}"
#SSH_PROMPT="${YELLOW_DIAMOND}${PR_BRIGHT_RED}SSH${PR_RESET}${YELLOW_DIAMOND}"
#SSH_VAR="${YELLOW_DIAMOND}${PR_BRIGHT_RED}SSH${PR_RESET}${YELLOW_DIAMOND}"
fi
HASH_NUM=$(echo $HOSTNAME | md5sum | tr -d 'a-f' | cut -b 1-6)
HASH_MOD=$(($HASH_NUM % 6 + 2))
if [[ $(whoami) = root ]]; then
PROMPT_LINE="%B%F{red}%n@%M%f%b"
else
PROMPT_LINE="%F{green}%n%f@%B%F{$HASH_MOD}%m%b%f"
fi
precmd(){
2021-02-16 14:50:03 +00:00
if [ "$(id -u)" -ne 0 ]; then
echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history | tail -n 1)" >>! $HOME/.history/zsh-history-$(date "+%Y-%m-%d").log;
fi
2018-10-02 21:41:43 +01:00
local exit_status=$?
vcs_info 'prompt'
# Battery Stuff
if which ibam &> /dev/null; then
IBAMSTAT="$(ibam)"
if [[ ${IBAMSTAT[(f)(1)][(w)1]} = "Battery" ]]; then
BATTSTATE="$(ibam --percentbattery)"
BATTPRCNT="${BATTSTATE[(f)1][(w)-2]}"
BATTTIME="${BATTSTATE[(f)2][(w)-1]}"
PR_BATTERY="Bat: ${BATTPRCNT}%% (${BATTTIME})"
if [[ "${BATTPRCNT}" -lt 15 ]]; then
PR_BATTERY=" ${BLUE_DIAMOND} ${PR_BRIGHT_RED}${PR_BATTERY}"
elif [[ "${BATTPRCNT}" -lt 50 ]]; then
PR_BATTERY=" ${BLUE_DIAMOND} ${PR_BRIGHT_YELLOW}${PR_BATTERY}"
elif [[ "${BATTPRCNT}" -lt 100 ]]; then
PR_BATTERY=" ${BLUE_DIAMOND} ${PR_BRIGHT_CYAN}${PR_BATTERY}${PR_RESET}"
else
PR_BATTERY=""
fi
else
PR_BATTERY=""
fi
fi
###End of Battery Stuff######
# now lets change the color of the path if its not writable
if [[ -w $PWD ]]; then
PR_PWDCOLOR="%F{yellow}"
else
PR_PWDCOLOR="${PR_BRIGHT_RED}"
fi
# exit code, print it if its not 0
if [[ $exit_status -ne 0 ]]; then
EXIT_STATUS=" %B%F{blue}◆%f%b %B%F{$HASH_MOD}Exit Code:%b%f %B%F{yellow}${exit_status}%b%f"
else
EXIT_STATUS=""
fi
#PROMPT LINE
#${PR_BRIGHT_YELLOW}%D{%R.%S %a %b %d %Y}${PR_RESET}\
2021-02-16 14:50:03 +00:00
#LINE1_PROMPT="\
#%B%F{black}▶%f%b%F{red}▶%B%F{red}▶%f%b \
#%B%F{$HASH_MOD}%D{%R.%S %a %b %d %Y}%b%f\
#${EXIT_STATUS}\
#%(1j. %B%F{green}◆%f%b %B%F{yellow}Jobs: %j%f%b.)\
#${PR_BATTERY}\
# %B%F{red}◀%f%b%F{red}◀%B%F{black}◀%f%b"
2018-10-02 21:41:43 +01:00
###################
local TERMWIDTH
(( TERMWIDTH = ${COLUMNS} - 2 ))
2021-02-16 14:50:03 +00:00
#LINE1=${(e%)LINE1_PROMPT} SSH_P=${(e%)SSH_PROMPT}
LINE1=SSH_P=${(e%)SSH_PROMPT}
2018-10-02 21:41:43 +01:00
#$LINE1
2021-02-16 14:50:03 +00:00
#LINE1_LENGTH=${#${LINE1//\[[^m]##m/}}
2018-10-02 21:41:43 +01:00
SSH_P_LENGTH=${#${SSH_P//\[[^m]##m/}}
2021-02-16 14:50:03 +00:00
#FILL_SPACES=${(l:TERMWIDTH - (LINE1_LENGTH + SSH_P_LENGTH):: :)}
FILL_SPACES=${(l:TERMWIDTH - (SSH_P_LENGTH):: :)}
2018-10-02 21:41:43 +01:00
2021-02-16 14:50:03 +00:00
#print -- "$LINE1 $FILL_SPACES $SSH_P"
print -- "$FILL_SPACES $SSH_P"
2018-10-02 21:41:43 +01:00
}
PROMPT='${PROMPT_LINE}%B%F{green}:%f%b${PR_PWDCOLOR}%~${PR_RESET}${vcs_info_msg_0_}%(!.%B%F{red}%#%f%b.%B%F{green}➤%f%b) '
######################################D
# set PATH so it includes user's private bin if it exists (as in GUI this will
# not be an interactive login shell)
if [ -d "$HOME/.local/bin" ]
then
PATH="$HOME/.local/bin:$PATH"
fi
2021-04-07 09:23:45 +01:00
if [ -d "$HOME/.local/bin" ]
then
PATH="$HOME/.cargo/bin:$PATH"
fi
2018-10-02 21:41:43 +01:00
# Make CTRL+S work
stty -ixon
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.zsh_aliases ]; then
. ~/.zsh_aliases
fi
# Start tmux
#if command -v tmux>/dev/null; then
# [[ ! $TERM =~ screen ]] && [ -z $TMUX ] && exec tmux
#fi
# Emacs style
#zle -N edit-command-line
#bindkey '^xe' edit-command-line
#bindkey '^x^e' edit-command-line
# Vi style:
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
export PATH="$PATH:$HOME/.config/composer/vendor/bin/"
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
export PATH="$HOME/.cabal/bin:$PATH"