Merge branch 'master' into tmigone/add-network-vpn

This commit is contained in:
Ethan Edwards 2023-04-08 15:14:05 -04:00 committed by GitHub
commit 19f69a1c58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 391 additions and 110 deletions

View file

@ -48,7 +48,8 @@ To enable plugins set up the `@dracula-plugins` option in you `.tmux.conf` file,
The order that you define the plugins will be the order on the status bar left to right. The order that you define the plugins will be the order on the status bar left to right.
```bash ```bash
# available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, network-ping, network-vpn, weather, time # available plugins: battery, cpu-usage, git, gpu-usage, ram-usage, network, network-bandwidth, network-ping, attached-clients, network-vpn, weather, time
set -g @dracula-plugins "cpu-usage gpu-usage ram-usage" set -g @dracula-plugins "cpu-usage gpu-usage ram-usage"
``` ```
@ -111,6 +112,12 @@ Enable high contrast pane border
set -g @dracula-border-contrast true set -g @dracula-border-contrast true
``` ```
Hide empty plugins
```bash
set -g @dracula-show-empty-plugins false
```
#### cpu-usage options #### cpu-usage options
Customize label Customize label
@ -138,6 +145,8 @@ set -g @dracula-battery-label "Battery"
#### gpu-usage options #### gpu-usage options
Note, currently only the Linux NVIDIA Proprietary drivers are supported. Nouveau and AMD Graphics Cards support are still under development.
Customize label Customize label
```bash ```bash
@ -152,6 +161,18 @@ Customize label
set -g @dracula-ram-usage-label "RAM" set -g @dracula-ram-usage-label "RAM"
``` ```
#### network-bandwidth
You can configure which network interface you want to view the bandwidth,
Displaying of the interface name, The interval between each bandwidth update.
The most common interfaces name are `eth0` for a wired connection and `wlan0` for a wireless connection.
```bash
set -g @dracula-network-bandwidth eth0
set -g @dracula-network-bandwidth-interval 0
set -g @dracula-network-bandwidth-show-interface true
```
#### network-ping options #### network-ping options
You can configure which server (hostname, IP) you want to ping and at which rate (in seconds). Default is google.com at every 5 seconds. You can configure which server (hostname, IP) you want to ping and at which rate (in seconds). Default is google.com at every 5 seconds.
@ -206,6 +227,17 @@ Set symbol or message to use when the current pane has no git repo
set -g @dracula-git-no-repo-message "" set -g @dracula-git-no-repo-message ""
``` ```
Hide untracked files from being displayed as local changes
```bash
# default is false
set -g @dracula-git-no-untracked-files true
```
Show remote tracking branch together with diverge/sync state
```bash
# default is false
set -g @dracula-git-show-remote-status true
```
#### weather options #### weather options
@ -226,3 +258,18 @@ Hide your location
```bash ```bash
set -g @dracula-show-location false set -g @dracula-show-location false
``` ```
#### attached-clients options
Set the minimum number of clients to show (otherwise, show nothing)
```bash
set -g @dracula-clients-minimum 1
```
Set the label when there is one client, or more than one client
```bash
set -g @dracula-clients-singular client
set -g @dracula-clients-plural clients
```

View file

@ -29,6 +29,9 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul
- When prefix is enabled smiley face turns from green to yellow - When prefix is enabled smiley face turns from green to yellow
- When charging, 'AC' is displayed - When charging, 'AC' is displayed
- If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature - If forecast information is available, a ☀, ☁, ☂, or ❄ unicode character corresponding with the forecast is displayed alongside the temperature
- Spotify playback (needs the tool spotify-tui installed)
- Current kubernetes context
- Current working directory of tmux pane
## Compatibility ## Compatibility

35
scripts/attached_clients.sh Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
# configuration
# @dracula-clients-minimum 1
# @dracula-clients-singular client
# @dracula-clients-plural clients
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh
count_clients() {
pane=$(tmux list-panes -F "#{session_name}" | head -n 1)
tmux list-clients -t $pane | wc -l | tr -d ' '
}
main() {
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
clients_count=$(count_clients)
clients_minimum=$(get_tmux_option "@dracula-clients-minimum" 1)
if (( $clients_count >= $clients_minimum )); then
if (( $clients_count > 1 )); then
clients_label=$(get_tmux_option "@dracula-clients-plural" "clients")
else
clients_label=$(get_tmux_option "@dracula-clients-singular" "client")
fi
echo "$clients_count $clients_label"
fi
sleep $RATE
}
# run main driver
main

View file

@ -44,10 +44,10 @@ main() {
# storing the refresh rate in the variable RATE, default is 5 # storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5) RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
cpu_load=$(get_tmux_option "@dracula-cpu-display-load" false) cpu_load=$(get_tmux_option "@dracula-cpu-display-load" false)
cpu_label=$(get_tmux_option "@dracula-cpu-usage-label" "CPU")
if [ "$cpu_load" = true ]; then if [ "$cpu_load" = true ]; then
echo "$(get_load)" echo "$cpu_label $(get_load)"
else else
cpu_label=$(get_tmux_option "@dracula-cpu-usage-label" "CPU")
cpu_percent=$(get_percent) cpu_percent=$(get_percent)
echo "$cpu_label $cpu_percent" echo "$cpu_label $cpu_percent"
fi fi

30
scripts/cwd.sh Executable file
View file

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# return current working directory of tmux pane
getPaneDir()
{
nextone="false"
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}");
do
if [ "$nextone" == "true" ]; then
echo $i
return
fi
if [ "$i" == "1" ]; then
nextone="true"
fi
done
}
main()
{
path=$(getPaneDir)
# change '/home/user' to '~'
cwd=$(echo $path | sed "s;$HOME;~;g")
echo $cwd
}
#run main driver program
main

View file

@ -24,7 +24,10 @@ main()
show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false) show_border_contrast=$(get_tmux_option "@dracula-border-contrast" false)
show_day_month=$(get_tmux_option "@dracula-day-month" false) show_day_month=$(get_tmux_option "@dracula-day-month" false)
show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5) show_refresh=$(get_tmux_option "@dracula-refresh-rate" 5)
time_format=$(get_tmux_option "@dracula-time-format" "%Y-%m-%d(%a) %H:%M")
show_kubernetes_context_label=$(get_tmux_option "@dracula-kubernetes-context-label" "")
IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather") IFS=' ' read -r -a plugins <<< $(get_tmux_option "@dracula-plugins" "battery network weather")
show_empty_plugins=$(get_tmux_option "@dracula-show-empty-plugins" true)
# Dracula Color Pallette # Dracula Color Pallette
white='#f8f8f2' white='#f8f8f2'
@ -127,53 +130,62 @@ main()
for plugin in "${plugins[@]}"; do for plugin in "${plugins[@]}"; do
if [ $plugin = "git" ]; then if [ $plugin = "cwd" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cwd-colors" "dark_gray white")
script="#($current_dir/git.sh)" tmux set-option -g status-right-length 250
fi script="#($current_dir/cwd.sh)"
if [ $plugin = "battery" ]; then elif [ $plugin = "git" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray")
tmux set-option -g status-right-length 250
script="#($current_dir/git.sh)"
elif [ $plugin = "battery" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-battery-colors" "pink dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-battery-colors" "pink dark_gray")
script="#($current_dir/battery.sh)" script="#($current_dir/battery.sh)"
fi
if [ $plugin = "gpu-usage" ]; then elif [ $plugin = "gpu-usage" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-usage-colors" "pink dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-gpu-usage-colors" "pink dark_gray")
script="#($current_dir/gpu_usage.sh)" script="#($current_dir/gpu_usage.sh)"
fi
if [ $plugin = "cpu-usage" ]; then elif [ $plugin = "cpu-usage" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cpu-usage-colors" "orange dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cpu-usage-colors" "orange dark_gray")
script="#($current_dir/cpu_info.sh)" script="#($current_dir/cpu_info.sh)"
fi
if [ $plugin = "ram-usage" ]; then elif [ $plugin = "ram-usage" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-ram-usage-colors" "cyan dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-ram-usage-colors" "cyan dark_gray")
script="#($current_dir/ram_info.sh)" script="#($current_dir/ram_info.sh)"
fi
if [ $plugin = "network" ]; then elif [ $plugin = "network" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-colors" "cyan dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-colors" "cyan dark_gray")
script="#($current_dir/network.sh)" script="#($current_dir/network.sh)"
fi
if [ $plugin = "network-bandwidth" ]; then elif [ $plugin = "network-bandwidth" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-bandwidth-colors" "cyan dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-network-bandwidth-colors" "cyan dark_gray")
tmux set-option -g status-right-length 250 tmux set-option -g status-right-length 250
script="#($current_dir/network_bandwidth.sh)" script="#($current_dir/network_bandwidth.sh)"
fi
if [ $plugin = "network-ping" ]; then elif [ $plugin = "network-ping" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-ping-colors" "cyan dark_gray") IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-ping-colors" "cyan dark_gray")
script="#($current_dir/network_ping.sh)" script="#($current_dir/network_ping.sh)"
fi
if [ $plugin = "network-vpn" ]; then elif [ $plugin = "network-vpn" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-vpn-colors" "cyan dark_gray") IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-network-vpn-colors" "cyan dark_gray")
script="#($current_dir/network_vpn.sh)" script="#($current_dir/network_vpn.sh)"
fi
if [ $plugin = "weather" ]; then elif [ $plugin = "attached-clients" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-attached-clients-colors" "cyan dark_gray")
script="#($current_dir/attached_clients.sh)"
elif [ $plugin = "spotify-tui" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-spotify-tui-colors" "green dark_gray")
script="#($current_dir/spotify-tui.sh)"
elif [ $plugin = "kubernetes-context" ]; then
IFS=' ' read -r -a colors <<<$(get_tmux_option "@dracula-kubernetes-context-colors" "cyan dark_gray")
script="#($current_dir/kubernetes_context.sh $show_kubernetes_context_label)"
elif [ $plugin = "weather" ]; then
# wait unit $datafile exists just to avoid errors # wait unit $datafile exists just to avoid errors
# this should almost never need to wait unless something unexpected occurs # this should almost never need to wait unless something unexpected occurs
while [ ! -f $datafile ]; do while [ ! -f $datafile ]; do
@ -182,26 +194,40 @@ main()
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-weather-colors" "orange dark_gray")
script="#(cat $datafile)" script="#(cat $datafile)"
fi
if [ $plugin = "time" ]; then elif [ $plugin = "time" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-time-colors" "dark_purple white")
if $show_day_month && $show_military ; then # military time and dd/mm if [ -n "$time_format" ]; then
script="%a %d/%m %R ${timezone} " script=${time_format}
elif $show_military; then # only military time
script="%a %m/%d %R ${timezone} "
elif $show_day_month; then # only dd/mm
script="%a %d/%m %I:%M %p ${timezone} "
else else
script="%a %m/%d %I:%M %p ${timezone} " if $show_day_month && $show_military ; then # military time and dd/mm
script="%a %d/%m %R ${timezone} "
elif $show_military; then # only military time
script="%a %m/%d %R ${timezone} "
elif $show_day_month; then # only dd/mm
script="%a %d/%m %I:%M %p ${timezone} "
else
script="%a %m/%d %I:%M %p ${timezone} "
fi
fi fi
else
continue
fi fi
if $show_powerline; then if $show_powerline; then
tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script " if $show_empty_plugins; then
tmux set-option -ga status-right "#[fg=${!colors[0]},bg=${powerbg},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script "
else
tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[0]},nobold,nounderscore,noitalics]${right_sep}#[fg=${!colors[1]},bg=${!colors[0]}] $script }"
fi
powerbg=${!colors[0]} powerbg=${!colors[0]}
else else
tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script " if $show_empty_plugins; then
tmux set-option -ga status-right "#[fg=${!colors[1]},bg=${!colors[0]}] $script "
else
tmux set-option -ga status-right "#{?#{==:$script,},,#[fg=${!colors[1]},bg=${!colors[0]}] $script }"
fi
fi fi
done done

View file

@ -7,6 +7,8 @@ IFS=' ' read -r -a hide_status <<< $(get_tmux_option "@dracula-git-disable-statu
IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-git-show-current-symbol" "✓") IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-git-show-current-symbol" "✓")
IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-git-show-diff-symbol" "!") IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-git-show-diff-symbol" "!")
IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-git-no-repo-message" "") IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-git-no-repo-message" "")
IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-git-no-untracked-files" "false")
IFS=' ' read -r -a show_remote_status <<< $(get_tmux_option "@dracula-git-show-remote-status" "false")
# Get added, modified, updated and deleted files from git status # Get added, modified, updated and deleted files from git status
getChanges() getChanges()
@ -16,7 +18,7 @@ getChanges()
declare -i updated=0; declare -i updated=0;
declare -i deleted=0; declare -i deleted=0;
for i in $(git -C $path status -s) for i in $(git -C $path --no-optional-locks status -s)
do do
case $i in case $i in
@ -77,8 +79,9 @@ checkEmptySymbol()
# check to see if the current repo is not up to date with HEAD # check to see if the current repo is not up to date with HEAD
checkForChanges() checkForChanges()
{ {
[ $no_untracked_files == "false" ] && no_untracked="" || no_untracked="-uno"
if [ "$(checkForGitDir)" == "true" ]; then if [ "$(checkForGitDir)" == "true" ]; then
if [ "$(git -C $path status -s)" != "" ]; then if [ "$(git -C $path --no-optional-locks status -s $no_untracked)" != "" ]; then
echo "true" echo "true"
else else
echo "false" echo "false"
@ -108,37 +111,59 @@ getBranch()
fi fi
} }
getRemoteInfo()
{
base=$(git -C $path for-each-ref --format='%(upstream:short) %(upstream:track)' "$(git -C $path symbolic-ref -q HEAD)")
remote=$(echo "$base" | cut -d" " -f1)
out=""
if [ -n "$remote" ]; then
out="...$remote"
ahead=$(echo "$base" | grep -E -o 'ahead[ [:digit:]]+' | cut -d" " -f2)
behind=$(echo "$base" | grep -E -o 'behind[ [:digit:]]+' | cut -d" " -f2)
[ -n "$ahead" ] && out+=" +$ahead"
[ -n "$behind" ] && out+=" -$behind"
fi
echo "$out"
}
# return the final message for the status bar # return the final message for the status bar
getMessage() getMessage()
{ {
if [ $(checkForGitDir) == "true" ]; then if [ $(checkForGitDir) == "true" ]; then
branch="$(getBranch)" branch="$(getBranch)"
output=""
if [ $(checkForChanges) == "true" ]; then if [ $(checkForChanges) == "true" ]; then
changes="$(getChanges)" changes="$(getChanges)"
if [ "${hide_status}" == "false" ]; then if [ "${hide_status}" == "false" ]; then
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
echo "${changes} $branch" output=$(echo "${changes} $branch")
else else
echo "$diff_symbol ${changes} $branch" output=$(echo "$diff_symbol ${changes} $branch")
fi fi
else else
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
echo "$branch" output=$(echo "$branch")
else else
echo "$diff_symbol $branch" output=$(echo "$diff_symbol $branch")
fi fi
fi fi
else else
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
echo "$branch" output=$(echo "$branch")
else else
echo "$current_symbol $branch" output=$(echo "$current_symbol $branch")
fi fi
fi fi
[ "$show_remote_status" == "true" ] && output+=$(getRemoteInfo)
echo "$output"
else else
echo $no_repo_message echo $no_repo_message
fi fi

View file

@ -27,7 +27,7 @@ get_gpu()
{ {
gpu=$(get_platform) gpu=$(get_platform)
if [[ "$gpu" == NVIDIA ]]; then if [[ "$gpu" == NVIDIA ]]; then
usage=$(nvidia-smi | grep '%' | awk '{ sum += $13 } END { printf("%d%%\n", sum / NR) }') usage=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits | awk '{ sum += $0 } END { printf("%d%%\n", sum / NR) }')
else else
usage='unknown' usage='unknown'
fi fi

51
scripts/kubernetes_context.sh Executable file
View file

@ -0,0 +1,51 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
label=$1
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
current_context=$(kubectl config view --minify --output 'jsonpath={.current-context}'; echo)
current_user=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.user}'; echo)
current_cluster=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.cluster}'; echo)
current_namespace=$(kubectl config view --minify --output 'jsonpath={.contexts[?(@.name=="'$current_context'")].context.namespace}'; echo)
main()
{
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
OUTPUT_STRING=""
if [ ! -z "$current_user" ]
then
OUTPUT_STRING="${current_user}@"
fi
if [ ! -z "$current_cluster" ]
then
OUTPUT_STRING="${OUTPUT_STRING}${current_cluster}"
fi
if [ ! -z "$current_namespace" ]
then
OUTPUT_STRING="${OUTPUT_STRING}:${current_namespace}"
fi
if [ "$OUTPUT_STRING" = "" ]
then
OUTPUT_STRING="kubeconfig not valid"
fi
if [ "$label" = "" ]
then
echo "${OUTPUT_STRING}"
else
echo "${label} ${OUTPUT_STRING}"
fi
sleep $RATE
}
# run the main driver
main

View file

@ -1,51 +1,103 @@
#!/usr/bin/env bash #!/usr/bin/env bash
INTERVAL="1" # update interval in seconds # INTERVAL is equal to 1s because we want to express the bandwidth in sec
readonly INTERVAL=1
network_name=$(tmux show-option -gqv "@dracula-network-bandwidth") # UPLOAD and DOWNLOAD index
readonly UPLOAD=0
readonly DOWNLOAD=1
# SIZE index are the multiple of the unit byte and value the internationally recommended unit symbol in sec
readonly SIZE=(
[1]='B/s'
[1024]='kB/s'
[1048576]='MB/s'
[1073741824]='GB/s'
)
# interface_get try to automaticaly get the used interface if network_name is empty
interface_get() {
name="$(tmux show-option -gqv "@dracula-network-bandwidth")"
if [[ -z $name ]]; then
case "$(uname -s)" in
Linux)
if type ip >/dev/null; then
name="$(ip -o route get 192.168.0.0 | awk '{print $5}')"
fi
;;
esac
fi
echo "$name"
}
# interface_bytes give interface name and signal tx/rx return Bytes
interface_bytes() {
cat "/sys/class/net/$1/statistics/$2_bytes"
}
# get_bandwidth return the number of bytes exchanged for tx and rx
get_bandwidth() {
upload="$(interface_bytes "$1" "tx")"
download="$(interface_bytes "$1" "rx")"
#wait the interval for Wait for interval to calculate the difference
sleep "$INTERVAL"
upload="$(bc <<<"$(interface_bytes "$1" "tx") - $upload")"
download="$(bc <<<"$(interface_bytes "$1" "rx") - $download")"
#set to 0 by default useful for non-existent interface
echo "${upload:-0} ${download:-0}"
}
# bandwidth_to_unit convert bytes into its highest unit and add unit symbol in sec
bandwidth_to_unit() {
local size=1
for i in "${!SIZE[@]}"; do
if (($1 < i)); then
break
fi
size="$i"
done
local result="0.00"
if (($1 != 0)); then
result="$(bc <<<"scale=2; $1 / $size")"
fi
echo "$result ${SIZE[$size]}"
}
main() { main() {
while true counter=0
do bandwidth=()
output_download=""
output_upload=""
output_download_unit=""
output_upload_unit=""
initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes) network_name=""
initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes) show_interface="$(tmux show-option -gqv "@dracula-network-bandwidth-show-interface")"
interval_update="$(tmux show-option -gqv "@dracula-network-bandwidth-interval")"
sleep $INTERVAL if [[ -z $interval_update ]]; then
interval_update=0
fi
final_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes) while true; do
final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes) if ((counter == 0)); then
counter=60
total_download_bps=$(expr $final_download - $initial_download) network_name="$(interface_get)"
total_upload_bps=$(expr $final_upload - $initial_upload)
if [ $total_download_bps -gt 1073741824 ]; then
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
output_download_unit="gB/s"
elif [ $total_download_bps -gt 1048576 ]; then
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
output_download_unit="mB/s"
else
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/$2}')
output_download_unit="kB/s"
fi fi
if [ $total_upload_bps -gt 1073741824 ]; then IFS=" " read -ra bandwidth <<<"$(get_bandwidth "$network_name")"
output_upload=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
output_upload_unit="gB/s"
elif [ $total_upload_bps -gt 1048576 ]; then
output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
output_upload_unit="mB/s"
else
output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/$2}')
output_upload_unit="kB/s"
fi
echo "$output_download $output_download_unit • ↑ $output_upload $output_upload_unit" if [[ $show_interface == "true" ]]; then echo -n "[$network_name] "; fi
echo "$(bandwidth_to_unit "${bandwidth[$DOWNLOAD]}") • ↑ $(bandwidth_to_unit "${bandwidth[$UPLOAD]}")"
((counter = counter - 1))
sleep "$interval_update"
done done
} }
#run main driver
main main

0
scripts/network_ping.sh Normal file → Executable file
View file

View file

@ -5,35 +5,26 @@ export LC_ALL=en_US.UTF-8
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh source $current_dir/utils.sh
get_percent() get_ratio()
{ {
case $(uname -s) in case $(uname -s) in
Linux) Linux)
total_mem_gb=$(free -g | awk '/^Mem/ {print $2}') usage="$(free -h | awk 'NR==2 {print $3}')"
used_mem=$(free -g | awk '/^Mem/ {print $3}') total="$(free -h | awk 'NR==2 {print $2}')"
total_mem=$(free -h | awk '/^Mem/ {print $2}') formated="${usage}/${total}"
if (( $total_mem_gb == 0)); then
memory_usage=$(free -m | awk '/^Mem/ {print $3}') echo "${formated//i/B}"
total_mem_mb=$(free -m | awk '/^Mem/ {print $2}')
echo $memory_usage\M\B/$total_mem_mb\M\B
elif (( $used_mem == 0 )); then
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
echo $memory_usage\M\B/$total_mem_gb\G\B
else
memory_usage=$(free -g | awk '/^Mem/ {print $3}')
echo $memory_usage\G\B/$total_mem_gb\G\B
fi
;; ;;
Darwin) Darwin)
# Get used memory blocks with vm_stat, multiply by page size to get size in bytes, then convert to MiB # Get used memory blocks with vm_stat, multiply by page size to get size in bytes, then convert to MiB
used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk -v pagesize=$(pagesize) '{printf "%d\n", ($1+$2) * pagesize / 1048576}') used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk -v pagesize=$(pagesize) '{printf "%d\n", ($1+$2) * pagesize / 1048576}')
total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}') total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}')
if (( $used_mem < 1024 )); then if ((used_mem < 1024 )); then
echo $used_mem\M\B/$total_mem echo "${used_mem}MB/$total_mem"
else else
memory=$(($used_mem/1024)) memory=$((used_mem/1024))
echo $memory\G\B/$total_mem echo "${memory}GB/$total_mem"
fi fi
;; ;;
@ -48,11 +39,11 @@ get_percent()
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024)) total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
used_mem=$((total_mem - free_mem)) used_mem=$((total_mem - free_mem))
echo $used_mem echo $used_mem
if (( $used_mem < 1024 )); then if ((used_mem < 1024 )); then
echo $used_mem\M\B/$total_mem echo "${used_mem}MB/$total_mem"
else else
memory=$(($used_mem/1024)) memory=$((used_mem/1024))
echo $memory\G\B/$total_mem echo "${memory}GB/$total_mem"
fi fi
;; ;;
@ -64,12 +55,9 @@ get_percent()
main() main()
{ {
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
ram_label=$(get_tmux_option "@dracula-ram-usage-label" "RAM") ram_label=$(get_tmux_option "@dracula-ram-usage-label" "RAM")
ram_percent=$(get_percent) ram_ratio=$(get_ratio)
echo "$ram_label $ram_percent" echo "$ram_label $ram_ratio"
sleep $RATE
} }
#run main driver #run main driver

24
scripts/spotify-tui.sh Executable file
View file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
# setting the locale, some users have issues with different locales, this forces the correct one
export LC_ALL=en_US.UTF-8
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
main()
{
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
if ! command -v spt &> /dev/null
then
exit 1
fi
spotify_playback=$(spt playback)
echo ${spotify_playback}
}
# run the main driver
main