Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script does not work for me out of the box... #1

Merged
merged 2 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ The command run to initialize the tab is everything after the comma.
| Command | Description |
|--------|----------|
|`htop, htop`|Creates a tab named "htop" and runs htop in the tab.|
|`, cd /proj && clear`|Creates a tab, changes directory to `/proj` then clears the console.|
|`shell`|Creates a tab that|
|`journalctl, journalctl --follow`|Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.|
|`home, cd ~ && clear`| Creates a tab, changes directory to your home then clears the console.|
|`shell【ツ】`|Creates a new shell tab.|
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best change here ;).

6 changes: 3 additions & 3 deletions sample.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Some stupid yakuake setup.
htop, htop
jornalctl, journalctl --follow --full
proj, cd /srv/proj && clear
shell
jornalctl, journalctl --follow
home, cd ~ && clear
shell【ツ】
58 changes: 50 additions & 8 deletions yakuake-init.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,50 @@ trim ()
echo $var
}

# debugging helper function
#
# usage:
# logm "There is an ERROR o.O!"
#
# view log:
# $ tail -f /var/log/syslog
#
SCRIPT_NAME="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")"
logm ()
{
logger --tag ${SCRIPT_NAME} $(trim ${1}) --priority 7
}

# Helper that sends a command to yakuake
call_yakuake_method ()
{
path="${1}"
method="${2}"
parameters=("${@:3}")
result=$(dbus-send --print-reply=literal --dest=org.kde.yakuake /yakuake/${path} org.kde.yakuake.${method} "${parameters[@]}")
result=$(trim ${result})

if [[ -n "${result}" ]]
if [[ -z "${parameters}" ]]
then
echo "${result}"
result=$(dbus-send --print-reply=literal --dest=org.kde.yakuake /yakuake/${path} org.kde.yakuake.${method})
else
case "$method" in
"terminalIdsForSessionId")
result=$(dbus-send --print-reply=literal --dest=org.kde.yakuake /yakuake/${path} org.kde.yakuake.${method} "${parameters[@]}")
;;
*)
result=$(dbus-send --type=method_call --dest=org.kde.yakuake /yakuake/${path} org.kde.yakuake.${method} "${parameters[@]}")
;;
esac
fi

result=$(trim ${result})

echo "${result}"
}

# Retrieves the currently active session id
get_active_session_id ()
{
logm "get_active_session_id = yes"
call_yakuake_method sessions activeSessionId | rev | cut -d" " -f1 | rev
}

Expand All @@ -56,7 +82,7 @@ set_active_session ()
get_terminal_ids_for_tab ()
{
# These tab ids are returned comma delimited. Replace the commas for easier time
# getting the results as an array.
# getting the results as an array.
call_yakuake_method sessions terminalIdsForSessionId "int32:${1}" | sed -e 's/,/ /g'
}

Expand All @@ -76,16 +102,32 @@ set_tab_title ()
# Takes a tab id and the command string
run_tab_command_in_first_terminal ()
{
terminals=($(get_terminal_ids_for_tab "${1}"))
terminals=$(get_terminal_ids_for_tab "${1}")
call_yakuake_method sessions runCommandInTerminal "int32:${terminals[0]}" "string:${@:2}"
}

# check yakuake is running
if pgrep -x "yakuake" > /dev/null
then
logm "yakuake is still running!"
else
logm "yakuake is stopped! Try to start."

# This line is needed in case yakuake does not accept fcitx inputs.
/usr/bin/yakuake --im /usr/bin/fcitx --inputstyle onthespot &

sleep 2
fi


# If we're given a file name, then process it. (Allows this script to be dot sourced)
config_file_name="${*}"
if [[ -n "${config_file_name}" ]]
then
INITIAL_SESSION_ID=$(get_active_session_id)


logm "INITIAL_SESSION_ID: $INITIAL_SESSION_ID"

while IFS=, read -r tab_title tab_command;
do
# Trim variables.
Expand All @@ -112,7 +154,7 @@ then
then
set_tab_title "${tab_id}" "${tab_title}"
fi

# Run the command.
if [[ -n "${tab_command}" ]]
then
Expand Down