Move zsh config to ~/.config

This commit is contained in:
2020-10-11 19:25:48 +02:00
parent 416ed81ceb
commit 81b70af9d3
20 changed files with 5 additions and 1 deletions

43
.config/zsh/.zlogin Normal file
View File

@ -0,0 +1,43 @@
## $ZDOTDIR/.zlogin - Contains commands that should be executed only in login shells
## Load config files in $ZSH/lib that for stage 3
for config_file ($ZDOTDIR/lib/30-*.zsh) source $config_file
## Run tasks in background
(
#Initalize and compile completion cache
autoload -Uz compinit
compinit
## Compile startup files
autoload -Uz zrecompile
for ((i=1; i <= $#fpath; ++i)); do
dir=$fpath[i]
zwc=${dir:t}.zwc
if [[ $dir == (.|..) || $dir == (.|..)/* ]]; then
continue
fi
files=($dir/*(N-.))
if [[ -w $dir:h && -n $files ]]; then
files=(${${(M)files%/*/*}#/})
if ( cd $dir:h &&
zrecompile -p -U -z $zwc $files ); then
fpath[i]=$fpath[i].zwc
fi
fi
done
)
## If tmux session is nested, source modified config (e.g. for overwriting styles)
if [[ "${SSH_CONNECTION}" ]] && [[ "${TMUX}" ]]; then
tmux source-file ~/.tmux.nested.conf
fi
## Update or install vim plugins
#vim -i NONE +PlugUpdate +PlugClean! +qal
## Print some system info
uname -npsr
uptime

4
.config/zsh/.zshrc Normal file
View File

@ -0,0 +1,4 @@
## $ZDOTDIR/.zshrc - Should be used to set up aliases, functions, keybindings etc.
# Load config files in $ZSH/lib that for stage 2
for config_file ($ZDOTDIR/lib/20-*.zsh) source $config_file

View File

@ -0,0 +1,35 @@
function extract() {
if [ -z "$1" ]; then
# display usage if no parameters given
echo "Usage: extract <path/file_name>.<zip|rar|bz2|gz|tar|tbz2|tgz|Z|7z|xz|ex|tar.bz2|tar.gz|tar.xz>"
echo " extract <path/file_name_1.ext> [path/file_name_2.ext] [path/file_name_3.ext]"
return 1
else
for n in $@
do
if [ -f "$n" ] ; then
case "${n%,}" in
*.tar.bz2|*.tar.gz|*.tar.xz|*.tbz2|*.tgz|*.txz|*.tar)
tar xvf "$n" ;;
*.lzma) unlzma ./"$n" ;;
*.bz2) bunzip2 ./"$n" ;;
*.rar) unrar x -ad ./"$n" ;;
*.gz) gunzip ./"$n" ;;
*.zip) unzip ./"$n" ;;
*.z) uncompress ./"$n" ;;
*.7z|*.arj|*.cab|*.chm|*.deb|*.dmg|*.iso|*.lzh|*.msi|*.rpm|*.udf|*.wim|*.xar)
7z x ./"$n" ;;
*.xz) unxz ./"$n" ;;
*.exe) cabextract ./"$n" ;;
*)
echo "extract: '$n' - unknown archive method"
return 1
;;
esac
else
echo "'$n' - file does not exist"
return 1
fi
done
fi
}

View File

@ -0,0 +1,29 @@
function tmix () {
set -o shwordsplit
SESSION="${TMIX_SESSION:-TMIX}"
SERVERS="${TMIX_SERVERS}"
if [[ $1 == "kill" ]]; then
echo "Killing tmux session $SESSION"
tmux kill-session -t "${SESSION}"
else
if [ -z "$SERVERS" ]; then
# display usage if no parameters given
echo "Usage: tmix"
echo "No servers configured. define them as TMIX_SERVERS=\"<SERVER> <SERVER> <SERVER>\" e.g. in ${ZDOTDIR}/lib/30-extras.zsh"
else
echo "Creating tmux session $SESSION"
tmux new-session -d -s "${SESSION}"
create_session=$?
if [[ $create_session = 0 ]]; then
for SERVER in ${SERVERS}; do
echo ">>> Connecting to ${SERVER}"
tmux new-window -n ${SERVER} -t ${SESSION}:
tmux send-keys -t ${SESSION}:${SERVER} "mosh ${SERVER} -- doas tmux a -d" C-m
done
fi
fi
fi
}

View File

@ -0,0 +1,21 @@
# Set $PATH
# Put only directories in $PATH that exist and remove duplicates
typeset -U path # No duplicates
path=()
_prepath() {
for dir in "$@"; do
dir=${dir:A}
[[ ! -d "$dir" ]] && return
path=("$dir" $path[@])
done
}
_prepath /usr/local/bin /bin /usr/local/sbin # General
_prepath /usr/bin /usr/sbin /sbin /Library/Apple/usr/bin # macOS
_prepath /usr/sbin /sbin # FreeBSD
_prepath ~/bin
_prepath ~/.npm-packages/bin #npm
_prepath ~/.local/bin/ #pip
unfunction _prepath

View File

@ -0,0 +1,41 @@
_exists() { (( $+commands[$1] )) }
_exists less && export PAGER=less
if _exists vim; then
export EDITOR=vim
alias vim="vim -p"
fi
unfunction _exists
alias ls="ls --color=always -h"
alias ll="ls -lah"
alias mkdir="mkdir -p"
alias ...="cd ../.."
alias foldersize="du -sh"
alias duf="du -sk * | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done"
alias google="ping -c 10240000 google.com"
alias history="history -i"
case `uname` in
Darwin)
# commands for OS X go here
alias flushdns="dscacheutil -flushcache && killall -HUP mDNSResponder"
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl"
alias r="open -a"
alias ydl="youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'"
alias nmap_localnet="nmap -sP 10.0.3.0/24"
alias fetch="curl -O"
alias htop="sudo htop"
alias sulast="sudo $(history -p !-1)"
;;
Linux)
# commands for Linux go here
;;
FreeBSD)
# commands for FreeBSD go here
alias stl="sockstat -l"
alias sulast="doas $(history -p !-1)"
;;
esac

View File

@ -0,0 +1,77 @@
# fixme - the load process here seems a bit bizarre
unsetopt menu_complete # do not autoselect the first completion entry
unsetopt flowcontrol
setopt auto_menu # show completion menu on succesive tab press
setopt complete_in_word
setopt always_to_end
WORDCHARS=''
zmodload -i zsh/complist
fpath=($fpath $ZDOTDIR/completions/)
fpath=($fpath /usr/local/share/zsh/site-functions/)
## case-insensitive (all),partial-word and then substring completion
if [ "x$CASE_SENSITIVE" = "xtrue" ]; then
zstyle ':completion:*' matcher-list 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
unset CASE_SENSITIVE
else
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
fi
# uncomment if completion should be colorful
zstyle ':completion:*' list-colors ''
# should this be in keybindings?
bindkey -M menuselect '^o' accept-and-infer-next-history
zstyle ':completion:*:*:*:*:*' menu select
zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
zstyle ':completion:*:*:*:*:processes' command "ps -u `whoami` -o pid,user,comm -w -w"
# disable named-directories autocompletion
zstyle ':completion:*:cd:*' tag-order local-directories directory-stack path-directories
cdpath=(.)
# use /etc/hosts and known_hosts for hostname completion
[ -r /etc/ssh/ssh_known_hosts ] && _global_ssh_hosts=(${${${${(f)"$(</etc/ssh/ssh_known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
[ -r ~/.ssh/known_hosts ] && _ssh_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_hosts=()
[ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$(</etc/hosts)"}%%\#*}##[:blank:]#[^[:blank:]]#}}} || _etc_hosts=()
[ -r ~/.ssh/config ] && _ssh_config=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p')) || _ssh_config=()
hosts=(
"$_global_ssh_hosts[@]"
"$_ssh_hosts[@]"
"$_etc_hosts[@]"
"$_ssh_config[@]"
"$HOST"
localhost
)
zstyle ':completion:*:hosts' hosts $hosts
# Use caching so that commands like apt and dpkg complete are useable
zstyle ':completion::complete:*' use-cache 1
zstyle ':completion::complete:*' cache-path ~/.oh-my-zsh/cache/
# Don't complete uninteresting users
zstyle ':completion:*:*:*:users' ignored-patterns \
adm amanda apache avahi beaglidx bin cacti canna clamav daemon \
dbus distcache dovecot fax ftp games gdm gkrellmd gopher \
hacluster haldaemon halt hsqldb ident junkbust ldap lp mail \
mailman mailnull mldonkey mysql nagios \
named netdump news nfsnobody nobody nscd ntp nut nx openvpn \
operator pcap postfix postgres privoxy pulse pvm quagga radvd \
rpc rpcuser rpm shutdown squid sshd sync uucp vcsa xfs
# ... unless we really want to.
zstyle '*' single-ignored show
if [ "x$COMPLETION_WAITING_DOTS" = "xtrue" ]; then
expand-or-complete-with-dots() {
echo -n "\e[31m......\e[0m"
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-dots
bindkey "^I" expand-or-complete-with-dots
fi

View File

@ -0,0 +1,11 @@
setopt correct_all
alias cap='nocorrect cap'
alias man='nocorrect man'
alias tree='nocorrect tree'
alias mv='nocorrect mv'
alias mkdir='nocorrect mkdir'
alias vim='nocorrect vim'
alias zsh='nocorrect zsh'
alias ssh='nocorrect ssh'
alias tmix='nocorrect tmix'

View File

@ -0,0 +1,4 @@
# Changing/making/removing directory
setopt auto_name_dirs
setopt auto_pushd
setopt pushd_ignore_dups

View File

@ -0,0 +1,4 @@
fpath=($fpath $ZDOTDIR/functions)
autoload extract
autoload tmix

View File

@ -0,0 +1,23 @@
## Command history configuration
HISTFILE=$ZDOTDIR/history
HISTSIZE=1000000000
SAVEHIST=1000000000
export HISTTIMEFORMAT="[%F %T] "
setopt INC_APPEND_HISTORY
setopt EXTENDED_HISTORY
setopt HIST_FIND_NO_DUPS
setopt hist_ignore_dups
setopt hist_verify
setopt incappendhistory
setopt histignorespace
setopt histnostore
setopt share_history
export HISTORY_IGNORE="([bf]g *|disown|cd ..|cd -)"
# Make up and down arrow take whats typed on the commandline in to account.
autoload -Uz up-line-or-beginning-search down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search

View File

@ -0,0 +1,34 @@
# TODO: Explain what some of this does..
bindkey -e
bindkey '\ew' kill-region
bindkey -s '\el' "ls\n"
bindkey -s '\e.' "..\n"
bindkey '^r' history-incremental-search-backward
bindkey "^[[5~" up-line-or-history
bindkey "^[[6~" down-line-or-history
# make search up and down work, so partially type and hit up/down to find relevant stuff
bindkey '^[[A' up-line-or-beginning-search # Arrow up
bindkey '^[OA' up-line-or-beginning-search
bindkey '^[[B' down-line-or-beginning-search # Arrow down
bindkey '^[OB' down-line-or-beginning-search
bindkey "^[[H" beginning-of-line
bindkey "^[[1~" beginning-of-line
bindkey "^[OH" beginning-of-line
bindkey "^[[F" end-of-line
bindkey "^[[4~" end-of-line
bindkey "^[OF" end-of-line
bindkey ' ' magic-space # also do history expansion on space
bindkey "^[[1;5C" forward-word
bindkey "^[[1;5D" backward-word
bindkey '^[[Z' reverse-menu-complete
# Make the delete key (or Fn + Delete on the Mac) work instead of outputting a ~
bindkey '^?' backward-delete-char
bindkey "^[[3~" delete-char
bindkey "^[3;5~" delete-char
bindkey "\e[3~" delete-char

View File

@ -0,0 +1,25 @@
# Directory shortcuts
# You can use cd ~x and vim ~x/file instead of cd /very/long/and/often/accessed/path. Some examples:
hash -d bin=$HOME/bin
case `uname` in
Darwin)
hash -d hucb=$HOME/Sites/christianbaer.me
;;
Linux)
# commands for Linux go here
;;
FreeBSD)
hash -d etc=/usr/local/etc
hash -d www=/usr/local/www/ngineerx
;;
esac
insert_doas() { zle beginning-of-line; zle -U "doas " }
replace_rm() { zle beginning-of-line; zle delete-word; zle -U "rm " }
zle -N insert-doas insert_doas
zle -N replace-rm replace_rm
bindkey '^s' insert-doas
bindkey '^r' replace-rm

View File

@ -0,0 +1,26 @@
# ls colors
autoload colors; colors;
export LSCOLORS="Gxfxcxdxbxegedabagacad"
#export LS_COLORS
# Enable ls colors
if [ "$DISABLE_LS_COLORS" != "true" ]
then
# Find the option for using colors in ls, depending on the version: Linux or BSD
ls --color -d . &>/dev/null 2>&1 && alias ls='ls --color=tty' || alias ls='ls -G'
fi
#setopt no_beep
setopt auto_cd
setopt multios
setopt cdablevarS
if [[ x$WINDOW != x ]]
then
SCREEN_NO="%B$WINDOW%b "
else
SCREEN_NO=""
fi
# Apply theming defaults
PS1="%n@%m:%~%# "

View File

@ -0,0 +1,22 @@
typeset -Ag FX FG BG
## Set Colors on BSD system
LSCOLORS="gxfxcxdxbxegedabagacad"
CLICOLOR="YES"
## Load .dir_colors for GNU systems
test -r "~/.dir_colors" && eval $(dircolors ~/.dir_colors)
FX=(
reset "%{%}"
bold "%{%}" no-bold "%{%}"
italic "%{%}" no-italic "%{%}"
underline "%{%}" no-underline "%{%}"
blink "%{%}" no-blink "%{%}"
reverse "%{%}" no-reverse "%{%}"
)
for color in {000..255}; do
FG[$color]="%{[38;5;${color}m%}"
BG[$color]="%{[48;5;${color}m%}"
done

View File

@ -0,0 +1 @@
## This for different additions that don't fit the scheme.

View File

@ -0,0 +1,18 @@
## smart urls
autoload -U url-quote-magic
zle -N self-insert url-quote-magic
## file rename magick
bindkey "^[m" copy-prev-shell-word
## jobs
setopt long_list_jobs
## pager
export LC_CTYPE=$LANG
export LC_ALL=de_DE.UTF-8
export IOCAGE_COLOR=TRUE
## npm config
NPM_PACKAGES="${HOME}/.npm-packages"
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"

View File

@ -0,0 +1,21 @@
setopt prompt_subst
autoload -U promptinit
promptinit
# Change user name color to red if logged in as root
if [[ $UID == 0 || $EUID == 0 ]]; then
PROMPT='%F{red}%n@%m%f '
else
PROMPT='%F{blue}%n@%m%f '
fi
PROMPT+='%F{yellow}%~%f '
# Change green arrows (⇣⇡) if connection is via ssh
if [[ "${SSH_CONNECTION}" ]]; then
PROMPT+="%F{green}⇣⇡%f %F{white}〉%f";
else
PROMPT+="%F{white}〉%f";
fi;
PROMPT+='%{$reset_color%}'

View File

@ -0,0 +1,70 @@
# Source: Josh Dick https://gist.github.com/joshdick/4415470
# Adapted from code found at <https://gist.github.com/1712320>.
setopt prompt_subst
autoload -U colors && colors # Enable colors in prompt
# 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[magenta]%}⚡︎%{$reset_color%}"
GIT_PROMPT_UNTRACKED="%{$fg[red]%}●%{$reset_color%}"
GIT_PROMPT_MODIFIED="%{$fg[yellow]%}●%{$reset_color%}"
GIT_PROMPT_STAGED="%{$fg[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 "$GIT_PROMPT_SYMBOL$(parse_git_state)$GIT_PROMPT_PREFIX%{$fg[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX"
}
# Set the right-hand prompt
RPS1='$(git_prompt_string)'