+ 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
This commit is contained in:
5
.tmux/plugins/tmux-ip-address/.editorconfig
Normal file
5
.tmux/plugins/tmux-ip-address/.editorconfig
Normal file
@ -0,0 +1,5 @@
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
21
.tmux/plugins/tmux-ip-address/LICENSE
Normal file
21
.tmux/plugins/tmux-ip-address/LICENSE
Normal file
@ -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.
|
63
.tmux/plugins/tmux-ip-address/README.md
Normal file
63
.tmux/plugins/tmux-ip-address/README.md
Normal file
@ -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 <kbd>prefix</kbd> + <kbd>A</kbd>.
|
||||
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)
|
35
.tmux/plugins/tmux-ip-address/ip_address.tmux
Executable file
35
.tmux/plugins/tmux-ip-address/ip_address.tmux
Executable file
@ -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
|
18
.tmux/plugins/tmux-ip-address/scripts/helpers.sh
Executable file
18
.tmux/plugins/tmux-ip-address/scripts/helpers.sh
Executable file
@ -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
|
||||
}
|
16
.tmux/plugins/tmux-ip-address/scripts/ip_address.sh
Executable file
16
.tmux/plugins/tmux-ip-address/scripts/ip_address.sh
Executable file
@ -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
|
33
.tmux/plugins/tmux-ip-address/scripts/update_ip_address.sh
Executable file
33
.tmux/plugins/tmux-ip-address/scripts/update_ip_address.sh
Executable file
@ -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
|
Reference in New Issue
Block a user