I’ve been struggling with getting a wezterm window running cmus on a specific workspace upon start up for a while now. I can’t use assign because the only eligible criteria differentiating it from a generic wezterm window is the pid, and my attempts to get the pid from get_tree and use that have been unsuccessful. I thought I had figured it out, when I put these lines in a another file:

#! /bin/bash
sway workspace 10 && sway 'exec wezterm -e cmus'

then in my config file I have this: exec ./start_cmus.sh

But it doesn’t work. If I run start_cmus from the shell, the expected behavior ensues (a wezterm window running cmus is opened on workspace 10).

Any tips?

  • DollyDuller@programming.dev
    link
    fedilink
    English
    arrow-up
    5
    ·
    edit-2
    2 days ago

    First, make sure to include the full path to the script in your config file, like exec /home/your_username/path/start_cmus.sh or exec ~/path/start_cmus.sh. If you just use ./start_cmus.sh, there will be a complaint as it doesn’t know where to look for the script.

    Another thing to keep in mind is that swaymsg is usually the better choice (man sway) when you want to send commands to sway. You can write your script as swaymsg -t command 'workspace 10; exec wezterm -e cmus' and then put the whole thing in your config file.

    To make debugging easier, I like to add some echo or notify-send commands to my script to see if it’s working as expected. I’ll put those in my config file, run it, and check if the debug commands are being executed correctly like echo "first: $first_output" && commands && echo "second: $second_output". It’s a simple trick that can save you a lot of time. Also, don’t forget to check out journalctl for more info.

    • Hammerheart@programming.devOP
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      17 hours ago

      thank you! your command worked like a charm once i prepended it with exec. i even added a final command taking me back to workspace 1. tested it with exec_always and it seems to be good, crossing fingers it will actually work on boot.

      maybe you can answer another question for me: is the config file executed asynchronously? What i mean is, does it run through each line, or is there a chance that, say, line 25 might execute before line 13?

      • DollyDuller@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        4 hours ago

        I’m not entirely sure how it works, but I think it’s read from top to bottom. If you need to control the order of execution, I’d suggest writing shell scripts and adding them to the config file. It should make things easier to manage.

  • just_another_person@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    2 days ago

    Many things wrong here, but you’re going to have issues using ‘&&’ in something like this. Remove that and see if you get any useful output.

    If you still don’t get useful output, then your exec is being swallowed up. Generally you need to very explicit in Sway: create workspace, switch to it, start script. Seems like you’re intentionally skipping steps, and you’re gonna have a bad time.

    If anything, to help debug, try the above, and explicitly create a class of window to start something in, then run something to know works, like calculator. Make sure these types of things work first before trying to chain scripts together.