
用 YAD 配合 Shell 实现更人性化的脚本编程
YAD, Yet Another Dialog 顾名思义,又一个 Dialog ,与 Dialog 通过 Ncurses 显示 TUI 不同, YAD 通过 Gtk 显示 GUI ,可玩性更高了,最近用 YAD 设计了几个菜单:
- 后面所有
--image 参数传进去的图标都来自包 papirus-icon-theme - YAD 说自己是 Zenity 的 Fork , Zenity 是 Dialog 的直线儿子,由 Gnome 开发且加上了 L I B A D W A I T A 显得十分的格格不入且难看, YAD 把这坨去掉了。
1. 电源管理
I3wm/Sway 有类似这种二级菜单:
1 2 3 4 5 6 7 8 9 10 11 12
| set $power_management (l) 锁定, (e) 注销, (s)⏾ 睡眠, (h) 休眠, (r) 重启, ( s) 关机 mode "$power_management" { bindsym l exec --no-startup-id $locker, mode "default" bindsym e exec --no-startup-id swaymsg exit, mode "default" bindsym s exec --no-startup-id $locker && systemctl suspend, mode "default" bindsym h exec --no-startup-id $locker && systemctl hibernate, mode "default" bindsym r exec --no-startup-id systemctl reboot, mode "default" bindsym Shift+s exec --no-startup-id systemctl poweroff, mode "default" bindsym Return mode "default" bindsym Escape mode "default" } bindsym $mod+p mode "$power_management"
|
但 Hyprland 没有这种设计(至少我没找到),遇到上面这种情况就很头疼,之前我都是通过 bemenu 手动执行 poweroff, reboot 之类的指令,但最近写了个脚本用 YAD 显示菜单:
1 2 3 4 5 6 7 8 9 10
| #!/usr/bin/sh
case "$(yad --title='Power Management' --text='Take care.' --text-align=center \ --image=org.xfce.powermanager --no-buttons --buttons-layout=spread --fixed \ --entry Poweroff Reboot Suspend)" in 'Poweroff') systemctl poweroff ;; 'Reboot') systemctl reboot ;; 'Suspend') systemctl suspend ;; *) echo see you again. ;; esac
|
效果:

焦点放在这个窗口上,键盘上下箭头选择关机、重启、睡眠,回车键执行, Esc 键退出。
2. 开机询问是否启动 Waydroid
因为之前把碧蓝档案国际服搬到我的笔记本上了,所以每次开机想要被询问是否启动 原神 Waydroid ,否则写死每次开机启动或者每次开机手动启动都挺麻烦的:
1 2 3 4 5 6
| if yad --title=Waydroid --text='start waydroid session?' --text-align=center \ --image=waydroid --buttons-layout=spread --fixed --button=yad-yes:0 \ --button=yad-no:1 ; then notify-send -i '/usr/share/icons/hicolor/512x512/apps/waydroid.png' Waydroid 'Session starting...' hyprctl dispatch exec -- waydroid session start fi
|
这里传给 yad 的图标是来自 waydroid 包的,但不知道为啥直接传 waydroid 给 notify-send 的话 notify-send 不能找到这个图标,所以给 notify-send 传了绝对路径
效果:

放进 Hyprland 配置里,前面加上 sleep 5 ,开机 5 秒钟后执行这个脚本(避免奇怪的显示问题):
1 2 3
|
exec-once = [workspace 1 silent] ~/.config/hypr/setup
|
3. 性能管理
用 x86_energy_perf_policy 可以调整 Intel 的 X86 架构 CPU 的性能模式,但手动打这么一长串实在累人,写了个脚本,绑个快捷键:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #!/usr/bin/sh
case "$(yad --title='Performance Management' --text='Relax.' \ --text-align=center --image=power-profile-performance-symbolic \ --buttons-layout=edge --no-buttons --fixed --width=220 --height=220 --list \ --separator='' --column='Energy Performance Policy' --no-headers \ 'best performance' 'better performance' 'balanced' 'better battery' \ 'battery saver')" in 'best performance') policy=performance ;; 'better performance') policy=balance-performance ;; 'balanced') policy=default ;; 'better battery') policy=balance-power ;; 'battery saver') policy=power ;; *) echo see you again.; exit ;; esac
sudo x86_energy_perf_policy ${policy}
|
效果:

需要注意我设置了 wheel 组用户 sudo 不需要密码(我在 wheel 组里)
键盘上下箭头可以选择方案,回车确认方案;或者鼠标双击确认方案。
废话
Kitty, CLI 的能力是有极限的。我从短暂的人生中学到一件事情……越是玩弄命令行,就越会发现 CLI 的能力是有限的……除非超越 CLI 。我要去搞 GUI 辣, Kitty!
