Merge branch 'master' into reject-unknown-plugins

This commit is contained in:
Ethan Edwards 2023-04-08 14:26:35 -04:00 committed by GitHub
commit e5ccca873b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 223 additions and 75 deletions

View file

@ -138,6 +138,8 @@ set -g @dracula-battery-label "Battery"
#### 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
```bash
@ -152,6 +154,18 @@ Customize label
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
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.
@ -212,6 +226,12 @@ Hide untracked files from being displayed as local changes
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
Switch from default fahrenheit to celsius
@ -230,4 +250,31 @@ Hide your location
```bash
set -g @dracula-show-location false
set -g @dracula-plugins "cpu-usage ram-usage network network-bandwidth time"
set -g @dracula-network-bandwidth enp5s0
set -g @dracula-show-powerline true
set -g @dracula-show-flags false
set -g @dracula-refresh-rate 5
set -g @dracula-show-left-icon session
set -g @dracula-border-contrast true
set -g @dracula-military-time true
set -g @dracula-show-location false
set -g @dracula-show-timezone false
set -g @dracula-show-weather false
# set -g @dracula-border-contrast true
# set -g @dracula-cpu-usage true
# set -g @dracula-military-time true
# set -g @dracula-ram-usage true
# set -g @dracula-refresh-rate 5
# set -g @dracula-show-battery true
# set -g @dracula-show-flags true
# set -g @dracula-show-left-icon session
# set -g @dracula-show-network false
# set -g @dracula-show-powerline false
# set -g @dracula-show-powerline true
# set -g @dracula-show-weather false
```

View file

@ -31,6 +31,7 @@ Configuration and options can be found at [draculatheme.com/tmux](https://dracul
- 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

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

@ -128,10 +128,17 @@ main()
for plugin in "${plugins[@]}"; do
if [ $plugin = "git" ]; then
if [ $plugin = "cwd" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cwd-colors" "dark_gray white")
tmux set-option -g status-right-length 250
script="#($current_dir/cwd.sh)"
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")
script="#($current_dir/battery.sh)"

View file

@ -8,6 +8,7 @@ IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-git-show-curre
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_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
getChanges()
@ -110,11 +111,30 @@ getBranch()
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
getMessage()
{
if [ $(checkForGitDir) == "true" ]; then
branch="$(getBranch)"
output=""
if [ $(checkForChanges) == "true" ]; then
@ -122,25 +142,28 @@ getMessage()
if [ "${hide_status}" == "false" ]; then
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
echo "${changes} $branch"
output=$(echo "${changes} $branch")
else
echo "$diff_symbol ${changes} $branch"
output=$(echo "$diff_symbol ${changes} $branch")
fi
else
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
echo "$branch"
output=$(echo "$branch")
else
echo "$diff_symbol $branch"
output=$(echo "$diff_symbol $branch")
fi
fi
else
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
echo "$branch"
output=$(echo "$branch")
else
echo "$current_symbol $branch"
output=$(echo "$current_symbol $branch")
fi
fi
[ "$show_remote_status" == "true" ] && output+=$(getRemoteInfo)
echo "$output"
else
echo $no_repo_message
fi

View file

@ -27,7 +27,7 @@ get_gpu()
{
gpu=$(get_platform)
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
usage='unknown'
fi

View file

@ -1,51 +1,103 @@
#!/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() {
while true
do
output_download=""
output_upload=""
output_download_unit=""
output_upload_unit=""
counter=0
bandwidth=()
initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
network_name=""
show_interface="$(tmux show-option -gqv "@dracula-network-bandwidth-show-interface")"
interval_update="$(tmux show-option -gqv "@dracula-network-bandwidth-interval")"
sleep $INTERVAL
final_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
total_download_bps=$(expr $final_download - $initial_download)
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"
if [[ -z $interval_update ]]; then
interval_update=0
fi
if [ $total_upload_bps -gt 1073741824 ]; then
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"
while true; do
if ((counter == 0)); then
counter=60
network_name="$(interface_get)"
fi
echo "$output_download $output_download_unit • ↑ $output_upload $output_upload_unit"
IFS=" " read -ra bandwidth <<<"$(get_bandwidth "$network_name")"
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
}
#run main driver
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 )"
source $current_dir/utils.sh
get_percent()
get_ratio()
{
case $(uname -s) in
Linux)
total_mem_gb=$(free -g | awk '/^Mem/ {print $2}')
used_mem=$(free -g | awk '/^Mem/ {print $3}')
total_mem=$(free -h | awk '/^Mem/ {print $2}')
if (( $total_mem_gb == 0)); then
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
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
usage="$(free -h | awk 'NR==2 {print $3}')"
total="$(free -h | awk 'NR==2 {print $2}')"
formated="${usage}/${total}"
echo "${formated//i/B}"
;;
Darwin)
# 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}')
total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}')
if (( $used_mem < 1024 )); then
echo $used_mem\M\B/$total_mem
if ((used_mem < 1024 )); then
echo "${used_mem}MB/$total_mem"
else
memory=$(($used_mem/1024))
echo $memory\G\B/$total_mem
memory=$((used_mem/1024))
echo "${memory}GB/$total_mem"
fi
;;
@ -48,11 +39,11 @@ get_percent()
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
used_mem=$((total_mem - free_mem))
echo $used_mem
if (( $used_mem < 1024 )); then
echo $used_mem\M\B/$total_mem
if ((used_mem < 1024 )); then
echo "${used_mem}MB/$total_mem"
else
memory=$(($used_mem/1024))
echo $memory\G\B/$total_mem
memory=$((used_mem/1024))
echo "${memory}GB/$total_mem"
fi
;;
@ -64,12 +55,9 @@ get_percent()
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_percent=$(get_percent)
echo "$ram_label $ram_percent"
sleep $RATE
ram_ratio=$(get_ratio)
echo "$ram_label $ram_ratio"
}
#run main driver