Created
January 9, 2025 01:25
-
-
Save garywill/0fcc6736a524fdf6993b77ab2fc90ba8 to your computer and use it in GitHub Desktop.
Find correct tty (X11) and user, then force restart KWin (KDE bug workaround). Need '0newline' script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # 获取当前用户ID | |
| CURRENT_USER_ID=$(id -u) | |
| echo "CURRENT_USER_ID=$CURRENT_USER_ID" | |
| # 遍历/proc,找到属于当前用户,且 exec 指向 /usr/bin/plasmashell 的进程 | |
| for dir in /proc/*; do | |
| # echo "checking dir = $dir" | |
| if [ -d $dir ] && [[ $dir =~ /proc/[0-9]* ]]; then | |
| if [ -f $dir/exe ] && [ -f $dir/environ ] && [ -f $dir/status ]; then | |
| PROC_USER_ID=$(cat $dir/status | grep Uid | awk '{print $2}') | |
| if [ "$PROC_USER_ID" -eq "$CURRENT_USER_ID" ]; then | |
| PROC_EXE=$(readlink -f $dir/exe) | |
| if [ "$PROC_EXE" == "/usr/bin/plasmashell" ]; then | |
| echo "Found process in $dir" | |
| PLASMASHELL_ENV="$(0newline $dir/environ 2>/dev/null)" | |
| IFS=$'\n' read -rd '' -a envS <<<"$PLASMASHELL_ENV" | |
| echo "There are ${#envS[@]} environment variables found" | |
| # ENV_CMD="env -i " | |
| # | |
| # # 遍历数组 | |
| # for ((i=0; i<${#envS[@]}; i++)) | |
| # do | |
| # # 对于第一个元素之后的元素,添加"env "前缀 | |
| # if [ $i -gt 0 ] | |
| # then | |
| # ENV_CMD+="env " | |
| # fi | |
| # # 添加数组元素 | |
| # ENV_CMD+="${envS[$i]} " | |
| # done | |
| # | |
| # # 打印变量 | |
| # echo "$ENV_CMD" | |
| for ((i=0; i<${#envS[@]}; i++)); do | |
| FSTR="${envS[$i]}" | |
| # 找到第一个等号左边的内容 | |
| NAME=${FSTR%%=*} | |
| # 去掉第一个等号及等号左边的内容 | |
| VAL=${FSTR#*=} | |
| # echo "Name: $NAME" | |
| # echo "Value: $VAL" | |
| declare -x "${NAME}=${VAL}" | |
| done | |
| # echo "PROC_EXE=$PROC_EXE" | |
| # echo "proc dir = $dir" | |
| # 0newline $dir/environ 2>/dev/null | |
| /usr/bin/kwin_x11 --replace | |
| break | |
| fi | |
| fi | |
| fi | |
| fi | |
| done | |
| # 使用plasmashell的环境变量运行 "kwin_x11 --replace" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment