sh 从https://faq.i3wm.org/question/2172/how-do-i-find-the-criteria-for-use-with-i3-config-command轻松查找

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 从https://faq.i3wm.org/question/2172/how-do-i-find-the-criteria-for-use-with-i3-config-command轻松查找相关的知识,希望对你有一定的参考价值。

#!/bin/sh

# i3-get-window-criteria - Get criteria for use with i3 config commands

# To use, run this script, then click on a window.
# Output is in the format: [<name>=<value> <name>=<value> ...]

# Known problem: when WM_NAME is used as fallback for the 'title="<string>"' criterion,
# quotes in "<string>" are not escaped properly. This is a problem with the output of `xprop`,
# reported upstream: https://bugs.freedesktop.org/show_bug.cgi?id=66807

PROGNAME=`basename "$0"`

# Check for xwininfo and xprop
for cmd in xwininfo xprop; do
    if ! which $cmd > /dev/null 2>&1; then
        echo "$PROGNAME: $cmd: command not found" >&2
        exit 1
    fi
done

match_int='[0-9][0-9]*'
match_string='".*"'
match_qstring='"[^"\\]*(\\.[^"\\]*)*"' # NOTE: Adds 1 backreference

{
    # Run xwininfo, get window id
    window_id=`xwininfo -int | sed -nre "s/^xwininfo: Window id: ($match_int) .*$/\1/p"`
    echo "id=$window_id"

    # Run xprop, transform its output into i3 criteria. Handle fallback to
    # WM_NAME when _NET_WM_NAME isn't set
    xprop -id $window_id |
        sed -nr \
            -e "s/^WM_CLASS\(STRING\) = ($match_qstring), ($match_qstring)$/instance=\1\nclass=\3/p" \
            -e "s/^WM_WINDOW_ROLE\(STRING\) = ($match_qstring)$/window_role=\1/p" \
            -e "/^WM_NAME\(STRING\) = ($match_string)$/{s//title=\1/; h}" \
            -e "/^_NET_WM_NAME\(UTF8_STRING\) = ($match_qstring)$/{s//title=\1/; h}" \
            -e '${g; p}'
} | sort | tr "\n" " " | sed -r 's/^(.*) $/[\1]\n/'

以上是关于sh 从https://faq.i3wm.org/question/2172/how-do-i-find-the-criteria-for-use-with-i3-config-command轻松查找的主要内容,如果未能解决你的问题,请参考以下文章

sh 用于从文件中提取电子邮件的命令行实用程序。用法sh extractemail.sh yourfile.csv

如何用SH脚本实现从一个文件中取出指定的行?

sh SH脚本截图并上传到Imgur(如果使用Snagit则从剪贴板获取)

“从jsp页面代码错误运行sh文件”

无法从 sh 文件向 hql 传递参数

如何使用 SH 从文本文件创建列表?