From e80d3cd1f4f3f5ed4069c4e384cc23854c0f615f Mon Sep 17 00:00:00 2001 From: Christian Baer Date: Sat, 23 May 2020 10:10:24 +0200 Subject: [PATCH] Pimped zsh config --- .zlogin | 24 ++++++++++++++++++------ .zsh/lib/aliases.zsh | 13 +++++++++++++ .zsh/lib/history.zsh | 9 ++++++++- .zsh/lib/key_bindings.zsh | 6 ++++-- .zsh/lib/misc.zsh | 5 ----- .zsh/lib/shortcuts.zsh | 9 +++++++++ 6 files changed, 52 insertions(+), 14 deletions(-) diff --git a/.zlogin b/.zlogin index baa0f2a..9a75182 100644 --- a/.zlogin +++ b/.zlogin @@ -1,11 +1,23 @@ -if [[ $UID == 0 || $EUID == 0 ]]; then - PATH="/root/bin:$PATH" -fi +# Set $PATH +# Put only directories in $PATH that exist and remove duplicates +typeset -U path # No duplicates +path=() -PATH="$HOME/bin:$PATH" +_prepath() { + for dir in "$@"; do + dir=${dir:A} + [[ ! -d "$dir" ]] && return + path=("$dir" $path[@]) + done +} -PATH="$PATH:/usr/local/sbin:/usr/sbin:/sbin" -PATH="/usr/local/bin:$PATH" +_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 "$HOME/bin" + +unfunction _prepath uname -npsr uptime diff --git a/.zsh/lib/aliases.zsh b/.zsh/lib/aliases.zsh index 6f918c1..d4c69cb 100644 --- a/.zsh/lib/aliases.zsh +++ b/.zsh/lib/aliases.zsh @@ -1,3 +1,16 @@ +_exists() { (( $+commands[$1] )) } + +_exists vim && export EDITOR=vim +_exists less && export PAGER=less + +if _exists vim; then + alias vim="vim -p" + alias vi="vim" +fi + +unfunction _exists + + alias ls='ls --color=always -h' alias ll='ls -la' alias ...='cd ../..' diff --git a/.zsh/lib/history.zsh b/.zsh/lib/history.zsh index d7ff39f..b222571 100644 --- a/.zsh/lib/history.zsh +++ b/.zsh/lib/history.zsh @@ -10,4 +10,11 @@ setopt hist_ignore_dups # ignore duplication command history list setopt hist_ignore_space setopt hist_verify setopt inc_append_history -setopt share_history # share command history data \ No newline at end of file +setopt share_history # share command history data + +# Make up and down arrow take what’s 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 diff --git a/.zsh/lib/key_bindings.zsh b/.zsh/lib/key_bindings.zsh index 2a70f20..b1d5832 100644 --- a/.zsh/lib/key_bindings.zsh +++ b/.zsh/lib/key_bindings.zsh @@ -9,8 +9,10 @@ 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-search -bindkey '^[[B' down-line-or-search +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 diff --git a/.zsh/lib/misc.zsh b/.zsh/lib/misc.zsh index 9aa4b4d..2f5049c 100644 --- a/.zsh/lib/misc.zsh +++ b/.zsh/lib/misc.zsh @@ -9,10 +9,5 @@ bindkey "^[m" copy-prev-shell-word setopt long_list_jobs ## pager -export PAGER=less export LC_CTYPE=$LANG export LC_ALL=de_DE.UTF-8 - -## editor - -export EDITOR=vim diff --git a/.zsh/lib/shortcuts.zsh b/.zsh/lib/shortcuts.zsh index 3527d45..59c4ccb 100644 --- a/.zsh/lib/shortcuts.zsh +++ b/.zsh/lib/shortcuts.zsh @@ -14,3 +14,12 @@ case `uname` in 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