bash:在事件窗口标题中显示简单的正弦动画

标签 bash ubuntu wmctrl

我正在使用带有基本 Greybird 主题的 Xubuntu 18.04.2 LTS。我的文件管理器是 Nemo (3.8.6),窗口装饰管理器是 xfwm4。

多亏了这个 bash script1(下面的代码和源代码 https://forum.ubuntu-fr.org/viewtopic.php?pid=22123363#p22123363),我可以在控制台窗口上显示一个简单的正弦曲线。此动画还会在调整窗口大小时自动适应:

[脚本1]

#!/bin/bash

motif="⠁⠂⠄⡀⢀⠠⠐⠈ "
tempo=0.04

recalcule() {
    columns=$( tput cols )
    repet=$(( columns / longMotif ))
    reste=$(( columns % longMotif ))
}

affPointApoint() {
    longChaine=${#1}
    for (( i=0; i<$longChaine; i++ )); do
        printf "${1:$i:1}"
        trap 'recalcule' SIGWINCH
    sleep $tempo
    done
}

longMotif="${#motif}"

while :; do
    recalcule
    tput clear   
    for (( x=0; x<$repet; x++ )); do
        affPointApoint "$motif"
    done
    affPointApoint "${motif:0:$reste}"
done

我现在想在控制台以外的窗口上显示这个简单的正弦曲线。甚至可以在事件窗口的装饰中做到这一点,例如在窗口标题旁边?

我的第一个想法是在下面的 script2 中使用 wmctrl,但我没能做到。你觉得你能帮上忙吗?谢谢!

[脚本2]
#!/bin/bash
while true
do
  wmctrl -r :ACTIVE: -N "$(awk -F' \\|\\|' '{print $1}' <<<  $(xdotool  getwindowfocus getwindowname)) || $(sinusoid variable here)"
    sleep .1
done

感谢您的时间和帮助!

最佳答案

以下实际有效(在终端中启动,将鼠标悬停在其他窗口上);我希望这是你的想法:

#!/bin/bash

motif="⠁⠂⠄⡀⢀⠠⠐⠈ "
tempo=0.04
len=${#motif}

i=0
while true
do
    left=${motif:0:i}
    right=${motif:i:len}

    wmctrl -r :ACTIVE: -N "${right}${left}"

    i=$((i+1))
    [ $i -eq $len ] && i=0

    sleep 0.1
done

关于bash:在事件窗口标题中显示简单的正弦动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57047447/

相关文章:

linux - 我正在尝试在 bash 中创建多行变量但面临错误 "unexpected EOF while looking for matching ` )' "

bash - 处理由反引号命令产生的带有空格的路径

session - Ubuntu 13.10 打破 NoMachine

apache - 为什么我在使用此 Perl CGI 脚本时收到 "permission denied"错误?

bash - 如何通过脚本或 Shell 命令将焦点切换到 Gnome 终端选项卡

linux - wmctrl:移动全屏窗口

Bash:如何在使用微调器时获取命令的退出代码?

linux - 如何批处理 sed 文件和重定向结果

php - Apache2,线程。 fatal error 。 pthreads 不支持 apache2handler SAPI

linux - 如何通过 'wmctl' 和 'ps' 获得 X 应用程序的完整命令?