-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
151 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,3 @@ indent_size = 2 | |
[.git*] | ||
indent_size = tab | ||
indent_style = tab | ||
|
||
[*.{sh,zsh}] | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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** ! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ===" |
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
done >| "functions.zini" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters