Created
February 17, 2012 21:49
-
-
Save kubek2k/1855659 to your computer and use it in GitHub Desktop.
Functions for yakuake to automatically spawn new terminals
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
# | |
# Utility functions to spawn terminals automatically | |
# @kubek2k 2012 | |
# | |
# sample usage: | |
# open_new_session_and_run_command ssh myhost tail -f /log/syslog.log | |
YAKUAKE_DBUS="qdbus org.kde.yakuake" | |
function close_session { | |
SESSION_ID="$1" | |
$YAKUAKE_DBUS /yakuake/sessions removeSession $SESSION_ID | |
} | |
function session_ids { | |
sessions=`$YAKUAKE_DBUS /yakuake/sessions sessionIdList | tr , \ ` | |
echo $sessions | |
} | |
function get_last_session_id { | |
sessions=`session_ids` | |
sessions_array=($sessions) | |
n=${#sessions_array[@]} | |
echo ${sessions_array[n - 1]} | |
} | |
function open_session { | |
$YAKUAKE_DBUS /yakuake/sessions addSession | |
echo `get_last_session_id` | |
} | |
function close_all_sessions { | |
sessions=`session_ids` | |
for session in $sessions ; do | |
close_session $session | |
done | |
} | |
function get_first_terminal_id { | |
session_id=$1 | |
terminals=`$YAKUAKE_DBUS /yakuake/sessions terminalIdsForSessionId $session_id` | |
arr=($terminals) | |
echo ${arr[0]} | |
} | |
function run_command_in_session { | |
session_id=$1 | |
shift | |
command=$@ | |
echo $command | |
terminal_id=`get_first_terminal_id $session_id` | |
$YAKUAKE_DBUS /yakuake/sessions runCommandInTerminal $terminal_id "$command" | |
} | |
function open_new_session_and_run_command { | |
session_id=`open_session` | |
run_command_in_session $session_id $@ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment