Create generic loop fn
Might be useful for things like: ``` loop 'PAGER="" hgst' 1 y ``` ``` loop 'du -hs .' ``` ``` loop ll ```
This commit is contained in:
parent
370f0346de
commit
79387acb96
1 changed files with 22 additions and 0 deletions
|
@ -406,6 +406,28 @@ is_online() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loop() {
|
||||||
|
# Continuously loop `command` every `sleep_amt` interval. `sleep_amt` defaults
|
||||||
|
# to 1 second. Pass y/n for `should_clear` if you'd like to clear the screen
|
||||||
|
# at the end of each iteration.
|
||||||
|
# Usage: loop <command> <sleep_amt> <should_clear>
|
||||||
|
local command=$1;
|
||||||
|
local sleep_amt=${2:-1};
|
||||||
|
local should_clear=${3:-n}
|
||||||
|
|
||||||
|
# clear the screen before kicking things off
|
||||||
|
if [ $should_clear = y ]; then
|
||||||
|
clear
|
||||||
|
fi
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
eval $command && sleep $sleep_amt
|
||||||
|
if [ $should_clear = y ]; then
|
||||||
|
clear
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
du_it_live() {
|
du_it_live() {
|
||||||
# Outputs and refreshes the size of a directory's content.
|
# Outputs and refreshes the size of a directory's content.
|
||||||
# Useful for watching a directory as large amounts of data are
|
# Useful for watching a directory as large amounts of data are
|
||||||
|
|
Loading…
Reference in a new issue