Add some configs from generic Ubuntu

This commit is contained in:
2020-05-11 05:16:27 -04:00
parent f32c1048d1
commit 754f64f135
16037 changed files with 205635 additions and 137 deletions

View File

@@ -0,0 +1,82 @@
#!/bin/bash
pomodoro_monitor () {
local signal
local -a msg
gdbus monitor \
--session \
--dest org.gnome.Shell \
--object-path /timepp/zagortenay333/Pomodoro |
while read -r -a msg; do
signal=${msg[1]} signal=${signal##*.}
case "$signal" in
"POMO") echo "$signal";;
"STOPPED") echo "$signal";;
"LONG_BREAK") echo "$signal";;
"SHORT_BREAK") echo "$signal";;
esac
done
}
# Examples:
# timer_start
# timer_start 60
# timer_start 30 "get to the chopaaaaaaaaaaa"
timer_start () {
local time="${1:-0}"
local msg="${2:-'null'}"
>/dev/null gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /timepp/zagortenay333/Timer \
--method timepp.zagortenay333.Timer.start_from_default_preset "$time" "$msg"
}
get_tracked_tasks () {
local res=$(
gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /timepp/zagortenay333/TimeTracker \
--method timepp.zagortenay333.TimeTracker.get_tracked_tasks
)
echo "$res"
}
get_tracked_projects () {
local res=$(
gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /timepp/zagortenay333/TimeTracker \
--method timepp.zagortenay333.TimeTracker.get_tracked_projects
)
echo "$res"
}
tracker_monitor () {
local task # the task string
local sig
local msg
local -a arr
gdbus monitor --session --dest org.gnome.Shell \
--object-path /timepp/zagortenay333/TimeTracker |
while read -r msg; do
read -r -a arr <<< $(echo $msg)
sig=${arr[1]} sig=${sig##*.}
arr[0]='' arr[1]='' task="${arr[@]}"
case "$sig" in
"started_tracking") notify-send "started:" "$task";;
"stopped_tracking") notify-send "stopped:" "$task";;
esac
done
}

View File

@@ -0,0 +1,167 @@
#!/bin/bash
set -eu
# =====================================================================
# This script is used to control the time-tracker of the Time++ gnome
# shell extension:
# https://github.com/zagortenay333/timepp__gnome
#
# Once executed, the script will listen for when the workspace change
# and do something.
#
# The tracker is controled by supplying string arguments.
# An arg string is of the form:
# "["default" ]tracker_id n1[, n2, n3,...]"
#
# If the string starts with the "default" keyword then:
# - the given tracker_id is gonna be the default id
# - no workspace numbers need to provided
#
# The tracker_id is either:
# - the string "stop"
# - a tracker_id specified in Time++ using the the "tracker_id:string"
# todo.txt extension. (See README of Time++.)
#
# The n1, n2, ... numbers correspond to workspace numbers. They are
# 0-indexed.
#
# Examples:
#
# 1) tracker_control "stop 0" "default id1 2 3" "id2 1 4"
# Means:
# - If on workspace number 0 , stop the tracker.
# - If on workspace number 2 or 3, start tracking tasks with id "id1".
# - If on workspace number 1 or 4, start tracking tasks with id "id2".
# - If on any other workspace , start tracking tasks with id "id1".
#
# 2) tracker_control "id1 2 3"
# Means:
# - If on workspace number 2 or 3, start tracking tasks with id "id1".
# - If on any other workspace , stop tracking.
#
# 3) tracker_control "default id1"
# Means:
# - Always track tasks with id "id1".
#
# 4) tracker_control
# Means:
# - Stop tracking.
# =====================================================================
# =====================================================================
# @@@ Constants
# =====================================================================
declare -A id_workspace_map
current_workspace=0
current_id=0
default_id="stop"
shell_version=$(gnome-shell --version | cut -d " " -f 3)
get_workspace_cmd="global.display.get_active_workspace_index()"
[[ $shell_version < "3.29" ]] &&
get_workspace_cmd="global.screen.get_active_workspace_index()"
# =====================================================================
# @@@ Funcs
# =====================================================================
stop_tracking () {
>/dev/null gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /timepp/zagortenay333/TimeTracker \
--method timepp.zagortenay333.TimeTracker.stop_all_tracking
}
start_tracking () {
local id=$1
stop_tracking
>/dev/null gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /timepp/zagortenay333/TimeTracker \
--method timepp.zagortenay333.TimeTracker.start_tracking_by_id "$id"
}
on_workspace_changed () {
local found_id=$default_id
local it
local workspace
for it in "${!id_workspace_map[@]}"; do
for workspace in ${id_workspace_map[$it]}; do
[[ $workspace == "$current_workspace" ]] && found_id=$it && break 1
done
done
[[ $found_id == "$current_id" ]] && return
if [[ $found_id == "stop" ]]; then
stop_tracking
else
start_tracking "$found_id"
fi
current_id=$found_id
}
check_workspace () {
local workspace
read -r -a workspace <<< "$(
gdbus call \
--session \
--dest org.gnome.Shell \
--object-path /org/gnome/Shell \
--method org.gnome.Shell.Eval \
"$get_workspace_cmd"
)"
# gdbus will return a string of the form "('bool', 'n')".
# We need to extract n only.
workspace=${workspace[1]}
workspace=${workspace:1: -2}
if [[ $workspace != "$current_workspace" ]]; then
current_workspace=$workspace
on_workspace_changed
fi
}
# =====================================================================
# @@@ Parse args
# =====================================================================
[[ $# == 0 ]] && stop_tracking && exit
for it in "$@"; do
read -r -a it <<< "$it"
case ${it[0]} in
"default")
default_id=${it[1]}
id_workspace_map[${it[1]}]="${it[*]:2}"
;;
*)
id_workspace_map[${it[0]}]="${it[*]:1}"
esac
done
# =====================================================================
# @@@ Mainloop
# =====================================================================
trap "stop_tracking" INT TERM EXIT
while true; do
check_workspace
sleep 1
done