Merge pull request #191 from rbucker/master

Add OpenBSD (cpu, ram) and Fossil SCM
This commit is contained in:
Ethan Edwards 2023-09-25 13:31:12 -04:00 committed by GitHub
commit ff25428868
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 222 additions and 7 deletions

View file

@ -21,6 +21,14 @@ get_percent()
normalize_percent_len $percent normalize_percent_len $percent
;; ;;
OpenBSD)
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
cpucores=$(sysctl -n hw.ncpuonline)
cpuusage=$(( cpuvalue / cpucores ))
percent="$cpuusage%"
normalize_percent_len $percent
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*) CYGWIN*|MINGW32*|MSYS*|MINGW*)
# TODO - windows compatability # TODO - windows compatability
;; ;;
@ -29,7 +37,7 @@ get_percent()
get_load() { get_load() {
case $(uname -s) in case $(uname -s) in
Linux | Darwin) Linux | Darwin | OpenBSD)
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
;; ;;

View file

@ -21,6 +21,7 @@ main()
show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley) show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley)
show_left_icon_padding=$(get_tmux_option "@dracula-left-icon-padding" 1) show_left_icon_padding=$(get_tmux_option "@dracula-left-icon-padding" 1)
show_military=$(get_tmux_option "@dracula-military-time" false) show_military=$(get_tmux_option "@dracula-military-time" false)
timezone=$(get_tmux_option "@dracula-set-timezone" "")
show_timezone=$(get_tmux_option "@dracula-show-timezone" true) show_timezone=$(get_tmux_option "@dracula-show-timezone" true)
show_left_sep=$(get_tmux_option "@dracula-show-left-sep") show_left_sep=$(get_tmux_option "@dracula-show-left-sep")
show_right_sep=$(get_tmux_option "@dracula-show-right-sep") show_right_sep=$(get_tmux_option "@dracula-show-right-sep")
@ -71,12 +72,14 @@ main()
fi fi
# Set timezone unless hidden by configuration # Set timezone unless hidden by configuration
if [[ -z "$timezone" ]]; then
case $show_timezone in case $show_timezone in
false) false)
timezone="";; timezone="";;
true) true)
timezone="#(date +%Z)";; timezone="#(date +%Z)";;
esac esac
fi
case $show_flags in case $show_flags in
false) false)
@ -144,6 +147,11 @@ main()
tmux set-option -g status-right-length 250 tmux set-option -g status-right-length 250
script="#($current_dir/cwd.sh)" script="#($current_dir/cwd.sh)"
elif [ $plugin = "fossil" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-fossil-colors" "green dark_gray")
tmux set-option -g status-right-length 250
script="#($current_dir/fossil.sh)"
elif [ $plugin = "git" ]; then elif [ $plugin = "git" ]; then
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray") IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray")
tmux set-option -g status-right-length 250 tmux set-option -g status-right-length 250

178
scripts/fossil.sh Executable file
View file

@ -0,0 +1,178 @@
#!/usr/bin/env bash
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
IFS=' ' read -r -a hide_status <<< $(get_tmux_option "@dracula-fossil-disable-status" "false")
IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-fossil-show-current-symbol" "✓")
IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-fossil-show-diff-symbol" "!")
IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-fossil-no-repo-message" "")
IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-fossil-no-untracked-files" "false")
IFS=' ' read -r -a show_remote_status <<< $(get_tmux_option "@dracula-fossil-show-remote-status" "false")
# Get added, modified, updated and deleted files from git status
getChanges()
{
declare -i added=0;
declare -i modified=0;
declare -i updated=0;
declare -i deleted=0;
for i in $(cd $path; fossil changes --differ|cut -f1 -d' ')
do
case $i in
'EXTRA')
added+=1
;;
'EDITED')
modified+=1
;;
'U')
updated+=1
;;
'DELETED')
deleted+=1
;;
esac
done
output=""
[ $added -gt 0 ] && output+="${added}A"
[ $modified -gt 0 ] && output+=" ${modified}M"
[ $updated -gt 0 ] && output+=" ${updated}U"
[ $deleted -gt 0 ] && output+=" ${deleted}D"
echo $output
}
# getting the #{pane_current_path} from dracula.sh is no longer possible
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
}
# check if the current or diff symbol is empty to remove ugly padding
checkEmptySymbol()
{
symbol=$1
if [ "$symbol" == "" ]; then
echo "true"
else
echo "false"
fi
}
# check to see if the current repo is not up to date with HEAD
checkForChanges()
{
if [ "$(checkForFossilDir)" == "true" ]; then
if [ "$(cd $path; fossil changes --differ)" != "" ]; then
echo "true"
else
echo "false"
fi
else
echo "false"
fi
}
# check if a git repo exists in the directory
checkForFossilDir()
{
if [ -f ${path}/.fslckout ]; then
echo "true"
else
echo "false"
fi
}
# return branch name if there is one
getBranch()
{
if [ $(checkForFossilDir) == "true" ]; then
echo $(cd $path; fossil branch current)
else
echo $no_repo_message
fi
}
getRemoteInfo()
{
base=$(cd $path; fossil branch current)
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 [ $(checkForFossilDir) == "true" ]; then
branch="$(getBranch)"
output=""
if [ $(checkForChanges) == "true" ]; then
changes="$(getChanges)"
if [ "${hide_status}" == "false" ]; then
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
output=$(echo "${changes} $branch")
else
output=$(echo "$diff_symbol ${changes} $branch")
fi
else
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
output=$(echo "$branch")
else
output=$(echo "$diff_symbol $branch")
fi
fi
else
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
output=$(echo "$branch")
else
output=$(echo "$current_symbol $branch")
fi
fi
[ "$show_remote_status" == "true" ] && output+=$(getRemoteInfo)
echo "$output"
else
echo $no_repo_message
fi
}
main()
{
path=$(getPaneDir)
getMessage
}
#run main driver program
main

View file

@ -47,6 +47,27 @@ get_ratio()
fi fi
;; ;;
OpenBSD)
# vmstat -s | grep "pages managed" | sed -ne 's/^ *\([0-9]*\).*$/\1/p'
# Looked at the code from neofetch
hw_pagesize="$(pagesize)"
used_mem=$(( (
$(vmstat -s | grep "pages active$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
$(vmstat -s | grep "pages inactive$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
$(vmstat -s | grep "pages wired$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
$(vmstat -s | grep "pages zeroed$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
0) * hw_pagesize / 1024 / 1024 ))
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
#used_mem=$((total_mem - free_mem))
total_mem=$(($total_mem/1024))
if (( $used_mem < 1024 )); then
echo $used_mem\M\B/$total_mem\G\B
else
memory=$(($used_mem/1024))
echo $memory\G\B/$total_mem\G\B
fi
;;
CYGWIN*|MINGW32*|MSYS*|MINGW*) CYGWIN*|MINGW32*|MSYS*|MINGW*)
# TODO - windows compatability # TODO - windows compatability
;; ;;