mirror of
https://github.com/TECHNOFAB11/tmux2k.git
synced 2025-12-11 23:50:08 +01:00
style: shellcheck fixes
This commit is contained in:
parent
54ecf3dc0b
commit
de0e8225a6
10 changed files with 356 additions and 389 deletions
|
|
@ -2,24 +2,24 @@
|
||||||
# setting the locale, some users have issues with different locales, this forces the correct one
|
# setting the locale, some users have issues with different locales, this forces the correct one
|
||||||
export LC_ALL=en_US.UTF-8
|
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
|
||||||
|
|
||||||
linux_acpi() {
|
linux_acpi() {
|
||||||
arg=$1
|
arg=$1
|
||||||
BAT=$(ls -d /sys/class/power_supply/BAT* | head -1)
|
BAT=$(ls -d /sys/class/power_supply/BAT* | head -1)
|
||||||
if [ ! -x "$(which acpi 2> /dev/null)" ];then
|
if [ ! -x "$(which acpi 2>/dev/null)" ]; then
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
status)
|
status)
|
||||||
cat $BAT/status
|
cat "$BAT"/status
|
||||||
;;
|
;;
|
||||||
|
|
||||||
percent)
|
percent)
|
||||||
cat $BAT/capacity
|
cat "$BAT"/capacity
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*) ;;
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
|
|
@ -29,14 +29,13 @@ linux_acpi() {
|
||||||
percent)
|
percent)
|
||||||
acpi | cut -d: -f2- | cut -d, -f2 | tr -d '% '
|
acpi | cut -d: -f2- | cut -d, -f2 | tr -d '% '
|
||||||
;;
|
;;
|
||||||
*)
|
*) ;;
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
battery_percent()
|
battery_percent() {
|
||||||
{
|
|
||||||
# Check OS
|
# Check OS
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
|
|
@ -52,17 +51,16 @@ battery_percent()
|
||||||
echo $(apm | sed '8,11d' | grep life | awk '{print $4}')
|
echo $(apm | sed '8,11d' | grep life | awk '{print $4}')
|
||||||
;;
|
;;
|
||||||
|
|
||||||
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
CYGWIN* | MINGW32* | MSYS* | MINGW*)
|
||||||
# leaving empty - TODO - windows compatability
|
# leaving empty - TODO - windows compatability
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*) ;;
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
battery_status()
|
battery_status() {
|
||||||
{
|
|
||||||
# Check OS
|
# Check OS
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
|
|
@ -77,16 +75,16 @@ battery_status()
|
||||||
status=$(apm | sed '8,11d' | grep Status | awk '{printf $3}')
|
status=$(apm | sed '8,11d' | grep Status | awk '{printf $3}')
|
||||||
;;
|
;;
|
||||||
|
|
||||||
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
CYGWIN* | MINGW32* | MSYS* | MINGW*)
|
||||||
# leaving empty - TODO - windows compatability
|
# leaving empty - TODO - windows compatability
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*) ;;
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case $status in
|
case $status in
|
||||||
discharging|Discharging)
|
discharging | Discharging)
|
||||||
echo ''
|
echo ''
|
||||||
;;
|
;;
|
||||||
high)
|
high)
|
||||||
|
|
@ -109,8 +107,7 @@ battery_status()
|
||||||
# fi
|
# fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main() {
|
||||||
{
|
|
||||||
bat_label=$(get_tmux_option "@tmux2k-battery-label" "")
|
bat_label=$(get_tmux_option "@tmux2k-battery-label" "")
|
||||||
bat_stat=$(battery_status)
|
bat_stat=$(battery_status)
|
||||||
bat_perc=$(battery_percent)
|
bat_perc=$(battery_percent)
|
||||||
|
|
@ -126,4 +123,3 @@ main()
|
||||||
|
|
||||||
#run main driver program
|
#run main driver program
|
||||||
main
|
main
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,10 @@
|
||||||
# setting the locale, some users have issues with different locales, this forces the correct one
|
# setting the locale, some users have issues with different locales, this forces the correct one
|
||||||
export LC_ALL=en_US.UTF-8
|
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_percent() {
|
||||||
{
|
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -d 0.01 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
|
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -d 0.01 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
|
||||||
|
|
@ -16,12 +15,12 @@ get_percent()
|
||||||
Darwin)
|
Darwin)
|
||||||
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
|
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
|
||||||
cpucores=$(sysctl -n hw.logicalcpu)
|
cpucores=$(sysctl -n hw.logicalcpu)
|
||||||
cpuusage=$(( cpuvalue / cpucores ))
|
cpuusage=$((cpuvalue / cpucores))
|
||||||
percent="$cpuusage%"
|
percent="$cpuusage%"
|
||||||
normalize_percent_len $percent
|
normalize_percent_len $percent
|
||||||
;;
|
;;
|
||||||
|
|
||||||
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
CYGWIN* | MINGW32* | MSYS* | MINGW*)
|
||||||
# TODO - windows compatability
|
# TODO - windows compatability
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
@ -31,7 +30,7 @@ get_load() {
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux | Darwin)
|
Linux | Darwin)
|
||||||
loadavg=$(uptime | awk -F'[a-z]:' '{ print $2}' | sed 's/,//g')
|
loadavg=$(uptime | awk -F'[a-z]:' '{ print $2}' | sed 's/,//g')
|
||||||
echo $loadavg
|
echo "$loadavg"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
CYGWIN* | MINGW32* | MSYS* | MINGW*)
|
CYGWIN* | MINGW32* | MSYS* | MINGW*)
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,21 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
IFS=' ' read -r -a hide_status <<< $(get_tmux_option "@tmux2k-git-disable-status" "false")
|
IFS=' ' read -r -a hide_status <<<$(get_tmux_option "@tmux2k-git-disable-status" "false")
|
||||||
IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@tmux2k-git-show-current-symbol" "")
|
IFS=' ' read -r -a current_symbol <<<$(get_tmux_option "@tmux2k-git-show-current-symbol" "")
|
||||||
IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@tmux2k-git-show-diff-symbol" "")
|
IFS=' ' read -r -a diff_symbol <<<$(get_tmux_option "@tmux2k-git-show-diff-symbol" "")
|
||||||
IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@tmux2k-git-no-repo-message" "")
|
IFS=' ' read -r -a no_repo_message <<<$(get_tmux_option "@tmux2k-git-no-repo-message" "")
|
||||||
|
|
||||||
# Get added, modified, updated and deleted files from git status
|
# Get added, modified, updated and deleted files from git status
|
||||||
getChanges()
|
getChanges() {
|
||||||
{
|
declare -i added=0
|
||||||
declare -i added=0;
|
declare -i modified=0
|
||||||
declare -i modified=0;
|
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" status -s); do
|
||||||
|
|
||||||
do
|
|
||||||
case $i in
|
case $i in
|
||||||
'A')
|
'A')
|
||||||
added+=1
|
added+=1
|
||||||
|
|
@ -42,18 +39,15 @@ for i in $(git -C $path status -s)
|
||||||
[ $updated -gt 0 ] && output+=" ${updated} "
|
[ $updated -gt 0 ] && output+=" ${updated} "
|
||||||
[ $deleted -gt 0 ] && output+=" ${deleted} "
|
[ $deleted -gt 0 ] && output+=" ${deleted} "
|
||||||
|
|
||||||
echo $output
|
echo "$output"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# getting the #{pane_current_path} from tmux2k.sh is no longer possible
|
# getting the #{pane_current_path} from tmux2k.sh is no longer possible
|
||||||
getPaneDir()
|
getPaneDir() {
|
||||||
{
|
|
||||||
nextone="false"
|
nextone="false"
|
||||||
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}");
|
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}"); do
|
||||||
do
|
|
||||||
if [ "$nextone" == "true" ]; then
|
if [ "$nextone" == "true" ]; then
|
||||||
echo $i
|
echo "$i"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if [ "$i" == "1" ]; then
|
if [ "$i" == "1" ]; then
|
||||||
|
|
@ -62,10 +56,8 @@ getPaneDir()
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# check if the current or diff symbol is empty to remove ugly padding
|
# check if the current or diff symbol is empty to remove ugly padding
|
||||||
checkEmptySymbol()
|
checkEmptySymbol() {
|
||||||
{
|
|
||||||
symbol=$1
|
symbol=$1
|
||||||
if [ "$symbol" == "" ]; then
|
if [ "$symbol" == "" ]; then
|
||||||
echo "true"
|
echo "true"
|
||||||
|
|
@ -75,10 +67,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() {
|
||||||
{
|
|
||||||
if [ "$(checkForGitDir)" == "true" ]; then
|
if [ "$(checkForGitDir)" == "true" ]; then
|
||||||
if [ "$(git -C $path status -s)" != "" ]; then
|
if [ "$(git -C "$path" status -s)" != "" ]; then
|
||||||
echo "true"
|
echo "true"
|
||||||
else
|
else
|
||||||
echo "false"
|
echo "false"
|
||||||
|
|
@ -89,9 +80,8 @@ checkForChanges()
|
||||||
}
|
}
|
||||||
|
|
||||||
# check if a git repo exists in the directory
|
# check if a git repo exists in the directory
|
||||||
checkForGitDir()
|
checkForGitDir() {
|
||||||
{
|
if [ "$(git -C "$path" rev-parse --abbrev-ref HEAD)" != "" ]; then
|
||||||
if [ "$(git -C $path rev-parse --abbrev-ref HEAD)" != "" ]; then
|
|
||||||
echo "true"
|
echo "true"
|
||||||
else
|
else
|
||||||
echo "false"
|
echo "false"
|
||||||
|
|
@ -99,18 +89,16 @@ checkForGitDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
# return branch name if there is one
|
# return branch name if there is one
|
||||||
getBranch()
|
getBranch() {
|
||||||
{
|
|
||||||
if [ $(checkForGitDir) == "true" ]; then
|
if [ $(checkForGitDir) == "true" ]; then
|
||||||
printf "%.20s " $(git -C $path rev-parse --abbrev-ref HEAD)
|
printf "%.20s " $(git -C "$path" rev-parse --abbrev-ref HEAD)
|
||||||
else
|
else
|
||||||
echo $no_repo_message
|
echo "$no_repo_message"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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)"
|
||||||
|
|
||||||
|
|
@ -119,13 +107,13 @@ getMessage()
|
||||||
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"
|
echo "${changes} $branch"
|
||||||
else
|
else
|
||||||
echo "$diff_symbol ${changes} $branch"
|
echo "$diff_symbol ${changes} $branch"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
|
if [ $(checkEmptySymbol "$diff_symbol") == "true" ]; then
|
||||||
echo "$branch"
|
echo "$branch"
|
||||||
else
|
else
|
||||||
echo "$diff_symbol $branch"
|
echo "$diff_symbol $branch"
|
||||||
|
|
@ -133,19 +121,18 @@ getMessage()
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
|
if [ $(checkEmptySymbol "$current_symbol") == "true" ]; then
|
||||||
echo "$branch"
|
echo "$branch"
|
||||||
else
|
else
|
||||||
echo "$current_symbol $branch"
|
echo "$current_symbol $branch"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo $no_repo_message
|
echo "$no_repo_message"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main() {
|
||||||
{
|
|
||||||
path=$(getPaneDir)
|
path=$(getPaneDir)
|
||||||
getMessage
|
getMessage
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,10 @@
|
||||||
# setting the locale, some users have issues with different locales, this forces the correct one
|
# setting the locale, some users have issues with different locales, this forces the correct one
|
||||||
export LC_ALL=en_US.UTF-8
|
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_platform()
|
get_platform() {
|
||||||
{
|
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}')
|
gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}')
|
||||||
|
|
@ -17,14 +16,13 @@ get_platform()
|
||||||
# TODO - Darwin/Mac compatability
|
# TODO - Darwin/Mac compatability
|
||||||
;;
|
;;
|
||||||
|
|
||||||
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
CYGWIN* | MINGW32* | MSYS* | MINGW*)
|
||||||
# TODO - windows compatability
|
# TODO - windows compatability
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
get_gpu()
|
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 | grep '%' | awk '{ sum += $13 } END { printf("%d%%\n", sum / NR) }')
|
||||||
|
|
@ -34,8 +32,7 @@ get_gpu()
|
||||||
normalize_percent_len $usage
|
normalize_percent_len $usage
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
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 "@tmux2k-refresh-rate" 5)
|
RATE=$(get_tmux_option "@tmux2k-refresh-rate" 5)
|
||||||
gpu_label=$(get_tmux_option "@tmux2k-gpu-usage-label" "GPU")
|
gpu_label=$(get_tmux_option "@tmux2k-gpu-usage-label" "GPU")
|
||||||
|
|
|
||||||
|
|
@ -2,26 +2,25 @@
|
||||||
# setting the locale, some users have issues with different locales, this forces the correct one
|
# setting the locale, some users have issues with different locales, this forces the correct one
|
||||||
export LC_ALL=en_US.UTF-8
|
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_percent() {
|
||||||
{
|
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
total_mem_gb=$(free -g | awk '/^Mem/ {print $2}')
|
total_mem_gb=$(free -g | awk '/^Mem/ {print $2}')
|
||||||
used_mem=$(free -g | awk '/^Mem/ {print $3}')
|
used_mem=$(free -g | awk '/^Mem/ {print $3}')
|
||||||
total_mem=$(free -h | awk '/^Mem/ {print $2}')
|
total_mem=$(free -h | awk '/^Mem/ {print $2}')
|
||||||
if (( "$total_mem_gb" == 0)); then
|
if (("$total_mem_gb" == 0)); then
|
||||||
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
|
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
|
||||||
total_mem_mb=$(free -m | awk '/^Mem/ {print $2}')
|
total_mem_mb=$(free -m | awk '/^Mem/ {print $2}')
|
||||||
echo $memory_usage\M\B/$total_mem_mb\M\B
|
echo "$memory_usage"\M\B/"$total_mem_mb"\M\B
|
||||||
elif (( "$used_mem" == 0 )); then
|
elif (("$used_mem" == 0)); then
|
||||||
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
|
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
|
||||||
echo $memory_usage\M\B/$total_mem_gb\G\B
|
echo "$memory_usage"\M\B/"$total_mem_gb"\G\B
|
||||||
else
|
else
|
||||||
memory_usage=$(free -g | awk '/^Mem/ {print $3}')
|
memory_usage=$(free -g | awk '/^Mem/ {print $3}')
|
||||||
echo $memory_usage\G\B/$total_mem_gb\G\B
|
echo "$memory_usage"\G\B/"$total_mem_gb"\G\B
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
@ -29,10 +28,10 @@ get_percent()
|
||||||
# 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"\M\B/"$total_mem"
|
||||||
else
|
else
|
||||||
memory=$(($used_mem/1024))
|
memory=$(($used_mem / 1024))
|
||||||
echo $memory\G\B/$total_mem
|
echo $memory\G\B/$total_mem
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
@ -48,22 +47,21 @@ 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\M\B/$total_mem
|
||||||
else
|
else
|
||||||
memory=$(($used_mem/1024))
|
memory=$(($used_mem / 1024))
|
||||||
echo $memory\G\B/$total_mem
|
echo $memory\G\B/$total_mem
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
CYGWIN* | MINGW32* | MSYS* | MINGW*)
|
||||||
# TODO - windows compatability
|
# TODO - windows compatability
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
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 "@tmux2k-refresh-rate" 5)
|
RATE=$(get_tmux_option "@tmux2k-refresh-rate" 5)
|
||||||
ram_label=$(get_tmux_option "@tmux2k-ram-usage-label" "")
|
ram_label=$(get_tmux_option "@tmux2k-ram-usage-label" "")
|
||||||
|
|
|
||||||
|
|
@ -11,30 +11,26 @@ fixedlocation=$3
|
||||||
LOCKFILE=/tmp/.tmux2k-tmux-weather.lock
|
LOCKFILE=/tmp/.tmux2k-tmux-weather.lock
|
||||||
DATAFILE=/tmp/.tmux2k-tmux-data
|
DATAFILE=/tmp/.tmux2k-tmux-data
|
||||||
|
|
||||||
ensure_single_process()
|
ensure_single_process() {
|
||||||
{
|
|
||||||
# check for another running instance of this script and terminate it if found
|
# check for another running instance of this script and terminate it if found
|
||||||
[ -f $LOCKFILE ] && ps -p "$(cat $LOCKFILE)" -o cmd= | grep -F " ${BASH_SOURCE[0]}" && kill "$(cat $LOCKFILE)"
|
[ -f $LOCKFILE ] && ps -p "$(cat $LOCKFILE)" -o cmd= | grep -F " ${BASH_SOURCE[0]}" && kill "$(cat $LOCKFILE)"
|
||||||
echo $$ > $LOCKFILE
|
echo $$ >$LOCKFILE
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main() {
|
||||||
{
|
|
||||||
ensure_single_process
|
ensure_single_process
|
||||||
|
|
||||||
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
if [ ! -f $DATAFILE ]; then
|
if [ ! -f $DATAFILE ]; then
|
||||||
printf "Loading..." > $DATAFILE
|
printf "Loading..." >$DATAFILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
"$current_dir"/weather.sh > $DATAFILE
|
"$current_dir"/weather.sh >$DATAFILE
|
||||||
|
|
||||||
while tmux has-session &> /dev/null
|
while tmux has-session &>/dev/null; do
|
||||||
do
|
"$current_dir"/weather.sh "$fahrenheit" "$location" "$fixedlocation" >$DATAFILE
|
||||||
"$current_dir"/weather.sh "$fahrenheit" "$location" "$fixedlocation" > $DATAFILE
|
if tmux has-session &>/dev/null; then
|
||||||
if tmux has-session &> /dev/null
|
|
||||||
then
|
|
||||||
sleep 1200
|
sleep 1200
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ main() {
|
||||||
# Handle left icon padding
|
# Handle left icon padding
|
||||||
padding=""
|
padding=""
|
||||||
if [ "$show_left_icon_padding" -gt "0" ]; then
|
if [ "$show_left_icon_padding" -gt "0" ]; then
|
||||||
padding="$(printf '%*s' $show_left_icon_padding)"
|
padding="$(printf '%*s' "$show_left_icon_padding")"
|
||||||
fi
|
fi
|
||||||
left_icon="$left_icon$padding"
|
left_icon="$left_icon$padding"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,7 @@ normalize_percent_len() {
|
||||||
percent_len=${#1}
|
percent_len=${#1}
|
||||||
let diff_len=$max_len-$percent_len
|
let diff_len=$max_len-$percent_len
|
||||||
# if the diff_len is even, left will have 1 more space than right
|
# if the diff_len is even, left will have 1 more space than right
|
||||||
let left_spaces=($diff_len+1)/2
|
let left_spaces=($diff_len + 1)/2
|
||||||
let right_spaces=($diff_len)/2
|
let right_spaces=($diff_len)/2
|
||||||
printf "%${left_spaces}s%s%${right_spaces}s\n" "" $1 ""
|
printf "%${left_spaces}s%s%${right_spaces}s\n" "" $1 ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,29 +6,26 @@ fahrenheit=$1
|
||||||
location=$2
|
location=$2
|
||||||
fixedlocation=$3
|
fixedlocation=$3
|
||||||
|
|
||||||
display_location()
|
display_location() {
|
||||||
{
|
if $location && [[ -n "$fixedlocation" ]]; then
|
||||||
if $location && [[ ! -z "$fixedlocation" ]]; then
|
|
||||||
echo " $fixedlocation"
|
echo " $fixedlocation"
|
||||||
elif $location; then
|
elif $location; then
|
||||||
city=$(curl -s https://ipinfo.io/city 2> /dev/null)
|
city=$(curl -s https://ipinfo.io/city 2>/dev/null)
|
||||||
region=$(curl -s https://ipinfo.io/region 2> /dev/null)
|
region=$(curl -s https://ipinfo.io/region 2>/dev/null)
|
||||||
echo " $city, $region"
|
echo " $city, $region"
|
||||||
else
|
else
|
||||||
echo ''
|
echo ''
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch_weather_information()
|
fetch_weather_information() {
|
||||||
{
|
|
||||||
display_weather=$1
|
display_weather=$1
|
||||||
# it gets the weather condition textual name (%C), and the temperature (%t)
|
# it gets the weather condition textual name (%C), and the temperature (%t)
|
||||||
curl -sL wttr.in/$fixedlocation\?format="%C+%t$display_weather"
|
curl -sL wttr.in/"$fixedlocation"\?format="%C+%t$display_weather"
|
||||||
}
|
}
|
||||||
|
|
||||||
#get weather display
|
#get weather display
|
||||||
display_weather()
|
display_weather() {
|
||||||
{
|
|
||||||
if $fahrenheit; then
|
if $fahrenheit; then
|
||||||
display_weather='&u' # for USA system
|
display_weather='&u' # for USA system
|
||||||
else
|
else
|
||||||
|
|
@ -43,8 +40,7 @@ display_weather()
|
||||||
echo "$unicode${temperature/+/}" # remove the plus sign to the temperature
|
echo "$unicode${temperature/+/}" # remove the plus sign to the temperature
|
||||||
}
|
}
|
||||||
|
|
||||||
forecast_unicode()
|
forecast_unicode() {
|
||||||
{
|
|
||||||
weather_condition=$(echo "$weather_condition" | awk '{print tolower($0)}')
|
weather_condition=$(echo "$weather_condition" | awk '{print tolower($0)}')
|
||||||
|
|
||||||
if [[ $weather_condition =~ 'snow' ]]; then
|
if [[ $weather_condition =~ 'snow' ]]; then
|
||||||
|
|
@ -60,8 +56,7 @@ forecast_unicode()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main() {
|
||||||
{
|
|
||||||
# process should be cancelled when session is killed
|
# process should be cancelled when session is killed
|
||||||
if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then
|
if ping -q -c 1 -W 1 ipinfo.io &>/dev/null; then
|
||||||
echo "$(display_weather)$(display_location)"
|
echo "$(display_weather)$(display_location)"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue