Skip to content

Commit ff25428

Browse files
Merge pull request #191 from rbucker/master
Add OpenBSD (cpu, ram) and Fossil SCM
2 parents 038b1d4 + 59e4fe7 commit ff25428

File tree

4 files changed

+222
-7
lines changed

4 files changed

+222
-7
lines changed

scripts/cpu_info.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ get_percent()
2121
normalize_percent_len $percent
2222
;;
2323

24+
OpenBSD)
25+
cpuvalue=$(ps -A -o %cpu | awk -F. '{s+=$1} END {print s}')
26+
cpucores=$(sysctl -n hw.ncpuonline)
27+
cpuusage=$(( cpuvalue / cpucores ))
28+
percent="$cpuusage%"
29+
normalize_percent_len $percent
30+
;;
31+
2432
CYGWIN*|MINGW32*|MSYS*|MINGW*)
2533
# TODO - windows compatability
2634
;;
@@ -29,7 +37,7 @@ get_percent()
2937

3038
get_load() {
3139
case $(uname -s) in
32-
Linux | Darwin)
40+
Linux | Darwin | OpenBSD)
3341
loadavg=$(uptime | awk -F'[a-z]:' '{ print $2}' | sed 's/,//g')
3442
echo $loadavg
3543
;;

scripts/dracula.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ main()
2121
show_left_icon=$(get_tmux_option "@dracula-show-left-icon" smiley)
2222
show_left_icon_padding=$(get_tmux_option "@dracula-left-icon-padding" 1)
2323
show_military=$(get_tmux_option "@dracula-military-time" false)
24+
timezone=$(get_tmux_option "@dracula-set-timezone" "")
2425
show_timezone=$(get_tmux_option "@dracula-show-timezone" true)
2526
show_left_sep=$(get_tmux_option "@dracula-show-left-sep")
2627
show_right_sep=$(get_tmux_option "@dracula-show-right-sep")
@@ -71,12 +72,14 @@ main()
7172
fi
7273

7374
# Set timezone unless hidden by configuration
74-
case $show_timezone in
75-
false)
76-
timezone="";;
77-
true)
78-
timezone="#(date +%Z)";;
79-
esac
75+
if [[ -z "$timezone" ]]; then
76+
case $show_timezone in
77+
false)
78+
timezone="";;
79+
true)
80+
timezone="#(date +%Z)";;
81+
esac
82+
fi
8083

8184
case $show_flags in
8285
false)
@@ -143,6 +146,11 @@ main()
143146
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-cwd-colors" "dark_gray white")
144147
tmux set-option -g status-right-length 250
145148
script="#($current_dir/cwd.sh)"
149+
150+
elif [ $plugin = "fossil" ]; then
151+
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-fossil-colors" "green dark_gray")
152+
tmux set-option -g status-right-length 250
153+
script="#($current_dir/fossil.sh)"
146154

147155
elif [ $plugin = "git" ]; then
148156
IFS=' ' read -r -a colors <<< $(get_tmux_option "@dracula-git-colors" "green dark_gray")

scripts/fossil.sh

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/usr/bin/env bash
2+
3+
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
source $current_dir/utils.sh
5+
6+
IFS=' ' read -r -a hide_status <<< $(get_tmux_option "@dracula-fossil-disable-status" "false")
7+
IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-fossil-show-current-symbol" "")
8+
IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-fossil-show-diff-symbol" "!")
9+
IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-fossil-no-repo-message" "")
10+
IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-fossil-no-untracked-files" "false")
11+
IFS=' ' read -r -a show_remote_status <<< $(get_tmux_option "@dracula-fossil-show-remote-status" "false")
12+
13+
# Get added, modified, updated and deleted files from git status
14+
getChanges()
15+
{
16+
declare -i added=0;
17+
declare -i modified=0;
18+
declare -i updated=0;
19+
declare -i deleted=0;
20+
21+
for i in $(cd $path; fossil changes --differ|cut -f1 -d' ')
22+
23+
do
24+
case $i in
25+
'EXTRA')
26+
added+=1
27+
;;
28+
'EDITED')
29+
modified+=1
30+
;;
31+
'U')
32+
updated+=1
33+
;;
34+
'DELETED')
35+
deleted+=1
36+
;;
37+
38+
esac
39+
done
40+
41+
output=""
42+
[ $added -gt 0 ] && output+="${added}A"
43+
[ $modified -gt 0 ] && output+=" ${modified}M"
44+
[ $updated -gt 0 ] && output+=" ${updated}U"
45+
[ $deleted -gt 0 ] && output+=" ${deleted}D"
46+
47+
echo $output
48+
}
49+
50+
51+
# getting the #{pane_current_path} from dracula.sh is no longer possible
52+
getPaneDir()
53+
{
54+
nextone="false"
55+
for i in $(tmux list-panes -F "#{pane_active} #{pane_current_path}");
56+
do
57+
if [ "$nextone" == "true" ]; then
58+
echo $i
59+
return
60+
fi
61+
if [ "$i" == "1" ]; then
62+
nextone="true"
63+
fi
64+
done
65+
}
66+
67+
68+
# check if the current or diff symbol is empty to remove ugly padding
69+
checkEmptySymbol()
70+
{
71+
symbol=$1
72+
if [ "$symbol" == "" ]; then
73+
echo "true"
74+
else
75+
echo "false"
76+
fi
77+
}
78+
79+
# check to see if the current repo is not up to date with HEAD
80+
checkForChanges()
81+
{
82+
if [ "$(checkForFossilDir)" == "true" ]; then
83+
if [ "$(cd $path; fossil changes --differ)" != "" ]; then
84+
echo "true"
85+
else
86+
echo "false"
87+
fi
88+
else
89+
echo "false"
90+
fi
91+
}
92+
93+
# check if a git repo exists in the directory
94+
checkForFossilDir()
95+
{
96+
if [ -f ${path}/.fslckout ]; then
97+
echo "true"
98+
else
99+
echo "false"
100+
fi
101+
}
102+
103+
# return branch name if there is one
104+
getBranch()
105+
{
106+
if [ $(checkForFossilDir) == "true" ]; then
107+
echo $(cd $path; fossil branch current)
108+
else
109+
echo $no_repo_message
110+
fi
111+
}
112+
113+
getRemoteInfo()
114+
{
115+
base=$(cd $path; fossil branch current)
116+
remote=$(echo "$base" | cut -d" " -f1)
117+
out=""
118+
119+
if [ -n "$remote" ]; then
120+
out="...$remote"
121+
ahead=$(echo "$base" | grep -E -o 'ahead[ [:digit:]]+' | cut -d" " -f2)
122+
behind=$(echo "$base" | grep -E -o 'behind[ [:digit:]]+' | cut -d" " -f2)
123+
124+
[ -n "$ahead" ] && out+=" +$ahead"
125+
[ -n "$behind" ] && out+=" -$behind"
126+
fi
127+
128+
echo "$out"
129+
}
130+
131+
# return the final message for the status bar
132+
getMessage()
133+
{
134+
if [ $(checkForFossilDir) == "true" ]; then
135+
branch="$(getBranch)"
136+
output=""
137+
138+
if [ $(checkForChanges) == "true" ]; then
139+
140+
changes="$(getChanges)"
141+
142+
if [ "${hide_status}" == "false" ]; then
143+
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
144+
output=$(echo "${changes} $branch")
145+
else
146+
output=$(echo "$diff_symbol ${changes} $branch")
147+
fi
148+
else
149+
if [ $(checkEmptySymbol $diff_symbol) == "true" ]; then
150+
output=$(echo "$branch")
151+
else
152+
output=$(echo "$diff_symbol $branch")
153+
fi
154+
fi
155+
156+
else
157+
if [ $(checkEmptySymbol $current_symbol) == "true" ]; then
158+
output=$(echo "$branch")
159+
else
160+
output=$(echo "$current_symbol $branch")
161+
fi
162+
fi
163+
164+
[ "$show_remote_status" == "true" ] && output+=$(getRemoteInfo)
165+
echo "$output"
166+
else
167+
echo $no_repo_message
168+
fi
169+
}
170+
171+
main()
172+
{
173+
path=$(getPaneDir)
174+
getMessage
175+
}
176+
177+
#run main driver program
178+
main

scripts/ram_info.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ get_ratio()
4747
fi
4848
;;
4949

50+
OpenBSD)
51+
# vmstat -s | grep "pages managed" | sed -ne 's/^ *\([0-9]*\).*$/\1/p'
52+
# Looked at the code from neofetch
53+
hw_pagesize="$(pagesize)"
54+
used_mem=$(( (
55+
$(vmstat -s | grep "pages active$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
56+
$(vmstat -s | grep "pages inactive$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
57+
$(vmstat -s | grep "pages wired$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
58+
$(vmstat -s | grep "pages zeroed$" | sed -ne 's/^ *\([0-9]*\).*$/\1/p') +
59+
0) * hw_pagesize / 1024 / 1024 ))
60+
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
61+
#used_mem=$((total_mem - free_mem))
62+
total_mem=$(($total_mem/1024))
63+
if (( $used_mem < 1024 )); then
64+
echo $used_mem\M\B/$total_mem\G\B
65+
else
66+
memory=$(($used_mem/1024))
67+
echo $memory\G\B/$total_mem\G\B
68+
fi
69+
;;
70+
5071
CYGWIN*|MINGW32*|MSYS*|MINGW*)
5172
# TODO - windows compatability
5273
;;

0 commit comments

Comments
 (0)