From d7629b994db29b3908bdf393db78defe8edc1e8d Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Sun, 7 Jul 2019 21:43:05 +0100 Subject: [PATCH] Move common parts to zsh.common and fix make --- %dircolors/.config/zshrc.d/fix-dircolors.zsh | 7 ++++ %zsh.grml/.zshrc.local | 39 +------------------- Makefile | 21 +++++------ brew/.config/zshrc.d/brew.zsh | 2 +- zsh.common/.config/zsh/autoload.zsh | 19 ++++++++++ zsh.common/.config/zsh/extras.zsh | 29 +++++++++++++++ zsh.common/.config/zshrc.d/autoload.zsh | 10 ----- 7 files changed, 68 insertions(+), 59 deletions(-) create mode 100755 %dircolors/.config/zshrc.d/fix-dircolors.zsh create mode 100755 zsh.common/.config/zsh/autoload.zsh create mode 100755 zsh.common/.config/zsh/extras.zsh delete mode 100755 zsh.common/.config/zshrc.d/autoload.zsh diff --git a/%dircolors/.config/zshrc.d/fix-dircolors.zsh b/%dircolors/.config/zshrc.d/fix-dircolors.zsh new file mode 100755 index 0000000..8966263 --- /dev/null +++ b/%dircolors/.config/zshrc.d/fix-dircolors.zsh @@ -0,0 +1,7 @@ +#!/usr/bin/env zsh +# Fix terminal colors +local __dircolors_config=~/.config/dircolors/dircolors.solarized-256-dark +if [ -f "${__dircolors_config}" ]; then + eval "$(dircolors "${__dircolors_config}")" +fi +unset __dircolors_config diff --git a/%zsh.grml/.zshrc.local b/%zsh.grml/.zshrc.local index d22f361..352f6ba 100644 --- a/%zsh.grml/.zshrc.local +++ b/%zsh.grml/.zshrc.local @@ -1,45 +1,10 @@ #!/usr/bin/env zsh -# Fix terminal colors -local __dircolors_config=~/.config/dircolors/dircolors.solarized-256-dark -if [ -f "${__dircolors_config}" ]; then - eval "$(dircolors "${__dircolors_config}")" -fi -unset __dircolors_config - # Adjust PATH export -U PATH="$HOME/.local/bin:$PATH" export -U FPATH="$XDG_CONFIG_HOME/zshrc.d/autoloaded/:$FPATH" -# Imports -# Source configurations from extra files {{{ -function __zshrc_load_extra() { - local cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/zsh" - local fp="$cache_dir/extras-cache.zsh" - local -U extra priv list - - if [ ! -f "$fp" ]; then - echo "Compiling extra zshrc files" - extra=( - # Meant for external installations, just check if file exists: - /usr/share/autojump/autojump.zs[h](N) # [h] -> POG to activate glob - - # Check if the file is executable (so we can deactivate it with chmod) - $HOME/.config/zsh/+local*.zsh(xN) - # ^ Files specific to host, not shared via dotfiles - $HOME/.config/zshrc.d/?*.zsh(xN) - # ^ Files from other program configurations (e.g. TMUX) - ) - set -x - mkdir -p "$cache_dir" - cat $extra > "$fp" - zcompile "$fp" - set +x - fi - source "$fp" -} -__zshrc_load_extra -unset -f __zshrc_load_extra # avoid lambdas so zprof can be used -# }}} +source "$XDG_CONFIG_HOME/zsh/autoload.zsh" +source "$XDG_CONFIG_HOME/zsh/extras.zsh" # SSH/GPG Agents ssh-init diff --git a/Makefile b/Makefile index 75dbe53..f9dd278 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ ## Define Targets DOTFILES := ${HOME}/.dotfiles XDG_CONFIG_HOME := ${HOME}/.config -ifneq (,$(wildcard "${XDG_CONFIG_HOME}/zsh")) +ifneq (,$(wildcard ${XDG_CONFIG_HOME}/zsh)) ZSH_USES_XDG = "true" ZDOTDIR := ${XDG_CONFIG_HOME}/zsh else @@ -14,22 +14,21 @@ ZDOT_FLAGS := -maxdepth 1 \( -not -type d \) -and \( -iname ".pathrc" -or -iname AUTOLOAD_FILES := $(shell find -L ${AUTOLOAD} -not -iname ".*" -not -iname "*.zwc" -not -type d) ZDOT_FILES := $(shell find -L ${ZDOTDIR} -maxdepth 1 \( -not -type d \) -and \( -iname ".pathrc" -or -iname ".zsh*" \) -not -iname ".zsh_history" -not -iname ".*.zwc") -ZSH_FILES := $(shell find -L ${ZSHRCD} -maxdepth 1 -iname "*.zsh" -not -type d) \ - $(shell find -L ${ZDOTDIR} -maxdepth 1 -iname "*.zsh" -not -type d) - -AUTOLOAD_TARGET := $(addsuffix .zwc,${AUTOLOAD_FILES}) -ZDOT_TARGET := $(addsuffix .zwc,${ZDOT_FILES}) -ZSH_TARGET := ${ZSH_FILES:.zsh=.zwc} -TARGET := ${AUTOLOAD_TARGET} ${ZDOT_TARGET} ${ZSH_TARGET} +ZSH_FILES := $(shell find -L ${ZSHRCD} ${ZDOTDIR} -maxdepth 1 -iname "*.zsh" -not -type d) +SRC_FILES:= ${AUTOLOAD_FILES} ${ZDOT_FILES} ${ZSH_FILES} +TARGET := $(addsuffix .zwc,${SRC_FILES}) default: pre-compile pre-compile: ${TARGET} -${ZDOT_TARGET} ${AUTOLOAD_TARGET}: %.zwc: % - zsh -c 'zcompile $<' +info: + @echo "ZDOTDIR ${ZDOTDIR}" + @echo "ZDOT: ${ZDOT_FILES}" + @echo "ZSH: ${ZSH_FILES}" + @echo "AUTOLOAD: ${AUTOLOAD_FILES}" -${ZSH_TARGET}: %.zwc: %.zsh +${TARGET}: %.zwc: % zsh -c 'zcompile $<' clean: diff --git a/brew/.config/zshrc.d/brew.zsh b/brew/.config/zshrc.d/brew.zsh index 89796d4..f1754fd 100755 --- a/brew/.config/zshrc.d/brew.zsh +++ b/brew/.config/zshrc.d/brew.zsh @@ -22,7 +22,7 @@ __zshrc_brew() { set -x mkdir -p "$cache_dir" "$brew_root/bin/brew" shellenv > "$fp" - zcompile "$fp" + zcompile "$fp" &! set +x break fi diff --git a/zsh.common/.config/zsh/autoload.zsh b/zsh.common/.config/zsh/autoload.zsh new file mode 100755 index 0000000..a8fc9f0 --- /dev/null +++ b/zsh.common/.config/zsh/autoload.zsh @@ -0,0 +1,19 @@ +#!/usr/bin/env zsh +# Autoload Functions + +__zshrc_autoload() { + local cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/zsh" + local fp="$cache_dir/autoload-cache.zsh" + if [ ! -f $fp ]; then + echo "Compiling autoload directive" + set -x + local -U autoloaded=($XDG_CONFIG_HOME/zshrc.d/autoloaded/[^_]*(xN:t)) + mkdir -p "$cache_dir" + echo -e "#!/usr/bin/env zsh\nautoload -Uz ${autoloaded[*]}" > "$fp" + zcompile "$fp" &! + set +x + fi + source "$fp" +} +__zshrc_autoload +unset -f __zshrc_autoload # avoid lambdas so we can use zprof diff --git a/zsh.common/.config/zsh/extras.zsh b/zsh.common/.config/zsh/extras.zsh new file mode 100755 index 0000000..183294f --- /dev/null +++ b/zsh.common/.config/zsh/extras.zsh @@ -0,0 +1,29 @@ +#!/usr/bin/env zsh + +function __zshrc_load_extra() { + local cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/zsh" + local fp="$cache_dir/extras-cache.zsh" + local -U extra priv list + + if [ ! -f "$fp" ]; then + echo "Compiling extra zshrc files" + extra=( + # Meant for external installations, just check if file exists: + /usr/share/autojump/autojump.zs[h](N) # [h] -> POG to activate glob + + # Check if the file is executable (so we can deactivate it with chmod) + $HOME/.config/zsh/+local*.zsh(xN) + # ^ Files specific to host, not shared via dotfiles + $HOME/.config/zshrc.d/?*.zsh(xN) + # ^ Files from other program configurations (e.g. TMUX) + ) + set -x + mkdir -p "$cache_dir" + cat $extra > "$fp" + zcompile "$fp" &! + set +x + fi + source "$fp" +} +__zshrc_load_extra +unset -f __zshrc_load_extra # avoid lambdas so zprof can be used diff --git a/zsh.common/.config/zshrc.d/autoload.zsh b/zsh.common/.config/zshrc.d/autoload.zsh deleted file mode 100755 index d661377..0000000 --- a/zsh.common/.config/zshrc.d/autoload.zsh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env zsh -# Autoload Functions - -__zshrc_autoload() { - local fp - fpath=($XDG_CONFIG_HOME/zshrc.d/autoloaded $fpath) - for fp in $XDG_CONFIG_HOME/zshrc.d/autoloaded/*(x); autoload -Uz $fp -} -__zshrc_autoload -unset -f __zshrc_autoload # avoid lambdas so we can use zprof