Last active
December 20, 2015 00:49
-
-
Save lampapetrol/6045033 to your computer and use it in GitHub Desktop.
Launches a session with the expected title, terminal layout and init command in Yakuake, the best console in the universe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() { | |
cat <<EOF | |
usage: $0 <options> <terminal1Command> <terminal2Command> ... | |
Launches a session with the expected title, terminal layout and init command in Yakuake, the best console in the universe. | |
OPTIONS: | |
-h Show this message | |
-t Title (optional) | |
-l Layout (optional) | |
1 : single (default) | |
2h: two terminals splitted horizontally | |
2v: two terminals splitted vertically | |
3u: three terminals with terminal full width in upper section and two terminals splitted vertically in lower section | |
3l: three terminals with terminal full width in lower section and two terminals splitted vertically in upper section | |
4: four splitted | |
<terminalXCommand> : command to run after session initialization. the order depends on the layout if you want to use commands but skip a terminal type a noop command like 'true' | |
EOF | |
} | |
open_session() { | |
# Open a session | |
case "$sessionTerminalLayout" in | |
"1") | |
sessionId=$(qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.addSession) | |
;; | |
"2h") | |
sessionId=$(qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.addSessionTwoVertical) | |
;; | |
"2v") | |
sessionId=$(qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.addSessionTwoHorizontal) | |
;; | |
"3u") | |
sessionId=$(qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.addSessionTwoVertical) | |
terminalIds=($(qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.terminalIdsForSessionId "$sessionId" | tr "," "\n")) | |
lastTerminalId=${terminalIds[${#terminalIds[@]} - 1]} | |
qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.splitTerminalLeftRight $lastTerminalId | |
;; | |
"3l") | |
sessionId=$(qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.addSessionTwoVertical) | |
qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.splitSessionLeftRight "$sessionId" | |
;; | |
"4") | |
sessionId=$(qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.addSessionQuad) | |
;; | |
*) | |
echo "Layout not supported: $sessionTerminalLayout" >&2 | |
exit 1; | |
;; | |
esac | |
# Set tab title | |
if [ ! -z "$sessionTitle" ]; then | |
qdbus org.kde.yakuake /yakuake/tabs org.kde.yakuake.setTabTitle "$sessionId" "$sessionTitle" | |
fi; | |
# Run command within tabs | |
terminalIds=$(qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.terminalIdsForSessionId "$sessionId") | |
terminalCount=0 | |
for terminalId in ${terminalIds//,/ }; do | |
terminalCommand="${commandList[$terminalCount]}" | |
if [ ! -z "$terminalCommand" ]; then | |
qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.runCommandInTerminal "$terminalId" "$terminalCommand" | |
fi; | |
terminalCount=$((terminalCount + 1)) | |
done; | |
} | |
sessionTitle='' | |
sessionTerminalLayout=1 | |
commandList=() | |
while getopts "hl:t:" OPTION | |
do | |
case $OPTION in | |
h) | |
usage | |
exit 1 | |
;; | |
l) | |
sessionTerminalLayout=$OPTARG | |
;; | |
t) | |
sessionTitle=$OPTARG | |
;; | |
?) | |
usage | |
exit | |
;; | |
esac | |
done | |
# consider trailing strings as a command array | |
shift $((OPTIND - 1)) | |
commandList=("$@") | |
open_session |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you may need to install qt4-default or "qt5-default + qdbus-qt5" to make qdbus work
http://askubuntu.com/questions/365644/qdbus-cannot-be-called-in-kubuntu-saucy