-
-
Save QiangF/51ff5d88547f66351ca762756e53b47a to your computer and use it in GitHub Desktop.
A small script that runs/activate or hide target window in i3
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 | |
| # | |
| # i3ass-drr -n "name" -c "class" -i "instance/classname" -m "mark" -r "command" | |
| while getopts c:n:r:i:m: option | |
| do | |
| case "${option}" | |
| in | |
| c) aSrch=("${aSrch[@]}" --class "${OPTARG}");; | |
| n) aSrch=("${aSrch[@]}" --name "${OPTARG}");; | |
| i) aSrch=("${aSrch[@]}" --classname "${OPTARG}");; | |
| r) RUN=${OPTARG};; | |
| m) MARK=${OPTARG};; | |
| esac | |
| done | |
| s1=$(echo "${aSrch[0]}") | |
| s2=$(echo "${aSrch[1]}") | |
| s3=$(echo "${aSrch[2]}") | |
| s4=$(echo "${aSrch[3]}") | |
| if [[ ${#aSrch[@]} == 4 ]]; then | |
| wExist=($(comm -12 <(xdotool search "$s1" "$s2" | sort) <(xdotool search "$s3" "$s4" | sort))) | |
| wVisible=($(comm -12 <(xdotool search --onlyvisible "$s1" "$s2" | sort) <(xdotool search --onlyvisible "$s3" "$s4" | sort))) | |
| else | |
| wExist=($(comm -12 <(xdotool search "$s1" "$s2" | sort) <(xdotool search "$s1" "$s2" | sort))) | |
| wVisible=($(comm -12 <(xdotool search --onlyvisible "$s1" "$s2" | sort) <(xdotool search --onlyvisible "$s1" "$s2" | sort))) | |
| fi | |
| nEx=$(( ${#wExist[@]}-1 )) | |
| nVi=$(( ${#wEVisible[@]}-1 )) | |
| if [[ -z ${wExist} ]]; then | |
| ${RUN} & | |
| if [ $MARK ]; then | |
| wExist=($(comm -12 <(xdotool search --sync "$s1" "$s2" | sort) <(xdotool search --sync "$s1" "$s2" | sort))) | |
| nEx=$(( ${#wExist[@]}-1 )) | |
| i3-msg [id=${wExist[$nEx]}] floating disable, move window to mark "$MARK", focus | |
| fi | |
| elif [[ "${wVisible[$nVi]}" = $(xdotool getactivewindow) ]]; then | |
| xdotool windowunmap "${wExist[$nEx]}" | |
| else | |
| xdotool windowmap ${wExist[$nEx]} | |
| xdotool windowactivate ${wExist[$nEx]} | |
| i3-msg [id=${wExist[$nEx]}] focus | |
| fi | |
| # The end is here ----------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment