Created
November 6, 2018 19:44
-
-
Save jvalrog/fcf7744f6997d4463577a5a5ab91c001 to your computer and use it in GitHub Desktop.
An i3-like scratchpad using xdotool
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/sh | |
# | |
# SCRATCHPAD | |
# | |
# An i3-like scratchpad using xdotool. | |
# | |
# Example: | |
# ~$ scratchpad htop-pad urxvt -T htop-pad -e htop | |
# | |
# Explanation: | |
# * If there is no window with title "htop-pad", a new | |
# urxvt terminal will be run with "htop-pad" as title and | |
# executing an htop instance. | |
# | |
# * If the window already exists (visible or not), its | |
# visibility will be toggled. | |
# | |
if [ $# -lt 2 ]; then | |
echo "usage: $(basename $0) <window title> <program>" >&2 | |
exit 1 | |
fi | |
title="$1"; shift; program="$@" | |
if ! wid=$(xdotool search --name "^$title$"); then | |
$program & | |
elif echo $wid | grep -q " "; then | |
echo "error: several windows matched." >&2 | |
exit 1 | |
else | |
if xdotool search --onlyvisible --name "^$title$" 2>&1 > /dev/null; then | |
xdotool windowunmap $wid | |
else | |
xdotool set_desktop_for_window $wid $(xdotool get_desktop) \ | |
windowmap --sync $wid windowfocus $wid | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment