From 0810927136ec258ef9ea79b894bffa30b63cfe65 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 10 Feb 2023 17:24:42 +0000 Subject: [PATCH 1/6] add fossil --- scripts/dracula.sh | 6 ++ scripts/fossil.sh | 179 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100755 scripts/fossil.sh diff --git a/scripts/dracula.sh b/scripts/dracula.sh index 3e1bc1b..eb748e7 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -128,6 +128,12 @@ main() for plugin in "${plugins[@]}"; do + if [ $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)" + fi + if [ $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 diff --git a/scripts/fossil.sh b/scripts/fossil.sh new file mode 100755 index 0000000..5646465 --- /dev/null +++ b/scripts/fossil.sh @@ -0,0 +1,179 @@ +#!/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) + + 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() +{ + [ $no_untracked_files == "false" ] && no_untracked="" || no_untracked="-uno" + if [ "$(checkForFossilDir)" == "true" ]; then + if [ "$(fossil changes --differ --extra)" != "" ]; 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 From 5cd6616479bb9af5d836a6f995120594800049df Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 10 Feb 2023 17:25:03 +0000 Subject: [PATCH 2/6] add OpenBSD --- scripts/cpu_info.sh | 10 +++++++++- scripts/ram_info.sh | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 41b49c1..9a33900 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -21,6 +21,14 @@ get_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*) # TODO - windows compatability ;; @@ -29,7 +37,7 @@ get_percent() get_load() { case $(uname -s) in - Linux | Darwin) + Linux | Darwin | OpenBSD) loadavg=$(uptime | awk -F'[a-z]:' '{ print $2}' | sed 's/,//g') echo $loadavg ;; diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 97d61b6..412f0b8 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -56,6 +56,22 @@ get_percent() fi ;; + OpenBSD) + # vmstat -s | grep "pages managed" | sed -ne 's/^ *\([0-9]*\).*$/\1/p' + # Looked at the code from neofetch + hw_pagesize="$(pagesize)" + free_mem=$(($(vmstat -s | grep "pages free$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') * 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*) # TODO - windows compatability ;; From 594812ee509a46d1be0ecbdff0bd0808930cb7a5 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 10 Feb 2023 18:01:00 +0000 Subject: [PATCH 3/6] get the change only --- scripts/fossil.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/fossil.sh b/scripts/fossil.sh index 5646465..0bc62f4 100755 --- a/scripts/fossil.sh +++ b/scripts/fossil.sh @@ -18,7 +18,7 @@ getChanges() declare -i updated=0; declare -i deleted=0; -for i in $(cd $path; fossil changes --differ) +for i in $(cd $path; fossil changes --differ|cut -f1 -d' ') do case $i in From 422bf2babd81ac1a8261066bfb00205d5debefbe Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 10 Feb 2023 18:03:23 +0000 Subject: [PATCH 4/6] missed on path change --- scripts/fossil.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/fossil.sh b/scripts/fossil.sh index 0bc62f4..a57a294 100755 --- a/scripts/fossil.sh +++ b/scripts/fossil.sh @@ -79,9 +79,8 @@ checkEmptySymbol() # check to see if the current repo is not up to date with HEAD checkForChanges() { - [ $no_untracked_files == "false" ] && no_untracked="" || no_untracked="-uno" if [ "$(checkForFossilDir)" == "true" ]; then - if [ "$(fossil changes --differ --extra)" != "" ]; then + if [ "$(cd $path; fossil changes --differ)" != "" ]; then echo "true" else echo "false" From 129c602c86ceec14c4b687b9ee65a5d8138c0a0e Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 14 Feb 2023 17:56:36 +0000 Subject: [PATCH 5/6] fix he ram value --- scripts/ram_info.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 412f0b8..d88b3bf 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -60,9 +60,14 @@ get_percent() # vmstat -s | grep "pages managed" | sed -ne 's/^ *\([0-9]*\).*$/\1/p' # Looked at the code from neofetch hw_pagesize="$(pagesize)" - free_mem=$(($(vmstat -s | grep "pages free$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') * hw_pagesize / 1024 / 1024 )) + 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)) + #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 From 1a90a5ae6afceccc3f20557a5305fc44cd3f6153 Mon Sep 17 00:00:00 2001 From: richard Date: Tue, 14 Feb 2023 20:41:46 +0000 Subject: [PATCH 6/6] set Timezone different from current --- scripts/dracula.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/scripts/dracula.sh b/scripts/dracula.sh index eb748e7..2f40b54 100755 --- a/scripts/dracula.sh +++ b/scripts/dracula.sh @@ -18,6 +18,7 @@ main() show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley) show_left_icon_padding=$(get_tmux_option "@dracula-left-icon-padding" 1) 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_left_sep=$(get_tmux_option "@dracula-show-left-sep" ) show_right_sep=$(get_tmux_option "@dracula-show-right-sep" ) @@ -71,12 +72,14 @@ main() fi # Set timezone unless hidden by configuration - case $show_timezone in - false) - timezone="";; - true) - timezone="#(date +%Z)";; - esac + if [[ -z "$timezone" ]]; then + case $show_timezone in + false) + timezone="";; + true) + timezone="#(date +%Z)";; + esac + fi case $show_flags in false) @@ -200,13 +203,13 @@ main() if [ $plugin = "time" ]; then 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 - script="%a %d/%m %R ${timezone} " + script="#(TZ=${timezone} date +'%%a %%d/%%m %%R') ${timezone} " elif $show_military; then # only military time - script="%a %m/%d %R ${timezone} " + script="#(TZ=${timezone} date +'%%a %%m/%%d %%R') ${timezone} " elif $show_day_month; then # only dd/mm - script="%a %d/%m %I:%M %p ${timezone} " + script="#(TZ=${timezone} date +'%%a %%d/%%m %%I:%%M %%p') ${timezone} " else - script="%a %m/%d %I:%M %p ${timezone} " + script="#(TZ=${timezone} date +'%%a %%m/%%d %%I:%%M %%p') ${timezone} " fi fi