From 05823efcb7775710c7c11ac050561b3dd2209fc4 Mon Sep 17 00:00:00 2001 From: dimti Date: Wed, 16 Oct 2024 12:39:03 +0300 Subject: [PATCH] + tmux-ip-address plugin with custom hand made fixes about remove beep x07 symbol (represented as \a from ip address values) from status-right bar --- .tmux/plugins/tmux-ip-address/.editorconfig | 5 ++ .tmux/plugins/tmux-ip-address/LICENSE | 21 ++++++++ .tmux/plugins/tmux-ip-address/README.md | 63 ++++++++++++++++++++++ .tmux/plugins/tmux-ip-address/ip_address.tmux | 35 ++++++++++++ .tmux/plugins/tmux-ip-address/scripts/helpers.sh | 18 +++++++ .../plugins/tmux-ip-address/scripts/ip_address.sh | 16 ++++++ .../tmux-ip-address/scripts/update_ip_address.sh | 33 ++++++++++++ 7 files changed, 191 insertions(+) create mode 100644 .tmux/plugins/tmux-ip-address/.editorconfig create mode 100644 .tmux/plugins/tmux-ip-address/LICENSE create mode 100644 .tmux/plugins/tmux-ip-address/README.md create mode 100755 .tmux/plugins/tmux-ip-address/ip_address.tmux create mode 100755 .tmux/plugins/tmux-ip-address/scripts/helpers.sh create mode 100755 .tmux/plugins/tmux-ip-address/scripts/ip_address.sh create mode 100755 .tmux/plugins/tmux-ip-address/scripts/update_ip_address.sh diff --git a/.tmux/plugins/tmux-ip-address/.editorconfig b/.tmux/plugins/tmux-ip-address/.editorconfig new file mode 100644 index 0000000..901d90d --- /dev/null +++ b/.tmux/plugins/tmux-ip-address/.editorconfig @@ -0,0 +1,5 @@ +[*] +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 diff --git a/.tmux/plugins/tmux-ip-address/LICENSE b/.tmux/plugins/tmux-ip-address/LICENSE new file mode 100644 index 0000000..0eb3f3b --- /dev/null +++ b/.tmux/plugins/tmux-ip-address/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Aaron Powell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.tmux/plugins/tmux-ip-address/README.md b/.tmux/plugins/tmux-ip-address/README.md new file mode 100644 index 0000000..e34f5ec --- /dev/null +++ b/.tmux/plugins/tmux-ip-address/README.md @@ -0,0 +1,63 @@ +# Tmux IP Address + +The plugin shows public IP Address on the status bar of tmux using `#{ip_address}` syntax on the tmux `status-right` option. + + +## Usage + +Add `#{ip_address}` to your existing `status-right` tmux option: + +```bash +set -g status-right '#{ip_address} | #H' +``` + +You'll now see some information like so: + +``` +172.116.1.10 +``` + +IP Address can be refreshed by prefix + A. +The key combination of refreshing IP Address can be customized by: +```bash +set -g @ip_address_refresh_key 'P' +``` + +## Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended) + +Add plugin to the list of TPM plugins in `.tmux.conf`: + +```bash +set -g @plugin 'anghootys/tmux-ip-address' +``` + +Hit `prefix + I` to fetch the plugin and source it. + +`#{ip_address}` interpolation should now work. + +### Manual Installation + +Clone the repo: + +```bash +$ git clone https://github.com/anghootys/tmux-ip-address ~/clone/path +``` + +Add this line to the bottom of `.tmux.conf`: + +```bash +run-shell ~/clone/path/ip_address.tmux +``` + +Reload TMUX environment: + +```bash +# type this in terminal +$ tmux source-file ~/.tmux.conf +``` + +`#{ip_address}` interpolation should now work. + +## License + +[MIT](LICENSE) diff --git a/.tmux/plugins/tmux-ip-address/ip_address.tmux b/.tmux/plugins/tmux-ip-address/ip_address.tmux new file mode 100755 index 0000000..705b395 --- /dev/null +++ b/.tmux/plugins/tmux-ip-address/ip_address.tmux @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/scripts/helpers.sh" + +ip_address="$($CURRENT_DIR/scripts/ip_address.sh)" +ip_address_interpolation_string="\#{ip_address}" +ip_address_refresh_cmd_key="$(get_tmux_option "@ip_address_refresh_key" "A")" + +do_interpolation() { + local string="$1" + local ip_addr=$ip_address + if [ -z "$ip_addr" ] + then + ip_addr="Offline" + fi + + local interpolated="$(echo $1 | sed "s/$ip_address_interpolation_string/$ip_addr/g")" + + echo "$interpolated" +} + +update_tmux_option() { + local option="$1" + local option_value="$(get_tmux_option "$option")" + local new_option_value="$(do_interpolation "$option_value")" + set_tmux_option "$option" "$new_option_value" +} + +main() { + tmux bind-key "$ip_address_refresh_cmd_key" run-shell -b "$CURRENT_DIR/scripts/update_ip_address.sh" + update_tmux_option "status-right" +} +main diff --git a/.tmux/plugins/tmux-ip-address/scripts/helpers.sh b/.tmux/plugins/tmux-ip-address/scripts/helpers.sh new file mode 100755 index 0000000..85f9ee7 --- /dev/null +++ b/.tmux/plugins/tmux-ip-address/scripts/helpers.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set_tmux_option() { + local option="$1" + local value="$2" + tmux set-option -gq "$option" "$value" +} + +get_tmux_option() { + local option="$1" + local default_value="$2" + local option_value="$(tmux show-option -gqv "$option")" + if [ -z "$option_value" ]; then + echo "$default_value" + else + echo "$option_value" + fi +} diff --git a/.tmux/plugins/tmux-ip-address/scripts/ip_address.sh b/.tmux/plugins/tmux-ip-address/scripts/ip_address.sh new file mode 100755 index 0000000..11d1c04 --- /dev/null +++ b/.tmux/plugins/tmux-ip-address/scripts/ip_address.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +print_ip_address() { + local ip_address=$(curl --max-time 1.5 --silent http://ip.me) + echo ${ip_address} +} + +main() { + print_ip_address +} + +main diff --git a/.tmux/plugins/tmux-ip-address/scripts/update_ip_address.sh b/.tmux/plugins/tmux-ip-address/scripts/update_ip_address.sh new file mode 100755 index 0000000..2840f29 --- /dev/null +++ b/.tmux/plugins/tmux-ip-address/scripts/update_ip_address.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/helpers.sh" + +ip_address="$($CURRENT_DIR/ip_address.sh)" +ip_address_interpolation_string="\#{ip_address}" + +do_interpolation() { + local string="$1" + local ip_addr=$ip_address + if [ -z "$ip_address" ] + then + ip_addr="Offline" + fi + + local interpolated="$(echo $1 | sed "s/$ip_address_interpolation_string/$ip_addr/g")" + + echo "$interpolated" +} + +update_tmux_option() { + local option="$1" + local option_value="$(get_tmux_option "$option")" + local new_option_value="$(do_interpolation "$option_value")" + set_tmux_option "$option" "$new_option_value" +} + +main() { + update_tmux_option "status-right" +} +main