about summary refs log tree commit diff
path: root/configs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2019-03-27T18·27+0000
committerWilliam Carroll <wpcarro@gmail.com>2019-03-27T18·27+0000
commit79387acb96d3a5e5fa72c92ca50eee1b6ad5f88e (patch)
tree6722ece379984e1b543034d0baeeca5c1397e181 /configs
parent370f0346dea102b36b65f09678361b1bbd41256d (diff)
Create generic loop fn
Might be useful for things like:

```
loop 'PAGER="" hgst' 1 y
```

```
loop 'du -hs .'
```

```
loop ll
```
Diffstat (limited to 'configs')
-rw-r--r--configs/shared/zsh/functions.zsh22
1 files changed, 22 insertions, 0 deletions
diff --git a/configs/shared/zsh/functions.zsh b/configs/shared/zsh/functions.zsh
index ea12bf313fe8..ec64c2293a96 100644
--- a/configs/shared/zsh/functions.zsh
+++ b/configs/shared/zsh/functions.zsh
@@ -406,6 +406,28 @@ is_online() {
   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() {
   # Outputs and refreshes the size of a directory's content.
   # Useful for watching a directory as large amounts of data are