diff --git a/.gitignore b/.gitignore index cb7ba26..5d7e293 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ +*~ +.* zplug/ diff --git a/README.md b/README.md index ecfd062..7a44859 100644 --- a/README.md +++ b/README.md @@ -4,5 +4,5 @@ Pronounced as '/ʃ/uper' This is my simple zsh config ## Installation -`git clone --depth=1 https://git.wut.ee/mikroskeem/zshuper ~/.config/zshuper && echo "source ~/.config/zshuper/main.zsh" > ~/.zshrc` +`git clone --depth=1 https://git.wut.ee/mikroskeem/zshuper ~/.config/zshuper && echo "source ~/.config/zshuper/init.zsh" > ~/.zshrc` diff --git a/config.zsh b/config.zsh index c7d61e2..8ef7de6 100644 --- a/config.zsh +++ b/config.zsh @@ -1,8 +1,6 @@ -# zshuper default configuration -# Runtime-critical configurations +# +# zshuper runtime-critical configurations +# -# zplug home -ZPLUG_HOME=~/.config/zshuper/zplug - -# Shall we use grml PS1? Useful only when there are no prompt plugins -USE_GRML_PS1=no +# Which plugin manager to use? Choices: antibody, zplug +ZSHUPER_PLUGIN_MANAGER=zplug diff --git a/functions/aliases.zsh b/functions/aliases.zsh deleted file mode 100644 index 6d26ab1..0000000 --- a/functions/aliases.zsh +++ /dev/null @@ -1,18 +0,0 @@ -# ls colors and aliases -[ ! "$(uname -s)" = "Linux" ] && return; -export LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:" -alias ls="ls --color" -alias l="ls -l" -alias lah="ls -lah" -alias ldot="ls -d .*" - -# Make rm, mv and cp recursive and verbose -alias rm="rm -rfv" -alias mv="mv -v" -alias cp="cp -rv" - -# Other aliases -alias grep="grep --color" -alias mkdir="mkdir -p" -alias dmesg="dmesg -L" -alias ip="ip -c" diff --git a/functions/correct.zsh b/functions/correct.zsh deleted file mode 100644 index 577d8c0..0000000 --- a/functions/correct.zsh +++ /dev/null @@ -1,5 +0,0 @@ -setopt correct -zstyle ':completion:*:correct:*' insert-unambiguous true -zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}' -zstyle ':completion:*:correct:*' original true -zstyle ':completion:correct:' prompt 'correct to: %e' diff --git a/functions/hosts-completion.zsh b/functions/hosts-completion.zsh deleted file mode 100644 index fe4b261..0000000 --- a/functions/hosts-completion.zsh +++ /dev/null @@ -1,7 +0,0 @@ -hosts=( - $( - ([ -r .ssh/known_hosts ] && awk '{print $1}' .ssh/known_hosts | tr , '\n') | sort -u - ) -) - -zstyle ':completion:*' hosts $hosts diff --git a/functions/keys.zsh b/functions/keys.zsh deleted file mode 100644 index 7c67c59..0000000 --- a/functions/keys.zsh +++ /dev/null @@ -1,23 +0,0 @@ -# Part of this is from http://unix.stackexchange.com/q/62919 -# Fixes my navigation keys -typeset -A key -key[Home]=${terminfo[khome]} -key[End]=${terminfo[kend]} -key[Insert]=${terminfo[kich1]} -key[Delete]=${terminfo[kdch1]} -key[Up]=${terminfo[kcuu1]} -key[Down]=${terminfo[kcud1]} -key[Left]=${terminfo[kcub1]} -key[Right]=${terminfo[kcuf1]} -key[PageUp]=${terminfo[kpp]} -key[PageDown]=${terminfo[knp]} -[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line -[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line -[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode -[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char -[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history -[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history -[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char -[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char -[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" beginning-of-buffer-or-history -[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" end-of-buffer-or-history diff --git a/functions/new-scratch.zsh b/functions/new-scratch.zsh deleted file mode 100644 index 63044e2..0000000 --- a/functions/new-scratch.zsh +++ /dev/null @@ -1,9 +0,0 @@ -# Create quick scratch directory for testing and other stuff -function new-scratch { - local cur_dir="$HOME/scratch" - local new_dir="$HOME/tmp/scratch_$(date --iso-8601=seconds)" - mkdir -p $new_dir - ln -nfs $new_dir $cur_dir - cd $cur_dir - printf "New scratch dir ready for grinding ;>\n\n" -} diff --git a/functions/use-zaw-search.zsh b/functions/use-zaw-search.zsh deleted file mode 100644 index 52c5503..0000000 --- a/functions/use-zaw-search.zsh +++ /dev/null @@ -1,12 +0,0 @@ -# Use ZAW search -# First check if ZAW is installed and sourced -zplug info zsh-users/zaw >|/dev/null || return - -bindkey '^R' zaw-history -bindkey -M filterselect '^R' down-line-or-history -bindkey -M filterselect '^S' up-line-or-history -bindkey -M filterselect '^E' accept-search - -zstyle ':filter-select:highlight' matched fg=red -zstyle ':filter-select' max-lines 5 -zstyle ':filter-select' extended-search yes diff --git a/functions/utils.zsh b/functions/utils.zsh new file mode 100644 index 0000000..d82f739 --- /dev/null +++ b/functions/utils.zsh @@ -0,0 +1,15 @@ +# +# Utilities +# + +# Returns whether command exists or not +function __zspr_has_command { + command -v "${1}" >/dev/null + return $? +} + +# Creates directory relative to home directory +function __zspr_mkdir { + local HOMEDIR="${HOME}" + mkdir -p "${HOMEDIR}/${1}" +} diff --git a/init.zsh b/init.zsh new file mode 100644 index 0000000..8af5827 --- /dev/null +++ b/init.zsh @@ -0,0 +1,63 @@ +# +# zshuper - pronounced as '/ʃ/uper' +# +# Edit config.zsh to configure zshuper +# Source this script like: +# % source "${ZSHUPER_DIR}/"init.zsh +# + +ZSHUPER_DIR="$(dirname "${_}")" + +# PATH +export PATH="${PATH}:${HOME}/.local/share/bin:${HOME}/bin" + +# Functions +source "${ZSHUPER_DIR}/functions/utils.zsh" + +# Load config +source "${ZSHUPER_DIR}/config.zsh" + +# Set up directories +source "${ZSHUPER_DIR}/modules/directories.zsh" + +# Setup plugin manager +source "${ZSHUPER_DIR}/modules/pluginmanager.zsh" + +case "${ZSHUPER_PLUGIN_MANAGER}" in; + "antibody") + source "${ZSHUPER_DIR}/modules/pluginmanager/antibody.zsh" + ;; + "zplug") + source "${ZSHUPER_DIR}/modules/pluginmanager/zplug.zsh" + ;; + *) + echo "Unknown plugin manager: '${ZSHUPER_PLUGIN_MANAGER}', plugins will not enable!" +esac + +__zspr_plm_init + +# Include own plugins +source "${ZSHUPER_DIR}/plugins.zsh" + +# Load plugins +__zspr_plm_load_plugins + +# Enable comments in interactive shell +setopt interactivecomments + +# Show program exit code and don't check for jobs on exit +setopt printexitvalue +setopt nocheckjobs + +# zshuper modules +source "${ZSHUPER_DIR}/modules/aliases.zsh" +source "${ZSHUPER_DIR}/modules/compinit.zsh" +source "${ZSHUPER_DIR}/modules/directories.zsh" +source "${ZSHUPER_DIR}/modules/editor.zsh" +source "${ZSHUPER_DIR}/modules/history.zsh" +source "${ZSHUPER_DIR}/modules/keys.zsh" +source "${ZSHUPER_DIR}/modules/new-scratch.zsh" +source "${ZSHUPER_DIR}/modules/pacman.zsh" +source "${ZSHUPER_DIR}/modules/rationalize-dot.zsh" +source "${ZSHUPER_DIR}/modules/new-scratch.zsh" +source "${ZSHUPER_DIR}/modules/use-zaw-search.zsh" diff --git a/main.zsh b/main.zsh deleted file mode 100644 index d177743..0000000 --- a/main.zsh +++ /dev/null @@ -1,100 +0,0 @@ -# zshuper - pronounced as '/ʃ/uper' -# -# Edit config.zsh to configure zshuper -# Source this script like: -# % source ~/.config/zshuper/main.zsh -# - -# Load config -source ~/.config/zshuper/config.zsh - -# --------------------------------- -# 3rd party plugins - -# Check if zplug is installed -if [ ! -d "${ZPLUG_HOME}" ]; then - echo ">>> Installing zplug" - git clone --depth=1 https://github.com/zplug/zplug ${ZPLUG_HOME} -fi - -# Include zplug -source ${ZPLUG_HOME}/init.zsh - -# Let zplug manage itself -zplug "zplug/zplug" - -# Include own plugins -source ~/.config/zshuper/plugins.zsh - -# And include highlighting at the end -# https://github.com/zsh-users/zsh-syntax-highlighting#faq -zplug "zsh-users/zsh-syntax-highlighting", defer:2 - - -# Install and load plugins -if ! zplug check; then - zplug install -fi -zplug load - -# --------------------------------- -# zshuper specific configuration - -# Set up sane defaults and useful functions -# Use grml PS1 (if enabled) -# https://grml.org/zsh/ -if [ "${USE_GRML_PS1}" = "yes" ]; then - PS1="%B%F{red}%(?..%? )%f%b%B%F{blue}%n%f%b@%m %B%40<..<%~%<< %b%# " -fi - -# Default editor and pager -# cool people use neovim :> -export EDITOR=$(if [ ! -z "$(command -v nvim)" ]; then echo "nvim"; else echo "vim"; fi) -export VISUAL=${EDITOR} -export PAGER=less -export MANPAGER=less - -# less options -export LESS="-r" - -# History control -setopt histignorealldups -setopt extended_history -setopt append_history -setopt histignorespace -unsetopt share_history -setopt histallowclobber -setopt INC_APPEND_HISTORY_TIME -HISTSIZE=100000 -SAVEHIST=100000 -HISTFILE=~/.zsh_history - -# PATH -export PATH=${PATH}:~/bin - -# Enable comments in interactive shell -setopt interactivecomments - -# Show program exit code and don't check for jobs on exit -setopt printexitvalue -setopt nocheckjobs - -# Set up autocompletion and correction -autoload -U compinit && compinit -setopt menu_complete -zstyle ':completion:*' menu select -zstyle ':completion:*:warnings' format 'Nuffin there :(' -zstyle ':completion:*' expand prefix suffix -zstyle ':completion:*' completer _expand_alias _complete _approximate -zstyle ':completion:*:approximate:*' max-errors 4 -zstyle ':completion:*' special-dirs true - -# zshuper functions -source ~/.config/zshuper/functions/aliases.zsh -source ~/.config/zshuper/functions/keys.zsh -source ~/.config/zshuper/functions/new-scratch.zsh -source ~/.config/zshuper/functions/rationalise-dot.zsh -source ~/.config/zshuper/functions/use-zaw-search.zsh -source ~/.config/zshuper/functions/correct.zsh -source ~/.config/zshuper/functions/pacman.zsh -source ~/.config/zshuper/functions/hosts-completion.zsh diff --git a/modules/aliases.zsh b/modules/aliases.zsh new file mode 100644 index 0000000..9e3b704 --- /dev/null +++ b/modules/aliases.zsh @@ -0,0 +1,30 @@ +# ls colors and aliases +if ! __zspr_has_command "exa"; then + alias ls="ls --color" + export LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:" +else + alias ls="exa" +fi +alias l="ls -l" +alias lah="ls -lah" +alias ldot="ls -d .*" + +# Make rm, mv and cp recursive and verbose +alias rm="rm -rfv" +alias mv="mv -v" +alias cp="cp -rv" + +# git +alias gd='git diff' +alias gco='git checkout' +alias gs='git status' +alias gl='git pull' +alias gp='git push' +alias gwc='git whatchanged -p --abbrev-commit --pretty=medium' + +# Other aliases +alias grep="grep --color" +alias mkdir="mkdir -p" +alias dmesg="dmesg -L" +alias ip="ip -c" +alias diff="diff --color" diff --git a/modules/compinit.zsh b/modules/compinit.zsh new file mode 100644 index 0000000..57bcaaa --- /dev/null +++ b/modules/compinit.zsh @@ -0,0 +1,59 @@ +# +# Autocompletions +# + +# Also see https://gist.github.com/ctechols/ca1035271ad134841284 +autoload -Uz compinit +if [[ -n ${HOME}/.zcompdump(#qN.mh+24) ]]; then + compinit; +else + compinit -C; +fi; + +# Make it case insensitive +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*' + +# Completion menu +setopt menu_complete +zstyle ':completion:*' menu select +zstyle ':completion:*:warnings' format 'Nuffin there :(' +zstyle ':completion:*' expand prefix suffix +zstyle ':completion:*' completer _expand_alias _complete _approximate +zstyle ':completion:*:approximate:*' max-errors 4 +zstyle ':completion:*' special-dirs true + +# Completion correction +setopt correct +zstyle ':completion:*:correct:*' insert-unambiguous true +zstyle ':completion:*:corrections' format $'%{\e[0;31m%}%d (errors: %e)%{\e[0m%}' +zstyle ':completion:*:correct:*' original true +zstyle ':completion:correct:' prompt 'correct to: %e' + +# Completion cache +zstyle ':completion::complete:*' use-cache 1 +zstyle ':completion::complete:*' cache-path "${ZSHUPER_DIR}/.cache/completion" + +# Username completion +ignored_users=( + $(cat /etc/passwd | cut -d':' -f1,6 | sed 's/:/ /g' | awk '$2 !~ /^ *\/home/ {print $1}') +) + +zstyle ':completion:*:*:*:users' ignored-patterns $ignored_users + +# Process killing +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" + +# Hostname completions +[ -r ~/.ssh/known_hosts ] && _ssh_known_hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[\|]*}%%\ *}%%,*}) || _ssh_known_hosts=() +[ -r ~/.ssh/config ] && _ssh_hosts=($(cat ~/.ssh/config | sed -ne 's/Host[=\t ]//p')) || _ssh_hosts=() +[ -r /etc/hosts ] && : ${(A)_etc_hosts:=${(s: :)${(ps:\t:)${${(f)~~"$( +export EDITOR=$(if __zspr_has_command nvim; then echo -n "nvim"; else echo -n "vim"; fi) +export VISUAL="${EDITOR}" +export PAGER=less +export MANPAGER=less + +# less options +export LESS="-r" diff --git a/modules/history.zsh b/modules/history.zsh new file mode 100644 index 0000000..f7d04e0 --- /dev/null +++ b/modules/history.zsh @@ -0,0 +1,14 @@ +# +# History control +# + +setopt histignorealldups +setopt extended_history +setopt append_history +setopt histignorespace +unsetopt share_history +setopt histallowclobber +setopt INC_APPEND_HISTORY_TIME +HISTSIZE=100000 +SAVEHIST=100000 +HISTFILE=~/.zsh_history diff --git a/modules/keys.zsh b/modules/keys.zsh new file mode 100644 index 0000000..9e7bfcc --- /dev/null +++ b/modules/keys.zsh @@ -0,0 +1,23 @@ +# Part of this is from http://unix.stackexchange.com/q/62919 +# Fixes my navigation keys +#typeset -A key +#key[Home]=${terminfo[khome]} +#key[End]=${terminfo[kend]} +#key[Insert]=${terminfo[kich1]} +#key[Delete]=${terminfo[kdch1]} +#key[Up]=${terminfo[kcuu1]} +#key[Down]=${terminfo[kcud1]} +#key[Left]=${terminfo[kcub1]} +#key[Right]=${terminfo[kcuf1]} +#key[PageUp]=${terminfo[kpp]} +#key[PageDown]=${terminfo[knp]} +#[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line +#[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line +#[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode +#[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char +#[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history +#[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history +#[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char +#[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char +#[[ -n "${key[PageUp]}" ]] && bindkey "${key[PageUp]}" beginning-of-buffer-or-history +#[[ -n "${key[PageDown]}" ]] && bindkey "${key[PageDown]}" end-of-buffer-or-history diff --git a/modules/new-scratch.zsh b/modules/new-scratch.zsh new file mode 100644 index 0000000..d12d0d3 --- /dev/null +++ b/modules/new-scratch.zsh @@ -0,0 +1,15 @@ +# +# Quick scratch directory creator +# + +# Create quick scratch directory for testing and other stuff +function new-scratch { + local SCRATCH="${HOME}/scratch" + local NEW_SCRATCH="${HOME}/tmp/scratch_$(date "+%s")" + __zspr_mkdir "${NEW_SCRATCH}" + ln -nfs "${NEW_SCRATCH}" "${SCRATCH}" + pushd "${SCRATCH}" > /dev/null + printf "New scratch dir ready for grinding ;>\n\n" +} + +autoload -Uz new-scratch diff --git a/functions/pacman.zsh b/modules/pacman.zsh similarity index 69% rename from functions/pacman.zsh rename to modules/pacman.zsh index 3aef0ea..b8c162a 100644 --- a/functions/pacman.zsh +++ b/modules/pacman.zsh @@ -1,5 +1,9 @@ +# # Wrap pacman so you don't need to put sudo before -# Optionally use yaourt or pacaur +# Optionally uses yaourt or pacaur +# Wrapper can be disabled using NO_PACMAN_WRAP=1 pacman -Syu +# + function pacman { if [ ! -z "${NO_PACMAN_WRAP}" ]; then sudo /usr/bin/pacman "$@" @@ -8,11 +12,13 @@ function pacman { local ypath="$(command -v yaourt)" local ppath="$(command -v pacaur)" if [ ! -z "${ypath}" ]; then - ${ypath} "$@" + "${ypath}" "$@" elif [ ! -z "${ppath}" ]; then - ${ppath} "$@" + "${ppath}" "$@" else sudo /usr/bin/pacman "$@" fi return $? } + +autoload -Uz pacman diff --git a/modules/pluginmanager.zsh b/modules/pluginmanager.zsh new file mode 100644 index 0000000..255277d --- /dev/null +++ b/modules/pluginmanager.zsh @@ -0,0 +1,56 @@ +# +# Plugin manager "interface" +# + +ZSPR_PLM_FUNCTIONS=( + __zspr_plm_init + __zspr_plm_load_plugins + __zspr_plm_install_plugin + __zspr_plm_update_plugins + __zspr_plm_has_plugin +) + +# Initializes plugin manager +function __zspr_plm_init { + if [[ "${ZSPR_PLM_FUNCTIONS[1]}" = "__zspr_plm_init" ]]; then + echo "Plugin manager does not implement __zspr_plm_init" + else + "${ZSPR_PLM_FUNCTIONS[1]}" "${@}" + fi +} + +# Loads plugins +function __zspr_plm_load_plugins { + if [[ "${ZSPR_PLM_FUNCTIONS[2]}" = "__zspr_plm_load_plugins" ]]; then + echo "Plugin manager does not implement __zspr_plm_load_plugins" + else + "${ZSPR_PLM_FUNCTIONS[2]}" "${@}" + fi +} + +# Installs new plugin +function __zspr_plm_install_plugin { + if [[ "${ZSPR_PLM_FUNCTIONS[3]}" = "__zspr_plm_install_plugin" ]]; then + echo "Plugin manager does not implement __zspr_plm_install_plugin" + else + "${ZSPR_PLM_FUNCTIONS[3]}" "${@}" + fi +} + +# Updates plugins +function __zspr_plm_update_plugins { + if [[ "${ZSPR_PLM_FUNCTIONS[4]}" = "__zspr_plm_update_plugins" ]]; then + echo "Plugin manager does not implement __zspr_plm_update_plugins" + else + "${ZSPR_PLM_FUNCTIONS[4]}" "${@}" + fi +} + +# Returns wheter plugin is present or not +function __zspr_plm_has_plugin { + if [[ "${ZSPR_PLM_FUNCTIONS[5]}" = "__zspr_plm_has_plugin" ]]; then + echo "Plugin manager does not implement __zspr_plm_has_plugin" + else + "${ZSPR_PLM_FUNCTIONS[5]}" "${@}" + fi +} diff --git a/modules/pluginmanager/antibody.zsh b/modules/pluginmanager/antibody.zsh new file mode 100644 index 0000000..489ecc2 --- /dev/null +++ b/modules/pluginmanager/antibody.zsh @@ -0,0 +1,60 @@ +# +# Antibody plugin manager +# + +function __zspr_antibody_download { + local DOWNLOAD_URL="https://github.com/getantibody/antibody/releases/download" + local LATEST="$(curl -s https://raw.githubusercontent.com/getantibody/homebrew-tap/master/Formula/antibody.rb | grep url | cut -f8 -d'/')" + local ANTIBODY_TMP="$(mktemp -d)" + local ANTIBODY_TGZ="${ANTIBODY_TMP}/antibody.tar.gz" + local ANTIBODY="${ANTIBODY_TMP}/antibody" + + echo "Downloading Antibody $LATEST for $(uname -s)_$(uname -m), please wait..." + curl -s -L -o "${ANTIBODY_TGZ}" "${DOWNLOAD_URL}/${LATEST}/antibody_$(uname -s)_$(uname -m).tar.gz" + + tar -xf "${ANTIBODY_TGZ}" -C "${ANTIBODY_TMP}" + + # Move antibody to ~/.local/share/bin + test -x "${ANTIBODY}" || { + echo "Failed to find unpacked Antibody binary!" + } + mv "${ANTIBODY}" "${HOME}/.local/share/bin/antibody" + + # Test if antibody works + __zspr_has_command "antibody" || echo "Could not get Antibody working!" + + # Clean up + rm -rf "${ANTIBODY_TMP}" +} + + +function __zspr_antibody_init { + __zspr_has_command "antibody" || __zspr_antibody_download + source <(antibody init) +} + +function __zspr_antibody_load_plugins { + # Iterate over array and let antibody create plugins script + for plugin in ${ZSHUPER_PLUGINS}; do echo "${plugin}"; done | antibody bundle +} + +function __zspr_antibody_install_plugin { + antibody bundle "${1}" +} + +function __zspr_antibody_update_plugins { + antibody update +} + +function __zspr_antibody_has_plugin { + local PLUGIN="$(echo -n "${1}" | sed 's#/#-SLASH-##g')" + antibody list | grep -q "${PLUGIN}" + return $? +} + +# Set up antibody as a plugin manager +ZSPR_PLM_FUNCTIONS[1]=__zspr_antibody_init +ZSPR_PLM_FUNCTIONS[2]=__zspr_antibody_load_plugins +ZSPR_PLM_FUNCTIONS[3]=__zspr_antibody_install_plugin +ZSPR_PLM_FUNCTIONS[4]=__zspr_antibody_update_plugins +ZSPR_PLM_FUNCTIONS[5]=__zspr_antibody_has_plugin diff --git a/modules/pluginmanager/zplug.zsh b/modules/pluginmanager/zplug.zsh new file mode 100644 index 0000000..2490b40 --- /dev/null +++ b/modules/pluginmanager/zplug.zsh @@ -0,0 +1,44 @@ +# +# zplug plugin manager +# +ZSPR_ZPLUG_HOME="${ZSHUPER_DIR}/zplug" + +function __zspr_zplug_init { + if [ ! -d "${ZSPR_ZPLUG_HOME}" ]; then + git clone --depth=1 https://github.com/zplug/zplug "${ZSPR_ZPLUG_HOME}" + fi + + source "${ZSPR_ZPLUG_HOME}/init.zsh" + zplug "zplug/zplug" +} + +function __zspr_zplug_load_plugins { + for plugin in ${ZSHUPER_PLUGINS}; do + __zspr_zplug_install_plugin "${plugin}" + done + + if ! zplug check; then + zplug install + fi + zplug load +} + +function __zspr_zplug_install_plugin { + zplug ${1} +} + +function __zspr_zplug_update_plugins { + zplug update +} + +function __zspr_zplug_has_plugin { + zplug check ${1} + return $? +} + +# Set up zplug as a plugin manager +ZSPR_PLM_FUNCTIONS[1]=__zspr_zplug_init +ZSPR_PLM_FUNCTIONS[2]=__zspr_zplug_load_plugins +ZSPR_PLM_FUNCTIONS[3]=__zspr_zplug_install_plugin +ZSPR_PLM_FUNCTIONS[4]=__zspr_zplug_update_plugins +ZSPR_PLM_FUNCTIONS[5]=__zspr_zplug_has_plugin diff --git a/functions/rationalise-dot.zsh b/modules/rationalize-dot.zsh similarity index 90% rename from functions/rationalise-dot.zsh rename to modules/rationalize-dot.zsh index 5c5ff29..c701b71 100644 --- a/functions/rationalise-dot.zsh +++ b/modules/rationalize-dot.zsh @@ -1,6 +1,9 @@ +# # Alias '...' to do '../..' # Example: type 'cd ...' to get 'cd ../..' -rationalise-dot() { +# + +function rationalise-dot { local MATCH if [[ $LBUFFER =~ '(^|/| | |'$'\n''|\||;|&)\.\.$' ]]; then LBUFFER+=/ @@ -10,5 +13,6 @@ rationalise-dot() { zle self-insert fi } + zle -N rationalise-dot bindkey . rationalise-dot diff --git a/modules/use-zaw-search.zsh b/modules/use-zaw-search.zsh new file mode 100644 index 0000000..11d7d10 --- /dev/null +++ b/modules/use-zaw-search.zsh @@ -0,0 +1,17 @@ +# +# Use ZAW search +# First check if ZAW is installed and sourced +# + +__zspr_plm_has_plugin "zsh-users/zaw" || return + +bindkey '^R' zaw-history +bindkey -M filterselect '^R' up-line-or-history +bindkey -M filterselect '^D' down-line-or-history +bindkey -M filterselect '^E' accept-search + +zstyle ':filter-select:highlight' matched fg=red,standout +zstyle ':filter-select' hist-find-no-dups +zstyle ':filter-select' max-lines 7 +zstyle ':filter-select' rotate-list yes +zstyle ':filter-select' extended-search yes diff --git a/plugins.zsh b/plugins.zsh index 81c7715..1f49056 100644 --- a/plugins.zsh +++ b/plugins.zsh @@ -1,7 +1,18 @@ -# See https://github.com/zplug/zplug -zplug "mafredri/zsh-async" -zplug "sindresorhus/pure" -zplug "zsh-users/zsh-history-substring-search" -zplug "willghatch/zsh-cdr" -zplug "zsh-users/zsh-completions" -zplug "zsh-users/zaw" +# +# zshuper plugins + +# See https://getantibody.github.io/ +# See https://github.com/zplug/zplug/ +# (depends which plugin manager you are currently using) +# + +ZSHUPER_PLUGINS=( + mafredri/zsh-async + sindresorhus/pure + zsh-users/zsh-history-substring-search + willghatch/zsh-cdr + zsh-users/zsh-completions + zsh-users/zaw + #zsh-users/zsh-syntax-highlighting + zdharma/fast-syntax-highlighting +)