답변1
이 스크립트가 있습니다 ~/.config/sway/status.sh
.
# The Sway configuration file in ~/.config/sway/config calls this script.
# You should see changes to the status bar after saving this script.
# If not, do "killall swaybar" and $mod+Shift+c to reload the configuration.
# Produces "21 days", for example
uptime_formatted=$(uptime | cut -d ',' -f1 | cut -d ' ' -f4,5)
# The abbreviated weekday (e.g., "Sat"), followed by the ISO-formatted date
# like 2018-10-06 and the time (e.g., 14:01)
date_formatted=$(date "+%a %F %H:%M")
# Get the Linux version but remove the "-1-ARCH" part
linux_version=$(uname -r | cut -d '-' -f1)
# Returns the battery status: "Full", "Discharging", or "Charging".
battery_status=$(cat /sys/class/power_supply/BAT0/status)
# Emojis and characters for the status bar
#
답변2
이것은 내 현재 상태 표시줄입니다.
오디오가 음소거된 경우:
status.sh
무엇이라고 불리는가 ~/.config/sway/config
:
# The Sway configuration file in ~/.config/sway/config calls this script.
# You should see changes to the status bar after saving this script.
# If not, do "killall swaybar" and $mod+Shift+c to reload the configuration.
# The abbreviated weekday (e.g., "Sat"), followed by the ISO-formatted date
# like 2018-10-06 and the time (e.g., 14:01). Check `man date` on how to format
# time and date.
date_formatted=$(date "+%a %F %H:%M")
# "upower --enumerate | grep 'BAT'" gets the battery name (e.g.,
# "/org/freedesktop/UPower/devices/battery_BAT0") from all power devices.
# "upower --show-info" prints battery information from which we get
# the state (such as "charging" or "fully-charged") and the battery's
# charge percentage. With awk, we cut away the column containing
# identifiers. i3 and sway convert the newline between battery state and
# the charge percentage automatically to a space, producing a result like
# "charging 59%" or "fully-charged 100%".
battery_info=$(upower --show-info $(upower --enumerate |\
grep 'BAT') |\
egrep "state|percentage" |\
awk '{print $2}')
# "amixer -M" gets the mapped volume for evaluating the percentage which
# is more natural to the human ear according to "man amixer".
# Column number 4 contains the current volume percentage in brackets, e.g.,
# "[36%]". Column number 6 is "[off]" or "[on]" depending on whether sound
# is muted or not.
# "tr -d []" removes brackets around the volume.
# Adapted from https://bbs.archlinux.org/viewtopic.php?id=89648
audio_volume=$(amixer -M get Master |\
awk '/Mono.+/ {print $6=="[off]" ?\
$4"
답변3
나는 bash를 좋아하지만 이를 위해 Python 스크립트를 사용합니다. Python의 표준 라이브러리에는 이런 종류의 작업을 위한 많은 유틸리티가 있는 것 같습니다.
from datetime import datetime
from psutil import disk_usage, sensors_battery
from psutil._common import bytes2human
from socket import gethostname, gethostbyname
from subprocess import check_output
from sys import stdout
from time import sleep
def write(data):
stdout.write('%s\n' % data)
stdout.flush()
def refresh():
disk = bytes2human(disk_usage('/').free)
ip = gethostbyname(gethostname())
try:
ssid = check_output("iwgetid -r", shell=True).strip().decode("utf-8")
ssid = "(%s)" % ssid
except Exception:
ssid = "None"
battery = int(sensors_battery().percent)
status = "Charging" if sensors_battery().power_plugged else "Discharging"
date = datetime.now().strftime('%h %d %A %H:%M')
format = "Space: %s | Internet: %s %s | Battery: %s%% %s | Date: %s"
write(format % (disk, ip, ssid, battery, status, date))
while True:
refresh()
sleep(1)
다음은 바의 스크린샷입니다.
답변4
가벼우면서도 기능이 풍부한 상태 표시줄을 작성했습니다.스윙 상태i3와 스웨이용입니다.
특히 Bash 스크립트처럼 매 순간 새로운 프로세스가 생성되는 것을 피하기 위해 가능한 한 가볍게 만들기 위해 전적으로 C/C++로 작성되었습니다.
libupower-glib
또는 를 사용 하는 대신 , libasound
및 라이브러리를 사용하여 배터리, 용량 및 네트워크 정보를 검색합니다 .libnm
upower
amixer
nmcli
백라이트, 로드 및 메모리 정보는 , /sys/class/backlight
및 에서 직접 /proc/loadavg
읽습니다 /proc/meminfo
.
내 x86-64 시스템에서는 clang-11
.