-
-
Save TitouanT/4dfb8c968f06965aaa875fcf6e837b3e to your computer and use it in GitHub Desktop.
#!/bin/sh | |
# requires jq | |
stick_to="name" && cmd="workspace" # stick to the workspace | |
# stick_to="output" && cmd="focus output" # stick to the screen | |
initial=$( | |
i3-msg -t get_workspaces | | |
jq -r ".[] | select(.focused == true) | .$stick_to" | |
) | |
py_script=$(cat <<EOF | |
import sys | |
from numpy import roll | |
s, w = [], [] | |
for l in sys.stdin.readlines(): | |
screen, workspace = l.strip().split(':', 1) | |
s.append(screen) | |
w.append(workspace) | |
for line in zip(s, roll(s,1), w, roll(w, -1)): | |
print(' '.join(line)) | |
EOF | |
) | |
i3-msg -t get_outputs | | |
jq -r '.[] | select(.active == true) | "\(.name):\(.current_workspace)"' | | |
python3 -c "$py_script" | | |
while read -r screen_src screen_dst workspace_tgt workspace_final | |
do | |
i3-msg -- workspace --no-auto-back-and-forth "$workspace_tgt" | |
i3-msg move workspace to output "$screen_dst" | |
i3-msg focus output "$screen_src" | |
i3-msg -- workspace --no-auto-back-and-forth "$workspace_final" | |
echo "moved $workspace_tgt to $screen_dst" | |
echo "and restored focus to $workspace_final" | |
done | |
i3-msg $cmd $initial |
I normally use zsh but I tried it both for zsh and bash and got the same error...
I meant what shell /bin/sh
points to you can see which it is with realpath /bin/sh
yeah thats the issue
Can you reference them by there number, for example does this put focus on your chrome workspace ?
i3-msg -- workspace --no-auto-back-and-forth "1"
If yes then just change screen, workspace = l.strip().split(':')
to screen, workspace = l.strip().split(':')[:2]
If it works then I will add it to the gist.
Let me see. The original script this is forked from did not give me that error.
@Zackhardtoname it should work now ! thanks for your feedback, I keep my workspaces named with numbers so I never ran into this issue.
The problem here was that you have :
in your workspace name and that's the symbol I use to split.
That wouldn't and didn't work because somehow i3 treats ws "3" and "3:" differently.
This works: screen, workspace = l.strip().split(':', maxsplit=1)
Thank you so much! I should have dug this more myself
Hi
I grabbed your script thinking that it would manage my special naming convention
set $workspace1 "1 "
set $workspace2 "2 "
set $workspace3 "3 "
set $workspace4 "4 "
set $workspace5 "5 "
set $workspace6 "6 "
set $workspace7 "7 "
set $workspace8 "8 "
set $workspace9 "9 "
set $workspace10 "10 "
Unfortunately, it doesn't, because of the spaces. Had to change the names changing spaces with underscores.
Not as pretty but it works.
Do you think there's a way to handle spaces in workspaces names ?
Regards
I just wanted to say thank you: I can't imagine how long it would have taken me to figure this out.
mmmh it looks like it's an issue with
IFS=:
Now that I think about it, it's not even needed to set it to
:
since it was for the final read and since I use a python script I can just use a space as separator.I don't understand why it's not working for you though, what shell do you use ? I have tried with both
dash
andbash
.Incase that's not it, give me the output of