Created
March 22, 2017 21:57
-
-
Save budRich/63c1cfa5eaa21f0a40f7afb65cf3b2fd to your computer and use it in GitHub Desktop.
A small script that runs/activate or hide target window in i3
This file contains 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