-
Notifications
You must be signed in to change notification settings - Fork 15
/
i3-assign-workspace-to-group
executable file
·38 lines (32 loc) · 1.1 KB
/
i3-assign-workspace-to-group
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
#!/usr/bin/env bash
# See https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -o errexit -o errtrace -o nounset -o pipefail
readonly HELP_HEADING='Select a group to assign to the focused workspace.'
readonly HELP_CONTENT='You can assign it to a new group by typing a new name.
Note that the default group is shown as <default>.'
readonly HELP_FORMAT='<span alpha="50%%" size="smaller"><b>%s</b>
<i>%s</i></span>'
# shellcheck disable=SC2059
# shellcheck disable=SC2155
readonly HELP_TEXT="$(printf "${HELP_FORMAT}" "${HELP_HEADING}" \
"${HELP_CONTENT}")"
command_exists() {
type "$1" &> /dev/null
}
get_tool() {
filename="$1"
local dir tool
dir="$(cd -- "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
tool="${dir}/${filename}"
command_exists "${tool}" || tool="${filename}"
printf '%s\n' "${tool}"
}
main() {
select_groups="$(get_tool i3-select-workspace-group)"
if ! group="$("${select_groups}" -mesg "${HELP_TEXT}")"; then
exit 1
fi
tool="$(get_tool "${I3_WORKSPACE_GROUPS_CLI:-i3-workspace-groups}")"
"${tool}" "$@" assign-workspace-to-group "${group}"
}
main "$@"