Blindfold uses emitter library for fake/custom event listening
The following list of events are already emitted in blindfold.bash all you need to do is attach the event and sepcify a function to execute whenever the event is emitted
list of emitted event that you should attach
- newFile
when a new file is created
- modifyFile
when a file is edited
- deleteFile
when a file is deleted
- newDir
when a new directory is created
- deleteFolder
when a folder is deleted
you should attach the event like this
event attach newFile functionToExecute
event attach modifyFile functionToExecute
event attach deleteFile functionToExecute
event attach newDir functionToExecute
event attach deleteFolder functionToExecute
using blindfold with traceur
you have to source blindfold in your script
source ../blindfold.bash
# This function will be executed when a new file is created
_nfile() {
local newfile=$2
if [[ "${newfile##*.}" != 'js' ]];then
printf "%s\n%s" "only javascript file are strictly allowed here" "this file has been moved to /tmp"
mv "$newfile" /tmp
return ;
fi
printf "%s\n" "javascript file detected , now watching $newfile"
}
# This function will be executed when a file is modified
_nmodfile() {
local filename=${1}
local access=${4}
local status
which traceur 1>/dev/null
status=$?
(( status == 0 )) && {
traceur "${filename}" --out /tmp/bb.js 2>/dev/null
status=$?
(( status == 0 )) && {
printf "%s\n" "This file has been transpiled successfully"
} || {
printf "%s\n" "Error transpiling file"
}
}
}
# This function will be executed when a file is deleted
_ndeletefile() {
local filedel="${1}"
printf "%s\n" "${filedel} removed from watch list"
}
# This function will be executed when a new directory is created
_nDir() {
local newdire="${2}"
printf "%s\n" "${newdire} added to watch list"
}
# This function will be executed when a folder is deleted
_ndeleteDir() {
local deldir="${1}"
printf "%s\n" "${deldir} has been deleted including all files and subfolder"
}
next thing to do is to attach the events
event attach newFile _nfile
event attach modifyFile _nmodfile
event attach deleteFile _ndeletefile
event attach newDir _nDir
event attach deleteFolder _ndeleteDir
after attaching the listeners call the blindfold function
blindfold "${@}"
-
when a new file is created ,
newFile
listener is emitted and two argument is passed to the function that will be executed when the event is emittedfirst_arg > the directory the file was created
second_arg > new file name
-
when a file is modified ,
modifyFile
listener is emitted and seven argument is passed to the function that will be executedfirst_arg > file name
second_arg > group id
third_arg > group owner id
fourt_arg > hexadecimal value for access right
fifth_arg > user id
sixth_arg > user owner name
seventh_arg > size of the file in bytes
-
when a file is deleted ,
deleteFile
listener is emitted and a single argument is passed to the function to executefirst_arg > name of deleted file
-
when a directory is created,
newDir
listener is emitted and two argument are passed to the function to executefirst_arg > name of parent folder
second_arg > name of new folder
-
when a directory is deleted,
deleteFolder
listener is emitted and a single argument is passed to the function to executefirsrt_arg > name of deleted file
- blindfold only accepts directory names . It can take more than one directory
- blindfold ignores arguments that are regular or charcter or socket or block files and gets stuck in its event loop
- readlink or realpath
- stat
UAHYW ( USE ANY HOW YOU WANT ) lol