简单的摇摆杆示例

简单的摇摆杆示例

我想要一个简单、平静的状态栏摇摆我将其与 Arch Linux 一起使用。

到目前为止我发现的配置使用一个单独的程序,例如导航栏或者i3状态。虽然它们看起来很棒,但我想保持简单并直接使用status_command提到的man sway-bar

最好,这个状态栏同样可以与i3这应该是可能的,因为 Sway 的目标是使其配置与 i3 兼容。

答案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 和 sway。

它完全用 C/C++ 编写,以使其尽可能轻量级,特别是避免像 Bash 脚本中那样每秒创建新进程。

libupower-glib它使用、libasound和等库libnm来检索电池、容量和网络信息,而不是使用upoweramixernmcli

对于背光、负载和内存信息,它直接从/sys/class/backlight/proc/loadavg和读取/proc/meminfo

在我的 x86-64 计算机上,它使用clang-11.

相关内容