Compare commits

...

2 Commits

Author SHA1 Message Date
bretello 9ccf8699ec
zsh: functions: fix upload() 2023-07-10 09:12:50 +02:00
bretello d72886b6c1
zsh: functions: add watch_file function
this can be used to watch a file for changes and execute the
given action on changes.
2023-07-10 09:12:30 +02:00
1 changed files with 19 additions and 3 deletions

View File

@ -121,14 +121,14 @@ function upload
echo -e "Done, file at:\t$out"
if [[ $(uname) == "Darwin" ]]; then
clipboard="pbcopy"
elif command -v wl-copy; then
elif command -v wl-copy &>/dev/null; then
clipboard="wl-copy"
elif command -v xclip; then
elif command -v xclip &>/dev/null ; then
clipboard="xclip"
else
clipboard="cat"
fi
echo -n"$out" | $clipboard
echo -en "$out" | $clipboard
}
## If connecting through ssh and reverse forwarding port 2222 (ssh -R 2222:localhost:22 ), this function allows to copy the files back to the machine one is connecting from by typing 'mecp filename' (configure the username for "localhost" in ~/.ssh/config or add an username)
@ -284,3 +284,19 @@ function mangrep() {
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
}