@@ -65,12 +65,21 @@ function print_help() {
6565 printf " \nRequired arguments:\n"
6666 printf " -p <path> %s\n" " Path to directoy to watch for changes."
6767 printf " -a <cmd> %s\n" " Command to execute when a directory was added."
68- printf " %s\n" " The full path of the new dir will be appended as an argument to this command."
68+ printf " %s\n" " You can also append the following placeholders to your command string:"
69+ printf " %s\n" " %p The full path of the directory that changed (added, deleted)."
70+ printf " %s\n" " %n The name of the directory that changed (added, deleted)."
71+ printf " %s\n" " Example: -a \" script.sh -f %p -c %n -a %p\" "
6972 printf " -d <cmd> %s\n" " Command to execute when a directory was deletd."
70- printf " %s\n" " The full path of the new dir will be appended as an argument to this command."
73+ printf " %s\n" " You can also append the following placeholders to your command string:"
74+ printf " %s\n" " %p The full path of the directory that changed (added, deleted)."
75+ printf " %s\n" " %n The name of the directory that changed (added, deleted)."
76+ printf " %s\n" " Example: -b \" script.sh -f %p -c %n -a %p\" "
7177 printf " \nOptional arguments:\n"
7278 printf " -t <cmd> %s\n" " Command to execute after all directories have been added or deleted during one round."
7379 printf " %s\n" " No argument will be appended."
80+ printf " %s\n" " %p The full path of the directory that changed (added, deleted)."
81+ printf " %s\n" " %n The name of the directory that changed (added, deleted)."
82+ printf " %s\n" " Example: -t \" script.sh -f %p -c %n -a %p\" "
7483 printf " -w <str> %s\n" " The directory watcher to use. Valid values are:"
7584 printf " %s\n" " 'inotify': Uses inotifywait to watch for directory changes."
7685 printf " %s\n" " 'bash': Uses a bash loop to watch for directory changes."
@@ -101,8 +110,14 @@ function action() {
101110 local action=" ${2} " # Add/Del command to execute
102111 local info=" ${3} " # Output text (ADD or DEL) for verbose mode
103112 local verbose=" ${4} " # Verbose?
113+ local name
114+ name=" $( basename " ${directory} " ) "
104115
105- if eval " ${action} ${directory} " ; then
116+ # Fill with placeholder values
117+ action=" ${action//% p/ ${directory} } "
118+ action=" ${action//% n/ ${name} } "
119+
120+ if eval " ${action} " ; then
106121 if [ " ${verbose} " -gt " 0" ]; then
107122 printf " [%s] [OK] %s succeeded: %s\n" " $( date ' +%Y-%m-%d %H:%M:%S' ) " " ${info} " " ${directory} "
108123 fi
0 commit comments