mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-11-24 12:31:31 +01:00
zsh: functions: add watch_file function
this can be used to watch a file for changes and execute the given action on changes.
This commit is contained in:
parent
e08ee08768
commit
d72886b6c1
|
@ -284,3 +284,19 @@ function mangrep() {
|
||||||
|
|
||||||
MANPAGER="less -p \"$pattern\"" man "$cmd"
|
MANPAGER="less -p \"$pattern\"" man "$cmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# watches the given file and executes the given action whenever the file is changed. Usage: watch_file <file> <command>
|
||||||
|
function watch_file() {
|
||||||
|
if ! which inotifywait &>/dev/null ; then echo "$0 requires inotifywait"; return 1; fi
|
||||||
|
[[ -z "$1" ]] && "Usage: $0 <file> <action>" && return 1
|
||||||
|
local file
|
||||||
|
file="$1"
|
||||||
|
shift
|
||||||
|
|
||||||
|
[[ -z "$@" ]] && "Usage: $0 <file> <action>" && return 1
|
||||||
|
|
||||||
|
local action
|
||||||
|
action="$@"
|
||||||
|
while inotifywait -e close_write "$file"; do zsh -c "$action"; done
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user