Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
It also has some logging for filtering files
  • Loading branch information
kevin-lee committed Apr 11, 2015
1 parent c54ff16 commit bc88afa
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,44 @@ function wikify() {
fi
}

# to enable log, run
# git config wikify.log true
#
# result:
# [INFO] some info blah blah
#
# to remove logging,
# git config --unset wikify.log
function log_info() {
local should_log=$(git config --get wikify.log)
if [[ -n "$should_log" && "$should_log" = "true" ]]; then
if [[ -n "$2" ]]; then
local log_level="$(echo "$1" | tr 'a-z' 'A-Z')"
local log_message="$2"
echo "[$log_level] $log_message"
else
echo "[INFO] $@"
fi
fi
}

# Filter some files and directories.
function continue_if_filtered() {
if [[ "$@" =~ "images$" ]]; then
# $1 filename
# $2 directory

if [[ "$1" =~ "images$" ]]; then
log_info "$1: images so ignored."
continue
elif [[ ( -n "$2" && $(file "$2/$1" | grep ".*: .* image.*," | sed "s;.*: .*\(image\)[^,]*, .*;\1;") == "image" ) || ( $(file "$1" | grep ".*: .* image.*," | sed "s;.*: .*\(image\)[^,]*, .*;\1;") == "image" ) ]]; then
# check file type and ignore it if it's image
log_info "$1: image so ignored."
continue
elif [[ "$@" =~ "(_sidebar|_footer|_header)" ]]; then
elif [[ "$1" =~ "(_sidebar|_footer|_header)" ]]; then
log_info "$1 in (_sidebar|_footer|_header) so ignored."
continue
elif [[ "$@" == "." ]]; then
elif [[ "$1" == "." ]]; then
log_info "$1: ignored"
continue
fi
}
Expand Down Expand Up @@ -123,7 +154,7 @@ function wikify() {
fi

for file in $(gls_or_ls -l -v $@ | awk '{ print $9 }'); do;
continue_if_filtered $file
continue_if_filtered $file $@
file="$@/$file"

if [[ "$(file -ib $file)" =~ "directory" ]]; then
Expand Down

0 comments on commit bc88afa

Please sign in to comment.