diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b8de10..34dc2ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,15 +16,19 @@ Security - in case of vulnerabilities. ## [Unreleased] ### Added -- Added hook `disallow-commits` -- Added hook `conventional-commit` -- Added hook `php-cs-fixer` +- Added hook `disallow-commits`. +- Added hook `conventional-commit`. +- Added hook `php-cs-fixer`. - Added help to all hooks, available on running hook with argument `-h` or `--help`. +## Changed +- Allowed multiple commands per file patterns in the `files-watcher`. + + ## [1.1.0] 2019-03-01 ### Added -- Added hook `motivation` -- Added hook `files-watcher` +- Added hook `motivation`. +- Added hook `files-watcher`. ## [1.0.0] 2019-03-01 Initial release. diff --git a/files-watcher/files-watcher b/files-watcher/files-watcher index c8026ab..0de503d 100755 --- a/files-watcher/files-watcher +++ b/files-watcher/files-watcher @@ -35,7 +35,7 @@ FCS='\033[0;37m' # Light gray (silver) NC='\033[0m' CMD="files-watcher" -VERSION="1.0.0" +VERSION="1.1.0" HOME="https://github.com/slavcodev/git-hooks-scripts" ABOUT="${FCG}Files watcher${NC} version ${FCY}$VERSION${NC}" HELP="$ABOUT @@ -50,6 +50,7 @@ ${FCS}~~~ mode = \"auto\" [${CMD} \"composer\.(json|lock)$\"] + command = \"composer self-update\" command = \"composer install -n\" [${CMD} \".php$\"] @@ -100,7 +101,7 @@ main() { fi watch_tasks_config_pattern=files-watcher\..\*\.command - watch_tasks=$(git config --name-only --get-regexp ${watch_tasks_config_pattern}) + watch_tasks=$(git config --name-only --get-regexp ${watch_tasks_config_pattern} | sort -u) if [[ -z ${watch_tasks} ]]; then exit @@ -122,7 +123,6 @@ main() { changed_files=$(git diff HEAD@\{1\} --name-only --diff-filter=ACMRTUXB | grep -iE ${pattern}) - command=$(git config --type path --get ${task}) mode=$(git config --default ${default_mode} --get ${task%.*}.mode) if [[ -n ${changed_files} ]]; then @@ -132,23 +132,34 @@ main() { echo "- ${FCS}${file}${NC}" done - case "${mode}" in - "auto" ) - command ${command} - ;; - "prompt" ) - if prompt "Do you like to run '${command}'?"; then - command ${command} - fi - ;; - "confirm" ) - if confirm "Do you like to run '${command}'?"; then + previous_ifs=${IFS} + IFS=' +' + commands="$(git config --type path --get-all ${task})" + + set -f + for command in ${commands} ; do + case "${mode}" in + "auto" ) command ${command} - fi - ;; - * ) - echo "${FCR}Invalid mode option${NC}" - esac + ;; + "prompt" ) + if prompt "Do you like to run '${command}'?"; then + command ${command} + fi + ;; + "confirm" ) + if confirm "Do you like to run '${command}'?"; then + command ${command} + fi + ;; + * ) + echo "${FCR}Invalid mode option${NC}" + esac + done + set +f + + IFS=${previous_ifs} fi done