-
Notifications
You must be signed in to change notification settings - Fork 4
/
sway-workspace-move
executable file
·72 lines (64 loc) · 2 KB
/
sway-workspace-move
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
#!/bin/bash
SCRIPTNAME=$(basename $0)
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
IFS=$'\n'
if [[ -n $THEME ]]; then
fzf_color="--color=$THEME"
fi
# $THEME env variable set via sway config.
# check for env variable, if exists we are the
# forked shell, get the waiting string from the fifo
# and call fzf and sway from there.
prompt="Workspace> "
header="Move which workspace to current output?"
if [[ -n $SWM_FIFO ]]; then
str=$(cat $SWM_FIFO)
# rm the fifo, we are done with it
rm -rf $SWM_FIFO
selection=$(printf $str | fzf --header=$header --prompt="$prompt" $fzf_color)
if [[ -z $selection ]]; then
exit
fi
focused_output=$(swaymsg -r -t get_outputs | jq -r '.[] | select( .focused == true ) | .name')
swaymsg workspace $selection
swaymsg move workspace to $focused_output
exit
fi
# build the selection string we will ultimate
# pipe to fzf, take note of largest string to set
# columns and number of lines to set lines for alacritty.
columns=0
lines=0
str=""
workspaces=($(swaymsg -t get_workspaces -r | jq -r -c '.[] | .name'))
for workspace in "${workspaces[@]}"; do
if [[ ${#workspace} -gt $columns ]];
then
columns=${#workspace}
fi
lines=$((lines+1))
str="$str$workspace\n"
done
# add some padding to the terminal for
# lines and columns, for columns make sure
# we take the prompt into the padding consideration
lines=$((lines+3))
columns=$((columns+"${#header}"+5))
if [[ columns -gt 100 ]];
then
columns=100
fi
# create fifo and launch a terminal with the title "fzf-switcher"
# run the script in the new terminal which will see the env vars
# and execute the first if block in this script.
fifo=/tmp/sws-$(date +%s)
mkfifo $fifo
SWM_FIFO=$fifo $SHELL -c "alacritty \
-o window.dimensions.columns=$columns \
-o window.dimensions.lines=$lines \
-o font.size=16.0 \
-o window.padding.x=20 \
-o window.padding.y=20 \
--title "fzf-switcher" \
-e $SCRIPTPATH/$SCRIPTNAME"&
echo -n $str > $fifo