diff --git a/.editorconfig b/.editorconfig index cb3c8440..4ccc8cbc 100644 --- a/.editorconfig +++ b/.editorconfig @@ -25,6 +25,3 @@ indent_size = 2 [.git*] indent_size = tab indent_style = tab - -[*.{sh,zsh}] -indent_style = space diff --git a/lib/_zi b/lib/_zi old mode 100644 new mode 100755 diff --git a/lib/git/hooks/post-checkout/README.md b/lib/git/hooks/post-checkout/README.md new file mode 100644 index 00000000..482084f6 --- /dev/null +++ b/lib/git/hooks/post-checkout/README.md @@ -0,0 +1,10 @@ +# Branch specific `.gitignore` + +This `post-checkout` hook will copy `.gitignore.branch_name in place` of `.git/info/exclude` each time with `git checkout branch_name`. + +## Setup + +1. Create new `.gitignore` files for each branch and name it : `.gitignore.branch_name` +2. In your git repo, go to `.git/hooks/` and copy `post-checkout` file there. +3. Make sure permissions are: `chmod +x post-checkout` and `chmod 755 post-checkout` +4. Just go to the branch you want and type `git status`: **TADAAA** ! diff --git a/lib/git/hooks/post-checkout/post-checkout b/lib/git/hooks/post-checkout/post-checkout new file mode 100755 index 00000000..18fa29d2 --- /dev/null +++ b/lib/git/hooks/post-checkout/post-checkout @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +old_ref="$1" +new_ref="$2" +branch_switched="$3" + +if [[ $branch_switched != '1' ]]; then + exit 0 +fi + +echo "=== POST CHECKOUT ===" +current_branch="$(git rev-parse --abbrev-ref HEAD)" +hook_dir="$(dirname $0)" +root_dir="$(pwd -P)" +info_dir="$root_dir/.git/info" +exclude_target='.gitignore' + +if [[ -f "${root_dir}/${exclude_target}.${current_branch}" ]]; then + echo -e "Use .gitignore.${current_branch} to exclude files" + exclude_target=.gitignore.${current_branch} +fi + +builtin cd "$info_dir" || exit +rm exclude +echo -e "Copy .gitignore.${current_branch} where required" +cp "${root_dir}/${exclude_target}" exclude +echo -e "=== POST CHECKOUT END ===" diff --git a/lib/git/pre-commit/.pre-commit-config.yaml b/lib/git/hooks/pre-commit/.pre-commit-config.yaml similarity index 100% rename from lib/git/pre-commit/.pre-commit-config.yaml rename to lib/git/hooks/pre-commit/.pre-commit-config.yaml diff --git a/lib/git/pre-commit/README.md b/lib/git/hooks/pre-commit/README.md similarity index 100% rename from lib/git/pre-commit/README.md rename to lib/git/hooks/pre-commit/README.md diff --git a/lib/zsh/additional.zsh b/lib/zsh/additional.zsh old mode 100644 new mode 100755 diff --git a/lib/zsh/install.zsh b/lib/zsh/install.zsh old mode 100644 new mode 100755 diff --git a/lib/zsh/side.zsh b/lib/zsh/side.zsh old mode 100644 new mode 100755 diff --git a/lib/zsh/zinit.zsh b/lib/zsh/zinit.zsh old mode 100644 new mode 100755 diff --git a/lib/zsh/ztransform b/lib/zsh/ztransform new file mode 100755 index 00000000..cf4b5b78 --- /dev/null +++ b/lib/zsh/ztransform @@ -0,0 +1,100 @@ +#!/usr/bin/zsh +# vim:ft=zsh + +setopt extendedglob + +fpath+=( "${0%/*}" ) +autoload zplg-process-buffer + +local name="$1" +local doc="$(<$name)" token prev_token="" spaces prev_spaces="" next_token next_spaces + +local preamble="" fun_name="" +local -A funs + +integer next_fun=0 cur_fun=0 prev_fun=0 +integer depth=0 prev_depth=0 fun_depth=-1 anon_depth=-1 descentff=0 descentfa=0 + +zplg-process-buffer "$doc" 1 +integer i size="${#ZPLG_PB_WORDS}" + +for (( i=1; i<=size; ++ i )); do + token="${ZPLG_PB_WORDS[i]}" + spaces="${ZPLG_PB_SPACES[i]}" + next_token="${ZPLG_PB_WORDS[i+1]}" + next_spaces="${ZPLG_PB_SPACES[i+1]}" + cur_fun=0 prev_fun=0 descentff=0 descentfa=0 + + (( next_fun )) && { next_fun=0 cur_fun=1 prev_fun=0 anon_depth=-1 } + + # Explicit future function + if [[ "$token" = "function" ]]; then + next_fun=1 cur_fun=0 prev_fun=0 anon_depth=-1 + # Detect function if not already in function + elif [[ "$token" = "()" && ( "$fun_depth" -lt 0 ) && ( $anon_depth -lt 0 ) ]]; then + if [[ "$spaces" = *$'\n'* || -z "$prev_token" ]]; then + next_fun=0 cur_fun=0 prev_fun=0 anon_depth=$depth + else + next_fun=0 cur_fun=0 prev_fun=1 anon_depth=-1 + fi + elif [[ "$token" = "{" ]]; then + (( ++ depth )) + elif [[ "$token" = "}" ]]; then + (( -- depth )) + fi + + if (( cur_fun )); then + fun_name="$token" + fun_depth="$depth" + elif (( prev_fun )); then + fun_name="$prev_token" + fun_depth="$depth" + fi + + # Ascent to function - skip '{' + if (( fun_depth >= 0 && depth == (fun_depth + 1) )) && [[ "$token" = "{" ]]; then + : + # In-function + elif (( fun_depth >= 0 && depth > fun_depth )); then + if [[ "$token" != [[:space:]]#\#* ]]; then + funs[$fun_name]+="${spaces}${token}" + fi + # Descent from function - skip '}' + elif (( fun_depth >= 0 && depth == fun_depth && prev_depth == fun_depth + 1 )); then + descentff=1 + # Descent from anon + elif (( anon_depth >= 0 && depth == anon_depth && prev_depth == anon_depth + 1 )); then + descentfa=1 + fi + + # Anon function in top-level + if (( anon_depth >= 0 && fun_depth < 0 )); then + [[ "$token" != [[:space:]]#\#* ]] && preamble+="${spaces}${token}" + fi + + # Late disable of (anon) + if (( descentfa )); then + anon_depth=-1 + elif (( descentff )); then + fun_name="" + fun_depth=-1 + # No-function printing + elif (( next_fun == 0 && cur_fun == 0 && prev_fun == 0 && anon_depth < 0 && fun_depth < 0 )); then + if [[ "$next_token" != "()" || "$next_spaces" = *$'\n'* ]]; then + [[ "$token" != [[:space:]]#\#* ]] && preamble+="${spaces}${token}" + fi + fi + + prev_depth="$depth" + prev_token="$token" + prev_spaces="$spaces" +done + +print -r -- "$preamble" >| "preamble.zini" + +for fun_name in "${(ko@)funs}"; do + print -r -- "[${fun_name}"$'\C-A'"fun]" + print -r -- "${funs[$fun_name]}" + print -r -- "PLG_END_F" + print +done >| "functions.zini" diff --git a/zi.zsh b/zi.zsh old mode 100644 new mode 100755 index 18f26d64..f941d970 --- a/zi.zsh +++ b/zi.zsh @@ -2464,7 +2464,7 @@ cdclear|delete) ]]; then reply=( ${ZI_EXTS[(I)z-annex subcommand:*]} ) - [[ -n $1 && $1 != (-h|--help|help|analytics|man|self-update|times|zstatus|load|light|unload|snippet|ls|ice|\ + [[ -n $1 && $1 != (-h|--help|help|analytics|control|man|self-update|times|zstatus|load|light|unload|snippet|ls|ice|\ update|status|report|delete|loaded|list|cd|create|edit|glance|stress|changes|recently|clist|\ completions|cclear|cdisable|cenable|creinstall|cuninstall|csearch|compinit|dtrace|dstart|dstop|\ dunload|dreport|dclear|compile|uncompile|compiled|cdlist|cdreplay|cdclear|srv|recall|\ @@ -2774,12 +2774,6 @@ You can try to prepend {apo}${___q}{lhi}@{apo}'{error} to the ID if the last ice (self-update) .zi-self-update ;; - (analytics) - .zi-analytics-menu - ;; - (control) - .zi-control-menu - ;; (unload) (( ${+functions[.zi-unload]} )) || builtin source "${ZI[BIN_DIR]}/lib/zsh/autoload.zsh" || return 1 if [[ -z $2 && -z $3 ]]; then @@ -2949,6 +2943,12 @@ You can try to prepend {apo}${___q}{lhi}@{apo}'{error} to the ID if the last ice shift .zi-recently "$@"; ___retval=$? ;; + (control) + .zi-control-menu + ;; + (analytics) + .zi-analytics-menu + ;; (-h|help) .zi-help ;; @@ -3018,12 +3018,16 @@ zicompdef() { ZI_COMPDEF_REPLAY+=( "${(j: :)${(q)@}}" ); } } # ]]] # Compatibility functions. [[[ -#zinit() { zi "$@"; } +zinit() { zi "$@"; } zpcdreplay() { .zi-compdef-replay -q; } zpcdclear() { .zi-compdef-clear -q; } zpcompinit() { autoload -Uz compinit; compinit -d ${ZI[ZCOMPDUMP_PATH]:-${ZDOTDIR:-$HOME}/.zcompdump} "${(Q@)${(z@)ZI[COMPINIT_OPTS]}}"; } zpcompdef() { ZI_COMPDEF_REPLAY+=( "${(j: :)${(q)@}}" ); } # ]]] +# FUNCTION: zt. [[[ +# Common ICE modifier to simplify Turbo mode. +zt() { zi depth'3' lucid ${1/#[0-9][a-d]/wait"${1}"} "${@:2}"; } +# ]]] # # Source-executed code. @@ -3042,7 +3046,8 @@ zmodload zsh/zpty zsh/system 2>/dev/null zmodload -F zsh/stat b:zstat 2>/dev/null && ZI[HAVE_ZSTAT]=1 # code. [[[ -builtin alias zpl=zi zplg=zi zini=zi zinit=zi +builtin alias zpl=zi zplg=zi zini=zi + .zi-prepare-home # Remember source's timestamps for the automatic-reload feature.