Skip to content

Commit 49aedce

Browse files
author
Bruno Sutic
committed
First commit
0 parents  commit 49aedce

File tree

6 files changed

+102
-0
lines changed

6 files changed

+102
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
# v0.0.1 2014-06-02
4+
- first working version

LICENSE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (C) 2014 Bruno Sutic
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the "Software"),
5+
to deal in the Software without restriction, including without limitation
6+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
and/or sell copies of the Software, and to permit persons to whom the
8+
Software is furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included
11+
in all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
19+
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Tmux online status
2+
3+
### License
4+
5+
[MIT](LICENSE.md)

online_status.tmux

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
online_status_icon="#($CURRENT_DIR/scripts/online_status_icon.sh)"
6+
online_status_interpolation_string="\#{online_status}"
7+
8+
source $CURRENT_DIR/scripts/shared.sh
9+
10+
do_interpolation() {
11+
local string=$1
12+
local interpolated=${string/$online_status_interpolation_string/$online_status_icon}
13+
echo "$interpolated"
14+
}
15+
16+
update_tmux_option() {
17+
local option=$1
18+
local option_value=$(get_tmux_option "$option")
19+
local new_option_value=$(do_interpolation "$option_value")
20+
set_tmux_option "$option" "$new_option_value"
21+
}
22+
23+
main() {
24+
update_tmux_option "status-right"
25+
update_tmux_option "status-left"
26+
}
27+
main

scripts/online_status_icon.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
online_option_string="@online_icon"
6+
offline_option_string="@offline_icon"
7+
8+
online_icon_default=""
9+
offline_icon_default="⛔️ "
10+
11+
source $CURRENT_DIR/shared.sh
12+
13+
online_status() {
14+
ping -c 3 www.google.com >/dev/null 2>&1
15+
}
16+
17+
print_icon() {
18+
local status=$(online_status)
19+
# spacer fixes weird emoji spacing
20+
local spacer=" "
21+
if $status; then
22+
printf "$(get_tmux_option "$online_option_string" "$online_icon_default")$spacer"
23+
else
24+
printf "$(get_tmux_option "$offline_option_string" "$offline_icon_default")$spacer"
25+
fi
26+
}
27+
28+
main() {
29+
print_icon "$status"
30+
}
31+
main

scripts/shared.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
get_tmux_option() {
2+
local option=$1
3+
local default_value=$2
4+
local option_value=$(tmux show-option -gqv "$option")
5+
if [ -z "$option_value" ]; then
6+
echo $default_value
7+
else
8+
echo $option_value
9+
fi
10+
}
11+
12+
set_tmux_option() {
13+
local option=$1
14+
local value=$2
15+
tmux set-option -gq "$option" "$value"
16+
}

0 commit comments

Comments
 (0)