-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm-workspace-get-next-empty
executable file
·55 lines (44 loc) · 1.62 KB
/
wm-workspace-get-next-empty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env bash
# SCRIPT_DIR is set to the directory where this script is localed. It it was
# run by a symlink, it will be resolved to the directory of the target script
# (that is, the actual script directory).
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [[ -L "${BASH_SOURCE[0]}" ]]; then
SCRIPT_DIR="$(readlink "${BASH_SOURCE[0]}")"
SCRIPT_DIR="$( cd "$( dirname "${SCRIPT_DIR}" )" >/dev/null 2>&1 && pwd )"
fi
# get platform info, populates 'platform' and 'apple_silicon' variables
source "${SCRIPT_DIR}"/lib/platform.sh
# wm-workspace-get-next-empty
# - Print number of the first empty workspace to the right of the current one
# (or the current workspace if it is empty).
shopt -s xpg_echo
bold="\033[1m"
green="\033[32m"
reset="\033[0m"
# print usage message on -h/--help
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
echo "${bold}Usage:${reset} ${green}wm-workspace-get-next-empty${reset}"
echo " - Print number of the first empty workspace to the right of the"
echo " current one (or the current workspace if it is empty)."
exit 0
fi
# get number of first empty workspace to the right of the current one
current_workspace=$(wm-workspace-get-current)
next_workspace=""
i=$current_workspace
while true; do
# if workspace doesn't exist, we found it
if ! wm-workspace-exists "$i" > /dev/null; then
next_workspace="${i}"
break
fi
# if workspace is empty, we found it
if wm-workspace-is-empty "$i" > /dev/null; then
next_workspace="${i}"
break
fi
# else, increment current workspace and try again
i=$((i+1))
done
echo "${next_workspace}"