consistent formatting across all scripts
This commit is contained in:
parent
dbdc65d22b
commit
d00c245d4e
10 changed files with 413 additions and 408 deletions
5
.editorconfig
Normal file
5
.editorconfig
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[*]
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
|
@ -3,121 +3,121 @@
|
||||||
export LC_ALL=en_US.UTF-8
|
export LC_ALL=en_US.UTF-8
|
||||||
|
|
||||||
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
|
||||||
status)
|
status)
|
||||||
acpi | cut -d: -f2- | cut -d, -f1 | tr -d ' '
|
acpi | cut -d: -f2- | cut -d, -f1 | tr -d ' '
|
||||||
;;
|
;;
|
||||||
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)
|
||||||
percent=$(linux_acpi percent)
|
percent=$(linux_acpi percent)
|
||||||
[ -n "$percent" ] && echo " $percent"
|
[ -n "$percent" ] && echo " $percent"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
Darwin)
|
Darwin)
|
||||||
echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%')
|
echo $(pmset -g batt | grep -Eo '[0-9]?[0-9]?[0-9]%')
|
||||||
;;
|
;;
|
||||||
|
|
||||||
FreeBSD)
|
FreeBSD)
|
||||||
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)
|
||||||
status=$(linux_acpi status)
|
status=$(linux_acpi status)
|
||||||
;;
|
;;
|
||||||
|
|
||||||
Darwin)
|
Darwin)
|
||||||
status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2 | tr -d " ")
|
status=$(pmset -g batt | sed -n 2p | cut -d ';' -f 2 | tr -d " ")
|
||||||
;;
|
;;
|
||||||
|
|
||||||
FreeBSD)
|
FreeBSD)
|
||||||
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)
|
||||||
echo ''
|
echo ''
|
||||||
;;
|
;;
|
||||||
charging)
|
charging)
|
||||||
echo 'AC'
|
echo 'AC'
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo 'AC'
|
echo 'AC'
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
### Old if statements didn't work on BSD, they're probably not POSIX compliant, not sure
|
### Old if statements didn't work on BSD, they're probably not POSIX compliant, not sure
|
||||||
# if [ $status = 'discharging' ] || [ $status = 'Discharging' ]; then
|
# if [ $status = 'discharging' ] || [ $status = 'Discharging' ]; then
|
||||||
# echo ''
|
# echo ''
|
||||||
# # elif [ $status = 'charging' ]; then # This is needed for FreeBSD AC checking support
|
# # elif [ $status = 'charging' ]; then # This is needed for FreeBSD AC checking support
|
||||||
# # echo 'AC'
|
# # echo 'AC'
|
||||||
# else
|
# else
|
||||||
# echo 'AC'
|
# echo 'AC'
|
||||||
# fi
|
# fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
bat_stat=$(battery_status)
|
bat_stat=$(battery_status)
|
||||||
bat_perc=$(battery_percent)
|
bat_perc=$(battery_percent)
|
||||||
|
|
||||||
if [ -z "$bat_stat" ]; then # Test if status is empty or not
|
if [ -z "$bat_stat" ]; then # Test if status is empty or not
|
||||||
echo "♥ $bat_perc"
|
echo "♥ $bat_perc"
|
||||||
elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
|
elif [ -z "$bat_perc" ]; then # In case it is a desktop with no battery percent, only AC power
|
||||||
echo "♥ $bat_stat"
|
echo "♥ $bat_stat"
|
||||||
else
|
else
|
||||||
echo "♥ $bat_stat $bat_perc"
|
echo "♥ $bat_stat $bat_perc"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#run main driver program
|
#run main driver program
|
||||||
|
|
|
@ -14,47 +14,47 @@ get_tmux_option() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# normalize the percentage string to always have a length of 5
|
# normalize the percentage string to always have a length of 5
|
||||||
normalize_percent_len() {
|
normalize_percent_len() {
|
||||||
# the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%"
|
# the max length that the percent can reach, which happens for a two digit number with a decimal house: "99.9%"
|
||||||
max_len=5
|
max_len=5
|
||||||
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 ""
|
||||||
}
|
}
|
||||||
|
|
||||||
get_percent()
|
get_percent()
|
||||||
{
|
{
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
|
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
|
||||||
normalize_percent_len $percent
|
normalize_percent_len $percent
|
||||||
;;
|
;;
|
||||||
|
|
||||||
Darwin)
|
|
||||||
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
|
|
||||||
cpucores=$(sysctl -n hw.logicalcpu)
|
|
||||||
cpuusage=$(( cpuvalue / cpucores ))
|
|
||||||
percent="$cpuusage%"
|
|
||||||
normalize_percent_len $percent
|
|
||||||
;;
|
|
||||||
|
|
||||||
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
Darwin)
|
||||||
# TODO - windows compatability
|
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
|
||||||
;;
|
cpucores=$(sysctl -n hw.logicalcpu)
|
||||||
esac
|
cpuusage=$(( cpuvalue / cpucores ))
|
||||||
|
percent="$cpuusage%"
|
||||||
|
normalize_percent_len $percent
|
||||||
|
;;
|
||||||
|
|
||||||
|
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
||||||
|
# TODO - windows compatability
|
||||||
|
;;
|
||||||
|
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 "@dracula-refresh-rate" 5)
|
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
|
||||||
cpu_percent=$(get_percent)
|
cpu_percent=$(get_percent)
|
||||||
echo "CPU $cpu_percent"
|
echo "CPU $cpu_percent"
|
||||||
sleep $RATE
|
sleep $RATE
|
||||||
}
|
}
|
||||||
|
|
||||||
# run main driver
|
# run main driver
|
||||||
|
|
|
@ -59,27 +59,27 @@ main()
|
||||||
|
|
||||||
# Handle left icon configuration
|
# Handle left icon configuration
|
||||||
case $show_left_icon in
|
case $show_left_icon in
|
||||||
smiley)
|
smiley)
|
||||||
left_icon="☺";;
|
left_icon="☺";;
|
||||||
session)
|
session)
|
||||||
left_icon="#S";;
|
left_icon="#S";;
|
||||||
window)
|
window)
|
||||||
left_icon="#W";;
|
left_icon="#W";;
|
||||||
*)
|
*)
|
||||||
left_icon=$show_left_icon;;
|
left_icon=$show_left_icon;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# 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"
|
||||||
|
|
||||||
# Handle powerline option
|
# Handle powerline option
|
||||||
if $show_powerline; then
|
if $show_powerline; then
|
||||||
right_sep="$show_right_sep"
|
right_sep="$show_right_sep"
|
||||||
left_sep="$show_left_sep"
|
left_sep="$show_left_sep"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# start weather script in background
|
# start weather script in background
|
||||||
|
@ -89,10 +89,10 @@ main()
|
||||||
|
|
||||||
# Set timezone unless hidden by configuration
|
# Set timezone unless hidden by configuration
|
||||||
case $show_timezone in
|
case $show_timezone in
|
||||||
false)
|
false)
|
||||||
timezone="";;
|
timezone="";;
|
||||||
true)
|
true)
|
||||||
timezone="#(date +%Z)";;
|
timezone="#(date +%Z)";;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case $show_flags in
|
case $show_flags in
|
||||||
|
@ -109,14 +109,14 @@ main()
|
||||||
|
|
||||||
# set the prefix + t time format
|
# set the prefix + t time format
|
||||||
if $show_military; then
|
if $show_military; then
|
||||||
tmux set-option -g clock-mode-style 24
|
tmux set-option -g clock-mode-style 24
|
||||||
else
|
else
|
||||||
tmux set-option -g clock-mode-style 12
|
tmux set-option -g clock-mode-style 12
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set length
|
# set length
|
||||||
tmux set-option -g status-left-length 100
|
tmux set-option -g status-left-length 100
|
||||||
tmux set-option -g status-right-length 100
|
tmux set-option -g status-right-length 100
|
||||||
|
|
||||||
# pane border styling
|
# pane border styling
|
||||||
if $show_border_contrast; then
|
if $show_border_contrast; then
|
||||||
|
@ -135,113 +135,113 @@ main()
|
||||||
# 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 $show_weather && [ ! -f $datafile ]; do
|
while $show_weather && [ ! -f $datafile ]; do
|
||||||
sleep 0.01
|
sleep 0.01
|
||||||
done
|
done
|
||||||
|
|
||||||
# Powerline Configuration
|
# Powerline Configuration
|
||||||
if $show_powerline; then
|
if $show_powerline; then
|
||||||
|
|
||||||
tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon} #[fg=${green},bg=${gray}]#{?client_prefix,#[fg=${yellow}],}${left_sep}"
|
tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon} #[fg=${green},bg=${gray}]#{?client_prefix,#[fg=${yellow}],}${left_sep}"
|
||||||
tmux set-option -g status-right ""
|
tmux set-option -g status-right ""
|
||||||
powerbg=${gray}
|
powerbg=${gray}
|
||||||
|
|
||||||
if $show_battery; then # battery
|
if $show_battery; then # battery
|
||||||
tmux set-option -g status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh)"
|
tmux set-option -g status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh)"
|
||||||
powerbg=${pink}
|
powerbg=${pink}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $show_ram_usage; then
|
||||||
|
tmux set-option -ga status-right "#[fg=${cyan},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh)"
|
||||||
|
powerbg=${cyan}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $show_cpu_usage; then
|
||||||
|
tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh)"
|
||||||
|
powerbg=${orange}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $show_gpu_usage; then
|
||||||
|
tmux set-option -ga status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/gpu_usage.sh)"
|
||||||
|
powerbg=${pink}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $show_network; then # network
|
||||||
|
tmux set-option -ga status-right "#[fg=${cyan},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh)"
|
||||||
|
powerbg=${cyan}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$show_network_bandwith" != "" ]]; then # network bandwith
|
||||||
|
tmux set-option -g status-right-length 250
|
||||||
|
tmux set-option -ga status-right "#[fg=${green},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh)"
|
||||||
|
powerbg=${green}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $show_weather; then # weather
|
||||||
|
tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #(cat $datafile)"
|
||||||
|
powerbg=${orange}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if $show_time; then
|
||||||
|
if $show_day_month && $show_military ; then # military time and dd/mm
|
||||||
|
tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %d/%m %R ${timezone} "
|
||||||
|
elif $show_military; then # only military time
|
||||||
|
tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %m/%d %R ${timezone} "
|
||||||
|
elif $show_day_month; then # only dd/mm
|
||||||
|
tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %d/%m %I:%M %p ${timezone} "
|
||||||
|
else
|
||||||
|
tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p ${timezone} "
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if $show_ram_usage; then
|
tmux set-window-option -g window-status-current-format "#[fg=${gray},bg=${dark_purple}]${left_sep}#[fg=${white},bg=${dark_purple}] #I #W${current_flags} #[fg=${dark_purple},bg=${gray}]${left_sep}"
|
||||||
tmux set-option -ga status-right "#[fg=${cyan},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh)"
|
|
||||||
powerbg=${cyan}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $show_cpu_usage; then
|
|
||||||
tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh)"
|
|
||||||
powerbg=${orange}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $show_gpu_usage; then
|
|
||||||
tmux set-option -ga status-right "#[fg=${pink},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${pink}] #($current_dir/gpu_usage.sh)"
|
|
||||||
powerbg=${pink}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $show_network; then # network
|
|
||||||
tmux set-option -ga status-right "#[fg=${cyan},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh)"
|
|
||||||
powerbg=${cyan}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$show_network_bandwith" != "" ]]; then # network bandwith
|
|
||||||
tmux set-option -g status-right-length 250
|
|
||||||
tmux set-option -ga status-right "#[fg=${green},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh)"
|
|
||||||
powerbg=${green}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $show_weather; then # weather
|
|
||||||
tmux set-option -ga status-right "#[fg=${orange},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${dark_gray},bg=${orange}] #(cat $datafile)"
|
|
||||||
powerbg=${orange}
|
|
||||||
fi
|
|
||||||
|
|
||||||
if $show_time; then
|
|
||||||
if $show_day_month && $show_military ; then # military time and dd/mm
|
|
||||||
tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %d/%m %R ${timezone} "
|
|
||||||
elif $show_military; then # only military time
|
|
||||||
tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %m/%d %R ${timezone} "
|
|
||||||
elif $show_day_month; then # only dd/mm
|
|
||||||
tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %d/%m %I:%M %p ${timezone} "
|
|
||||||
else
|
|
||||||
tmux set-option -ga status-right "#[fg=${dark_purple},bg=${powerbg},nobold,nounderscore,noitalics] ${right_sep}#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p ${timezone} "
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
tmux set-window-option -g window-status-current-format "#[fg=${gray},bg=${dark_purple}]${left_sep}#[fg=${white},bg=${dark_purple}] #I #W${current_flags} #[fg=${dark_purple},bg=${gray}]${left_sep}"
|
|
||||||
|
|
||||||
# Non Powerline Configuration
|
# Non Powerline Configuration
|
||||||
else
|
else
|
||||||
tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon}"
|
tmux set-option -g status-left "#[bg=${green},fg=${dark_gray}]#{?client_prefix,#[bg=${yellow}],} ${left_icon}"
|
||||||
|
|
||||||
tmux set-option -g status-right ""
|
tmux set-option -g status-right ""
|
||||||
|
|
||||||
if $show_battery; then # battery
|
if $show_battery; then # battery
|
||||||
tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh) "
|
tmux set-option -g status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/battery.sh) "
|
||||||
fi
|
fi
|
||||||
if $show_ram_usage; then
|
if $show_ram_usage; then
|
||||||
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh) "
|
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/ram_info.sh) "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $show_cpu_usage; then
|
if $show_cpu_usage; then
|
||||||
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh) "
|
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #($current_dir/cpu_info.sh) "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $show_gpu_usage; then
|
if $show_gpu_usage; then
|
||||||
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/gpu_usage.sh) "
|
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${pink}] #($current_dir/gpu_usage.sh) "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $show_network; then # network
|
if $show_network; then # network
|
||||||
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh) "
|
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${cyan}] #($current_dir/network.sh) "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$show_network_bandwith" != "" ]]; then # network bandwith
|
if [[ "$show_network_bandwith" != "" ]]; then # network bandwith
|
||||||
tmux set-option -g status-right-length 250
|
tmux set-option -g status-right-length 250
|
||||||
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh) "
|
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${green}] #($current_dir/network_bandwith.sh) "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $show_weather; then # weather
|
if $show_weather; then # weather
|
||||||
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #(cat $datafile) "
|
tmux set-option -ga status-right "#[fg=${dark_gray},bg=${orange}] #(cat $datafile) "
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if $show_time; then
|
if $show_time; then
|
||||||
if $show_day_month && $show_military ; then # military time and dd/mm
|
if $show_day_month && $show_military ; then # military time and dd/mm
|
||||||
tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %d/%m %R ${timezone} "
|
tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %d/%m %R ${timezone} "
|
||||||
elif $show_military; then # only military time
|
elif $show_military; then # only military time
|
||||||
tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %R ${timezone} "
|
tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %R ${timezone} "
|
||||||
elif $show_day_month; then # only dd/mm
|
elif $show_day_month; then # only dd/mm
|
||||||
tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %d/%m %I:%M %p ${timezone} "
|
tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %d/%m %I:%M %p ${timezone} "
|
||||||
else
|
else
|
||||||
tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p ${timezone} "
|
tmux set-option -ga status-right "#[fg=${white},bg=${dark_purple}] %a %m/%d %I:%M %p ${timezone} "
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
tmux set-window-option -g window-status-current-format "#[fg=${white},bg=${dark_purple}] #I #W${current_flags} "
|
tmux set-window-option -g window-status-current-format "#[fg=${white},bg=${dark_purple}] #I #W${current_flags} "
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -16,38 +16,38 @@ get_tmux_option() {
|
||||||
|
|
||||||
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}')
|
||||||
echo $gpu
|
echo $gpu
|
||||||
;;
|
;;
|
||||||
|
|
||||||
Darwin)
|
Darwin)
|
||||||
# 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) }')
|
||||||
else
|
else
|
||||||
usage='unknown'
|
usage='unknown'
|
||||||
fi
|
fi
|
||||||
echo $usage
|
echo $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 "@dracula-refresh-rate" 5)
|
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
|
||||||
gpu_usage=$(get_gpu)
|
gpu_usage=$(get_gpu)
|
||||||
echo "GPU $gpu_usage"
|
echo "GPU $gpu_usage"
|
||||||
sleep $RATE
|
sleep $RATE
|
||||||
}
|
}
|
||||||
# run the main driver
|
# run the main driver
|
||||||
main
|
main
|
||||||
|
|
|
@ -6,46 +6,46 @@ HOSTS="google.com github.com example.com"
|
||||||
|
|
||||||
get_ssid()
|
get_ssid()
|
||||||
{
|
{
|
||||||
# Check OS
|
# Check OS
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
SSID=$(iw dev | sed -nr 's/^\t\tssid (.*)/\1/p')
|
SSID=$(iw dev | sed -nr 's/^\t\tssid (.*)/\1/p')
|
||||||
if [ -n "$SSID" ]; then
|
if [ -n "$SSID" ]; then
|
||||||
printf '%s' "$SSID"
|
printf '%s' "$SSID"
|
||||||
else
|
else
|
||||||
echo 'Ethernet'
|
echo 'Ethernet'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
Darwin)
|
Darwin)
|
||||||
if /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2 | sed 's/ ^*//g' &> /dev/null; then
|
if /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2 | sed 's/ ^*//g' &> /dev/null; then
|
||||||
echo "$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2)" | sed 's/ ^*//g'
|
echo "$(/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I | grep -E ' SSID' | cut -d ':' -f 2)" | sed 's/ ^*//g'
|
||||||
else
|
else
|
||||||
echo 'Ethernet'
|
echo 'Ethernet'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
||||||
# leaving empty - TODO - windows compatability
|
# leaving empty - TODO - windows compatability
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
network="Offline"
|
network="Offline"
|
||||||
for host in $HOSTS; do
|
for host in $HOSTS; do
|
||||||
if ping -q -c 1 -W 1 $host &>/dev/null; then
|
if ping -q -c 1 -W 1 $host &>/dev/null; then
|
||||||
network="$(get_ssid)"
|
network="$(get_ssid)"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "$network"
|
echo "$network"
|
||||||
}
|
}
|
||||||
|
|
||||||
#run main driver function
|
#run main driver function
|
||||||
|
|
|
@ -6,22 +6,22 @@ network_name=$(tmux show-option -gqv "@dracula-network-bandwith")
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
|
initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
|
||||||
initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
|
initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
|
||||||
|
|
||||||
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)
|
sleep $INTERVAL
|
||||||
total_upload_bps=$(expr $final_upload - $initial_upload)
|
|
||||||
|
|
||||||
total_download_kbps=$(echo "scale=2; $total_download_bps / 1024" | bc)
|
final_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
|
||||||
total_upload_kbps=$(echo "scale=2; $total_upload_bps / 1024" | bc)
|
final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
|
||||||
|
|
||||||
echo "↓ $total_download_kbps kB/s • ↑ $total_upload_kbps kB/s"
|
total_download_bps=$(expr $final_download - $initial_download)
|
||||||
done
|
total_upload_bps=$(expr $final_upload - $initial_upload)
|
||||||
|
|
||||||
|
total_download_kbps=$(echo "scale=2; $total_download_bps / 1024" | bc)
|
||||||
|
total_upload_kbps=$(echo "scale=2; $total_upload_bps / 1024" | bc)
|
||||||
|
|
||||||
|
echo "↓ $total_download_kbps kB/s • ↑ $total_upload_kbps kB/s"
|
||||||
|
done
|
||||||
}
|
}
|
||||||
main
|
main
|
||||||
|
|
|
@ -16,70 +16,70 @@ get_tmux_option() {
|
||||||
|
|
||||||
get_percent()
|
get_percent()
|
||||||
{
|
{
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
# percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}')
|
# percent=$(free -m | awk 'NR==2{printf "%.1f%%\n", $3*100/$2}')
|
||||||
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\G\B
|
echo $memory_usage\M\B/$total_mem\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\G\B
|
echo $memory_usage\G\B/$total_mem\G\B
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
Darwin)
|
Darwin)
|
||||||
# percent=$(ps -A -o %mem | awk '{mem += $1} END {print mem}')
|
# percent=$(ps -A -o %mem | awk '{mem += $1} END {print mem}')
|
||||||
# Get used memory blocks with vm_stat, multiply by 4096 to get size in bytes, then convert to MiB
|
# Get used memory blocks with vm_stat, multiply by 4096 to get size in bytes, then convert to MiB
|
||||||
used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk '{printf "%d\n", ($1+$2) * 4096 / 1048576}')
|
used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk '{printf "%d\n", ($1+$2) * 4096 / 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
|
||||||
;;
|
;;
|
||||||
|
|
||||||
FreeBSD)
|
|
||||||
# Looked at the code from neofetch
|
|
||||||
hw_pagesize="$(sysctl -n hw.pagesize)"
|
|
||||||
mem_inactive="$(($(sysctl -n vm.stats.vm.v_inactive_count) * hw_pagesize))"
|
|
||||||
mem_unused="$(($(sysctl -n vm.stats.vm.v_free_count) * hw_pagesize))"
|
|
||||||
mem_cache="$(($(sysctl -n vm.stats.vm.v_cache_count) * hw_pagesize))"
|
|
||||||
|
|
||||||
free_mem=$(((mem_inactive + mem_unused + mem_cache) / 1024 / 1024))
|
FreeBSD)
|
||||||
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
|
# Looked at the code from neofetch
|
||||||
used_mem=$((total_mem - free_mem))
|
hw_pagesize="$(sysctl -n hw.pagesize)"
|
||||||
echo $used_mem
|
mem_inactive="$(($(sysctl -n vm.stats.vm.v_inactive_count) * hw_pagesize))"
|
||||||
if (( $used_mem < 1024 )); then
|
mem_unused="$(($(sysctl -n vm.stats.vm.v_free_count) * hw_pagesize))"
|
||||||
echo $used_mem\M\B/$total_mem
|
mem_cache="$(($(sysctl -n vm.stats.vm.v_cache_count) * hw_pagesize))"
|
||||||
else
|
|
||||||
memory=$(($used_mem/1024))
|
|
||||||
echo $memory\G\B/$total_mem
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
free_mem=$(((mem_inactive + mem_unused + mem_cache) / 1024 / 1024))
|
||||||
# TODO - windows compatability
|
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
|
||||||
;;
|
used_mem=$((total_mem - free_mem))
|
||||||
esac
|
echo $used_mem
|
||||||
|
if (( $used_mem < 1024 )); then
|
||||||
|
echo $used_mem\M\B/$total_mem
|
||||||
|
else
|
||||||
|
memory=$(($used_mem/1024))
|
||||||
|
echo $memory\G\B/$total_mem
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
|
CYGWIN*|MINGW32*|MSYS*|MINGW*)
|
||||||
|
# TODO - windows compatability
|
||||||
|
;;
|
||||||
|
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 "@dracula-refresh-rate" 5)
|
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
|
||||||
ram_percent=$(get_percent)
|
ram_percent=$(get_percent)
|
||||||
echo "RAM $ram_percent"
|
echo "RAM $ram_percent"
|
||||||
sleep $RATE
|
sleep $RATE
|
||||||
}
|
}
|
||||||
|
|
||||||
#run main driver
|
#run main driver
|
||||||
|
|
|
@ -12,35 +12,35 @@ DATAFILE=/tmp/.dracula-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 > $DATAFILE
|
$current_dir/weather.sh $fahrenheit $location > $DATAFILE
|
||||||
if tmux has-session &> /dev/null
|
if tmux has-session &> /dev/null
|
||||||
then
|
then
|
||||||
sleep 1200
|
sleep 1200
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
rm $LOCKFILE
|
rm $LOCKFILE
|
||||||
}
|
}
|
||||||
|
|
||||||
#run main driver function
|
#run main driver function
|
||||||
|
|
|
@ -7,64 +7,64 @@ location=$2
|
||||||
|
|
||||||
display_location()
|
display_location()
|
||||||
{
|
{
|
||||||
if $location; then
|
if $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\?format="%C+%t$display_weather"
|
curl -sL wttr.in\?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
|
||||||
display_weather='&m' # for metric system
|
display_weather='&m' # for metric system
|
||||||
fi
|
fi
|
||||||
weather_information=$(fetch_weather_information $display_weather)
|
weather_information=$(fetch_weather_information $display_weather)
|
||||||
|
|
||||||
weather_condition=$(echo $weather_information | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc
|
weather_condition=$(echo $weather_information | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc
|
||||||
temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
|
temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
|
||||||
unicode=$(forecast_unicode $weather_condition)
|
unicode=$(forecast_unicode $weather_condition)
|
||||||
|
|
||||||
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
|
||||||
echo '❄ '
|
echo '❄ '
|
||||||
elif [[ (($weather_condition =~ 'rain') || ($weather_condition =~ 'shower')) ]]; then
|
elif [[ (($weather_condition =~ 'rain') || ($weather_condition =~ 'shower')) ]]; then
|
||||||
echo '☂ '
|
echo '☂ '
|
||||||
elif [[ (($weather_condition =~ 'overcast') || ($weather_condition =~ 'cloud')) ]]; then
|
elif [[ (($weather_condition =~ 'overcast') || ($weather_condition =~ 'cloud')) ]]; then
|
||||||
echo '☁ '
|
echo '☁ '
|
||||||
elif [[ $weather_condition = 'NA' ]]; then
|
elif [[ $weather_condition = 'NA' ]]; then
|
||||||
echo ''
|
echo ''
|
||||||
else
|
else
|
||||||
echo '☀ '
|
echo '☀ '
|
||||||
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)"
|
||||||
else
|
else
|
||||||
echo "Location Unavailable"
|
echo "Location Unavailable"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
#run main driver program
|
#run main driver program
|
||||||
|
|
Loading…
Reference in a new issue