优化代码

This commit is contained in:
bin456789
2024-03-31 00:47:13 +08:00
parent f2e1cb8b89
commit ffa7b63d93
7 changed files with 42 additions and 35 deletions

11
ttys.sh
View File

@@ -1,16 +1,14 @@
#!/bin/sh
prefix=$1
is_in_windows() {
[ "$(uname -o)" = Cygwin ] || [ "$(uname -o)" = Msys ]
}
# 不要在 windows 上使用,因为不准确
# 在原系统上使用,也可能不准确?例如安装了 cloud 内核的甲骨文?
# 最后一个 tty 是主 tty显示的信息最全
is_first=true
for tty in ttyS0 ttyAMA0 tty0; do
# hytron 有ttyS0 但无法写入
# cygwin 没有 tty0所以 windows 下 tty0 免检
if { [ "$tty" = tty0 ] && is_in_windows; } || stty -g -F "/dev/$tty" >/dev/null 2>&1; then
if stty -g -F "/dev/$tty" >/dev/null 2>&1; then
if $is_first; then
is_first=false
else
@@ -19,7 +17,8 @@ for tty in ttyS0 ttyAMA0 tty0; do
printf "%s" "$prefix$tty"
if [ "$prefix" = "console=" ] && [ "$tty" = ttyS0 ]; then
if [ "$prefix" = "console=" ] &&
{ [ "$tty" = ttyS0 ] || [ "$tty" = ttyAMA0 ]; }; then
printf ",115200n8"
fi
fi