Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion bash/starcommand.sh
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,29 @@ _rkt_hw_info() {
os_str="$pretty $arch"
fi
fi
elif [[ "$os_type" == MINGW* || "$os_type" == MSYS* || "$os_type" == CYGWIN* ]]; then
# Git Bash / MSYS2 / Cygwin expose Linux-style /proc files
local procs_n=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null)
local cores_n=$(grep "cpu cores" /proc/cpuinfo 2>/dev/null | head -1 | cut -d ":" -f2 | tr -d " ")
local cpu_type=$(grep "model name" /proc/cpuinfo 2>/dev/null | head -1 | cut -d ":" -f2 | sed 's/^[[:space:]]*//')
cpu_str="$procs_n processors, $cores_n cores, $cpu_type"
local mem_kb=$(awk '/^MemTotal:/ {print $2}' /proc/meminfo 2>/dev/null | tr -d ' \n')
if [[ -n $mem_kb ]]; then
mem_str=$(awk -v k="$mem_kb" 'BEGIN{printf "%.0fGB", k/1024/1024}')
fi
# Windows product name lives in the registry; ProductName still says
# "Windows 10" on Windows 11, so correct it via the build number.
local reg_out
reg_out=$(reg query 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion' 2>/dev/null | tr -d '\r')
local win_name=$(echo "$reg_out" | awk -F'REG_SZ' '$1 ~ /^[[:space:]]*ProductName[[:space:]]/ {print $2; exit}' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')
local win_disp=$(echo "$reg_out" | awk -F'REG_SZ' '$1 ~ /^[[:space:]]*DisplayVersion[[:space:]]/ {print $2; exit}' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')
local win_build=$(echo "$reg_out" | awk -F'REG_SZ' '$1 ~ /^[[:space:]]*CurrentBuild[[:space:]]/ {print $2; exit}' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')
if [[ -n $win_name ]]; then
if [[ "$win_build" =~ ^[0-9]+$ ]] && (( win_build >= 22000 )); then
win_name="${win_name/Windows 10/Windows 11}"
fi
os_str="$win_name${win_disp:+ $win_disp} $(uname -m)"
fi
fi
printf '_rkt_os="%s"\n' "$os_str" > "$cache"
printf '_rkt_cpu="%s"\n' "$cpu_str" >> "$cache"
Expand Down Expand Up @@ -641,6 +664,17 @@ _rkt_net_info() {
elif [[ "$os_type" == "Linux" ]]; then
ip=$(ip -o addr show 2>/dev/null | awk '$3 == "inet" && $2 !~ /^(lo|docker|br-|veth|vmnet|vboxnet|utun|tun|tap|awdl|llw|anpi)/ && $4 !~ /^127\./ { split($4, a, "/"); print a[1]; exit }')
gw=$(ip route 2>/dev/null | awk '/^default/ {print $3; exit}')
elif [[ "$os_type" == MINGW* || "$os_type" == MSYS* || "$os_type" == CYGWIN* ]]; then
# The default-route row is pure numbers, so it survives any UI language.
# Columns: destination netmask gateway interface metric
local route_line
route_line=$(route print -4 0.0.0.0 2>/dev/null | tr -d '\r' \
| awk '$1 == "0.0.0.0" && $2 == "0.0.0.0" && $3 ~ /^[0-9]+\./ {
if (best == "" || $5 + 0 < best) { best = $5 + 0; g = $3; a = $4 }
} END { if (g != "") print g, a }')
gw=${route_line%% *}
ip=${route_line##* }
[[ "$gw" == "$ip" ]] && ip=""
fi
printf '_rkt_ip="%s"\n' "$ip" > "$cache"
printf '_rkt_gw="%s"\n' "$gw" >> "$cache"
Expand Down Expand Up @@ -1248,7 +1282,15 @@ show_date_info() {
cols=$(_rkt_cols)
prefix_len=19
available=$((cols - prefix_len - 2))
up_time=$(uptime | awk -F '(up |,)' '{print $2}' | sed 's/^ *//g')
if command -v uptime >/dev/null 2>&1; then
up_time=$(uptime | awk -F '(up |,)' '{print $2}' | sed 's/^ *//g')
elif [[ -r /proc/uptime ]]; then
# Git Bash has no uptime(1), but MSYS provides /proc/uptime
up_time=$(awk '{ s = int($1); d = int(s / 86400); h = int((s % 86400) / 3600); m = int((s % 3600) / 60)
if (d > 0) printf "%d day%s, %d hour%s", d, (d == 1 ? "" : "s"), h, (h == 1 ? "" : "s")
else if (h > 0) printf "%d hour%s, %d min%s", h, (h == 1 ? "" : "s"), m, (m == 1 ? "" : "s")
else printf "%d min%s", m, (m == 1 ? "" : "s") }' /proc/uptime)
fi
value="Today is $(date +%Y.%m.%d), we are up and running for $up_time."
if [[ ${#value} -gt $available ]]; then
echo -n "${value:0:$((available - 1))}…"
Expand Down