Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. A regular plugin only needs to have execution priviledges.
  2. For instance, lets look at this 'hello world' plugin:
  3.  
  4. ```bash
  5. #!/bin/bash
  6. echo "hello world!"
  7. ```
  8.  
  9. If 'hello world' takes a lot of time, we might want to cache the result.
  10. Results are cached for `status-interval` seoconds. lets look at the following plugin:
  11.  
  12. ```bash
  13. #!/bin/bash
  14. PLUGIN_DIR=$(tmux show-option -gqv "@status_variables_dir")
  15. source "$PLUGIN_DIR/utils/sdk.sh"
  16.  
  17. on_cache_miss() {
  18. echo "hello world!"
  19. sleep 1
  20. }
  21.  
  22. echo "$(get_cached_value on_cache_miss)"
  23. ```
  24.  
  25. `on_cache_miss` will run only when `status-interval` seconds have passed.
  26. This is important because tmux might refreshe the status line when redrawing the pane.
  27. Every time you press <Enter> or create a new pane, the status line is refreshed which causes many script calls.
  28.  
  29. Now all that's left is to run it:
  30. 1. Dump the content of the script to the `scripts_directory`, and name it `hello_world.tmux`
  31. 2. Add `set -g status-left "#{hello_world}"` to your `tmux.conf` and your good to go!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement