You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
913 B

  1. #!/usr/bin/env bash
  2. CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. source "$CURRENT_DIR/scripts/helpers.sh"
  4. ip_address="$($CURRENT_DIR/scripts/ip_address.sh)"
  5. ip_address_interpolation_string="\#{ip_address}"
  6. ip_address_refresh_cmd_key="$(get_tmux_option "@ip_address_refresh_key" "A")"
  7. do_interpolation() {
  8. local string="$1"
  9. local ip_addr=$ip_address
  10. if [ -z "$ip_addr" ]
  11. then
  12. ip_addr="Offline"
  13. fi
  14. local interpolated="$(echo $1 | sed "s/$ip_address_interpolation_string/$ip_addr/g")"
  15. echo "$interpolated"
  16. }
  17. update_tmux_option() {
  18. local option="$1"
  19. local option_value="$(get_tmux_option "$option")"
  20. local new_option_value="$(do_interpolation "$option_value")"
  21. set_tmux_option "$option" "$new_option_value"
  22. }
  23. main() {
  24. tmux bind-key "$ip_address_refresh_cmd_key" run-shell -b "$CURRENT_DIR/scripts/update_ip_address.sh"
  25. update_tmux_option "status-right"
  26. }
  27. main