How to launch a KDE konsole with multiple tabs running various progs?

后端 未结 4 1642
别那么骄傲
别那么骄傲 2021-02-13 05:24

I know how to start a Konsole with one executable running in it, and leave the Konsole open after the program ends. I can do this using a .desktop file and change s

4条回答
  •  旧巷少年郎
    2021-02-13 06:30

    qdbus solution above didn't work for me because blockable call /usr/bin/konsole, so I upgrade it a little. I'm using ZSH so change shebang on yours.

    #! /bin/zsh
    # Multi command start in various konsole tabs
    
    # List of commands to run, with parameters, in quotes, space-separated; do not use quotes inside (see bash arrays)
    COMMANDS=("vi" "nano")
    # Geting length of the COMMANDS array
    len_arr=${#COMMANDS[@]}
    
    # Simple /usr/bin/konsole block this script, no work for me. So use qdbus to run konsole
    qdbus org.kde.klauncher5 /KLauncher exec_blind "/usr/bin/konsole" "/home/$USER"
    # Wait until konsole was run up completely. 1s for me
    sleep 1s
    # get the last added konsole and save it in $KDS variable
    qdbus | grep konsole | tail -1 | { read KDS }
    # loop the array with commands . 
    for (( i=1; i<=$len_arr; i++ ))
    do
     if [ $i -gt 1 ]
     then
         # for all commands beside first getting the number of the new konsole tab
         session=$(qdbus $KDS /Windows/1 newSession)
         
     else
         # get the number of the current console tab
         session=$(qdbus $KDS /Windows/1 currentSession)
     fi
     # run current command in tab
     qdbus $KDS /Sessions/${session} runCommand "${COMMANDS[$i]}"
     
     # Silence if you need. I'm not using it.
     # Optional: will ping when there's no more output in the window
     # qdbus $KDS /Sessions/${session} setMonitorSilence true
    done
     
    

提交回复
热议问题