From 6c3826e32dc5951be46f2815490de2cb36c86fb1 Mon Sep 17 00:00:00 2001 From: crater2150 Date: Mon, 11 Feb 2019 15:36:37 +0100 Subject: [PATCH] Clean up modules and loading --- completion.zsh | 32 +++++++++++++++++++++-- modules/autoloader/init | 2 +- modules/completion/init | 39 ---------------------------- modules/conf/init | 23 ++++++++++++++++- modules/fuck/init | 3 --- modules/highlight/init | 2 +- modules/percol/init | 14 ----------- modules/project/init | 56 ----------------------------------------- modules/ssh-agent/init | 27 -------------------- modules/ssh/init | 12 --------- zshrc | 21 +++------------- 11 files changed, 57 insertions(+), 174 deletions(-) delete mode 100644 modules/completion/init delete mode 100644 modules/fuck/init delete mode 100755 modules/percol/init delete mode 100755 modules/project/init delete mode 100644 modules/ssh-agent/init delete mode 100644 modules/ssh/init diff --git a/completion.zsh b/completion.zsh index 05c10dd..bf9c0dc 100644 --- a/completion.zsh +++ b/completion.zsh @@ -6,17 +6,45 @@ fpath=( "${ZDOTDIR:+$ZDOTDIR/compdef}" "/etc/zsh/compdef" $fpath ) autoload -Uz compinit && compinit -u -zstyle ':completion:*' verbose yes zstyle ':completion:*:descriptions' format ‘%B%d%b’ zstyle ':completion:*:messages' format ‘%d’ zstyle ':completion:*:warnings' format ‘No matches for: %d’ +zstyle ':completion:*' use-cache on +zstyle ':completion:*' cache-path ~/.zsh/cache +zstyle ':completion:*' completer _complete _ignored _match _approximate _correct +zstyle ':completion:*:match:*' original only +zstyle ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)' +zstyle ':completion:*:functions' ignored-patterns '_*' +zstyle ':completion:*' squeeze-slashes true +zstyle ':completion:*' expand prefix suffix +zstyle ':completion:*' group-name '' +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s' +zstyle ':completion:*' list-suffixes true +zstyle ':completion:*' preserve-prefix '//[^/]##/' +zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s' +zstyle ':completion:*' special-dirs true +zstyle ':completion:*' verbose true +zstyle :compinstall filename '/etc/zsh/completion' # completion for programs with standard gnu --help -for prog in amm tapestry; do +for prog in amm tapestry virtualenv; do compdef _gnu_generic $prog done # custom compdefs compdef _xbps xi=xbps-install + +{ + local _myhosts + _myhosts=( $(awk '/^Host/ {for (i=2; i<=NF; i++) print $i}' ~/.ssh/config) ) + zstyle ':completion:*' hosts $_myhosts +}&>/dev/null + +zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq' + +compdef _command fork +compdef _command detach +compdef _command ontv diff --git a/modules/autoloader/init b/modules/autoloader/init index 7a7bc07..28eb1ce 100644 --- a/modules/autoloader/init +++ b/modules/autoloader/init @@ -38,7 +38,7 @@ done for dir in $ZFUNCTIONPATH; do if [ -d $dir ]; then for i in $dir/*~*.zwc(N:t); do - autoload -Uz $i && $i + autoload -Uz $i done fi done diff --git a/modules/completion/init b/modules/completion/init deleted file mode 100644 index 14bacd9..0000000 --- a/modules/completion/init +++ /dev/null @@ -1,39 +0,0 @@ - -# The following lines were added by compinstall - -#zstyle ':completion::complete:*' completer _complete _ignored _correct - -zstyle ':completion:*' use-cache on -zstyle ':completion:*' cache-path ~/.zsh/cache -zstyle ':completion:*' completer _complete _ignored _match _approximate _correct -zstyle ':completion:*:match:*' original only -zstyle ':completion:*:approximate:*' max-errors 'reply=($((($#PREFIX+$#SUFFIX)/3))numeric)' -zstyle ':completion:*:functions' ignored-patterns '_*' -zstyle ':completion:*' squeeze-slashes true -zstyle ':completion:*' expand prefix suffix -zstyle ':completion:*' group-name '' -zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} -zstyle ':completion:*' list-prompt '%SAt %p: Hit TAB for more, or the character to insert%s' -zstyle ':completion:*' list-suffixes true -zstyle ':completion:*' preserve-prefix '//[^/]##/' -zstyle ':completion:*' select-prompt '%SScrolling active: current selection at %p%s' -zstyle ':completion:*' special-dirs true -zstyle ':completion:*' verbose true -zstyle :compinstall filename '/etc/zsh/completion' - -autoload -Uz compinit -compinit -# End of lines added by compinstall - -# ssh known hosts complete -{ - local _myhosts - _myhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} ) - zstyle ':completion:*' hosts $_myhosts -}&>/dev/null - -zstyle ':completion:*:processes-names' command 'ps c -u ${USER} -o command | uniq' - -compdef _command fork -compdef _command detach -compdef _command ontv diff --git a/modules/conf/init b/modules/conf/init index 8b66981..9e68425 100755 --- a/modules/conf/init +++ b/modules/conf/init @@ -1,7 +1,26 @@ #!/bin/zsh +typeset -Ax conf_locations + conf() { - local target=${conf_locations[${1}]} + if [[ $1 == -r ]]; then + local confconf=$(zdotfile confs) + if [[ -e $confconf ]]; then + conf_locations[conf]=$confconf + conf_locations+=( $(<$confconf) ) + fi + return + fi + + if [[ -z $1 ]]; then + echo "Available configs:" + for k v in ${(kv)conf_locations}; do + printf "%-20s %s\n" ${k}: ${(e)v} + done + return 1 + fi + + local target=${(e)conf_locations[${1}]} if [[ -d ${target} ]]; then cd ${target} if ! [[ -w ${target} ]]; then @@ -20,3 +39,5 @@ conf() { fi } + +conf -r diff --git a/modules/fuck/init b/modules/fuck/init deleted file mode 100644 index 40203d6..0000000 --- a/modules/fuck/init +++ /dev/null @@ -1,3 +0,0 @@ -if exists thefuck; then - eval "$(thefuck --alias)" -fi diff --git a/modules/highlight/init b/modules/highlight/init index c4ffec2..9bfbc2d 100644 --- a/modules/highlight/init +++ b/modules/highlight/init @@ -1,4 +1,4 @@ -. $MPATH/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh +. /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern) diff --git a/modules/percol/init b/modules/percol/init deleted file mode 100755 index 90c035e..0000000 --- a/modules/percol/init +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/zsh - -if exists percol; then - function percol_select_history() { - local tac - exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r" } } - BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER") - CURSOR=$#BUFFER # move cursor - zle -R -c # refresh - } - - zle -N percol_select_history - bindkey '^R' percol_select_history -fi diff --git a/modules/project/init b/modules/project/init deleted file mode 100755 index 3bc1b88..0000000 --- a/modules/project/init +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/zsh - -typeset -ag ZP_LIST - -local load-project-list() { - ZP_LIST=( $ZDOTDIR/projects/*(N:t) ) -} -load-project-list - -project() { - case "$1" in - reload) - load-project-list - echo "${(j:\n:)ZP_LIST}" - ;; - close) - unset ZPROJECT - ;; - open) - shift - open-project "$@" - ;; - esac -} - -_project_open() { - _arguments "2:project:($ZP_LIST)" - #_alternative "project:project:($ZP_LIST)" -} - -_project() { - _arguments "1:Action:->action" \ - "*: :->args" - case "$state" in - action) - _arguments '1:action:(open close reload)' - ;; - args) - _project_$words[2] - ;; - esac -} -compdef _project project - -local open-project() { - typeset -gA ZPROJECT - ZPROJECT[name]="$1" - source $ZDOTDIR/projects/$1 - pcd -} - -pcd() { - cd ${ZPROJECT[path]} -} - -alias pp=project diff --git a/modules/ssh-agent/init b/modules/ssh-agent/init deleted file mode 100644 index 22c08e7..0000000 --- a/modules/ssh-agent/init +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/zsh -# start ssh-agent on first opened shell, retrieve information on all others from -# file -SSH_ENV="$HOME/.ssh/environment" - -[ -e "${SSH_ENV:h}" ] || mkdir -p "${SSH_ENV:h}" - -function start_agent { - echo "Initialising new SSH agent..." - /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" - echo succeeded - chmod 600 "${SSH_ENV}" - . "${SSH_ENV}" > /dev/null -} - -# Source SSH settings, if applicable - -if [ -f "${SSH_ENV}" ]; then - . "${SSH_ENV}" > /dev/null - #ps ${SSH_AGENT_PID} doesn't work under cywgin - ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { - start_agent; - } -else - start_agent; -fi - diff --git a/modules/ssh/init b/modules/ssh/init deleted file mode 100644 index d6d8620..0000000 --- a/modules/ssh/init +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/zsh -h=() -if [[ -r ~/.ssh/config ]]; then - h=($h ${${${(@M)${(f)"$(cat ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*}) -fi -if [[ -r ~/.ssh/known_hosts ]]; then - h=($h ${${${(f)"$(cat ~/.ssh/known_hosts{,2} || true)"}%%\ *}%%,*}) 2>/dev/null -fi -if [[ $#h -gt 0 ]]; then - zstyle ':completion:*:ssh:*' hosts $h - zstyle ':completion:*:slogin:*' hosts $h -fi diff --git a/zshrc b/zshrc index 3b9b2da..ac7f574 100644 --- a/zshrc +++ b/zshrc @@ -25,8 +25,10 @@ zdotfile() { fi } +. $(zdotfile completion.zsh) +source $(zdotfile zplug.zsh) + bindkey -v -autoload -Uz zmv function exists { command -v "$@" >/dev/null } ZMODLOAD_BLACKLIST=( ssh-agent ) @@ -43,23 +45,6 @@ echo $PATH | grep -q 'local' || . /etc/zsh/zprofile echo $PATH | grep -q 'sbin' || . /etc/zsh/zprofile -typeset -A conf_locations -conf_locations=( - vim $XDG_CONFIG_HOME/vim - awesome $XDG_CONFIG_HOME/awesome - mutt $HOME/.mutt/muttrc - xd $XDG_CONFIG_HOME/xd.conf - zsh /etc/zsh - offlineimap $XDG_CONFIG_HOME/offlineimap/config - compose $HOME/.XCompose.long - vdirsyncer $HOME/.vdirsyncer/config - xd $XDG_CONFIG_HOME/xd.conf - ssh $HOME/.ssh/config -) - - -. $(zdotfile completion.zsh) - FZF_ALT_C_COMMAND="fd -t d" [[ -e /usr/share/doc/fzf/key-bindings.zsh ]] && . /usr/share/doc/fzf/key-bindings.zsh