This repository has been archived by the owner on May 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsway-workspace
executable file
·81 lines (71 loc) · 1.78 KB
/
sway-workspace
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
# sway-launch
shopt -s xpg_echo
bold="\033[1m"
green="\033[32m"
red="\033[31m"
reset="\033[0m"
# swaymsg, fallback to i3-msg
swaymsg() {
if command -v swaymsg >/dev/null 2>&1; then
command swaymsg "$@"
else
command i3-msg "$@"
fi
}
usage() {
echo "${bold}Usage:${reset} ${green}sway-workspace${reset} [OPTIONS] [VALUE]"
echo
echo "- Go to provided workspace."
echo "- If no value is provided, print the current workspace."
echo
echo "VALUE can be:"
echo '- "next", "prev", "next-empty", or a number.'
echo
echo "OPTIONS:"
echo ' -q, --quiet Do not print any output. (Useful for wrapping scripts'
echo ' with their own outputs.)'
echo " -h, --help Show this help message."
}
# parse options
quiet=0
workspace=""
while [[ "$#" -gt 0 ]]; do
case "$1" in
-q|--quiet)
quiet=1
shift
;;
-h|--help)
usage
exit 0
;;
current|next|prev|next-empty|[0-9]*)
workspace=$1
shift
;;
*)
echo "Invalid argument: $1"
[[ $quiet -eq 0 ]] && usage
exit 1
;;
esac
done
# if no argument, print current workspace
if [[ "$workspace" == "" ]]; then
sway-get-current-workspace
exit 0
fi
# handle "next", "prev" and number, in which case we message sway
if [[ "$workspace" =~ ^[0-9]+$ ]] || [[ "$workspace" == "next" ]] || [[ "$workspace" == "prev" ]]; then
[[ $quiet -eq 0 ]] && echo "Going to workspace ${green}${workspace}${reset} ..."
swaymsg workspace "$workspace"
exit 0
fi
# handle "next-empty"
if [[ "$workspace" == "next-empty" ]]; then
workspace=$(sway-get-next-empty-workspace)
[[ $quiet -eq 0 ]] && echo "Going to workspace ${green}${workspace}${reset} ..."
swaymsg workspace "$workspace"
exit 0
fi