Browse Source

initial checkin

master
Georg Hopp 10 years ago
commit
ce9adec2f0
  1. 1
      README.md
  2. 90
      keymanagement.sh
  3. 49
      tmp.sh
  4. 9
      tools.sh
  5. 100
      tools/background
  6. 20
      tools/coltest
  7. 116
      tools/dates
  8. 25
      tools/diff_no_links
  9. 8
      tools/execalias
  10. 116
      tools/gcal
  11. 116
      tools/hollidays
  12. 67
      tools/i3odcnt
  13. 67
      tools/i3overdue
  14. 67
      tools/i3task
  15. 44
      tools/lxc-snapshot
  16. 40
      tools/lxc-start
  17. 8
      tools/mailterms
  18. 116
      tools/mdates
  19. 13
      tools/rand_printable
  20. 61
      tools/tardiff
  21. 116
      tools/tcoming
  22. 116
      tools/tcomingf
  23. 116
      tools/terms
  24. 116
      tools/tpast
  25. 116
      tools/ttomorrow
  26. 116
      tools/ttomorrowf
  27. 23
      vcs.sh

1
README.md

@ -0,0 +1 @@
A collection of shell functions and tools I am using.

90
keymanagement.sh

@ -0,0 +1,90 @@
SSH_KEYGEN="/usr/bin/ssh-keygen"
SSH_ADD="/usr/bin/ssh-add"
export SSH_KEYGEN SSH_ADD
IDENTITY_FILE="/mnt/auth/ghopp/.ssh/ident"
SSH_AGENT_FILE="${HOME}/.ssh/agent.info"
GPG_TTY=$(tty)
export IDENTITY_FILE SSH_AGENT_FILE GPG_TTY
alias ssh_init_github="ssh-add /mnt/auth/ghopp/.ssh/ident-github ~/.ssh/getcred_github.sh"
function ssh-keygen() {
ident="${1:-${IDENTITY_FILE}}"
${SSH_KEYGEN} -f "${ident}" "$@"
}
function ssh-add() {
ident="${1:-${IDENTITY_FILE}}"
ask_pass="${2:-${HOME}/.ssh/getcred.sh}"
if [ '-' != "${ident:0:1}" ]
then
DISPLAY=:0.0 SSH_ASKPASS="${ask_pass}" \
${SSH_ADD} ${ident} 2>/dev/null </dev/null
else
${SSH_ADD} "$@"
fi
}
function ssh-init-agent() {
local CAT="/bin/cat"
local PS="/bin/ps"
local ECHO="/bin/echo"
local SSH_AGENT="/usr/bin/ssh-agent"
test -e "${SSH_AGENT_FILE}" && eval `${CAT} "${SSH_AGENT_FILE}"` >/dev/null
if [ "x" != x${SSH_AGENT_PID} ]
then
if [ "ssh-agent" = "`${PS} -p ${SSH_AGENT_PID} -o comm=`" ]
then
return
fi
fi
${ECHO} -n "start ssh-agent ... "
${SSH_AGENT} >"${SSH_AGENT_FILE}"
if [ 0 -eq $? ]
then
eval `${CAT} "${SSH_AGENT_FILE}"` >/dev/null
${ECHO} "OK"
ssh-add
else
${ECHO} "FAILED"
fi
}
function gpg-init-agent() {
local FUSER="/bin/fuser"
local CAT="/bin/cat"
local PS="/bin/ps"
local ECHO="/bin/echo"
local CUT="/usr/bin/cut"
local GPG_AGENT="/usr/bin/gpg-agent --daemon --allow-preset-passphrase"
local GPG_PRESET="/usr/libexec/gpg-preset-passphrase"
local CREDDIR="/mnt/auth/ghopp/gnupg/"
local KEYGRIP="D17D6099DA4F7CF580991F6525BAC9DB841C9B30"
local SUBKEYGRIP="BE4A9914142B488736792B9CBE01AE3A94D96E7A"
if ${FUSER} ${HOME}/.gnupg/S.gpg-agent >/dev/null 2>&1
then
return
else
${ECHO} -n "start gpg-agent ... "
${GPG_AGENT}
if [ 0 -eq $? ]
then
${ECHO} "OK"
${CAT} "${CREDDIR}/gpg.pw" | ${GPG_PRESET} --preset ${KEYGRIP}
${CAT} "${CREDDIR}/gpg.pw" | ${GPG_PRESET} --preset ${SUBKEYGRIP}
else
${ECHO} "FAILED"
fi
fi
}
# vim: set ft=sh ts=4 sw=4:

49
tmp.sh

@ -0,0 +1,49 @@
#!/bin/bash -x
TMPDIR="/tmp/${USER}/"
test -d ${TMPDIR} || mkdir ${TMPDIR}
for dir in \
".cache" \
".adobe" \
".macromedia" \
".mozilla/firefox" \
".pentadactyl" \
".scummvm/logs"
do
test -d "${TMPDIR}${dir}" || mkdir -p "${TMPDIR}${dir}"
done
for file in \
".dmenu_cache" \
".scummvm/logs/scummvm.log"
do
test -f "${TMPDIR}${file}" || touch "${TMPDIR}${file}"
done
FF_PROFILE='default'
FF_DIR="${HOME}/.mozilla/firefox/"
FF_PROFILE_DIR="${FF_DIR}${FF_PROFILE}/"
if [ ! -e "${FF_PROFILE_DIR}" ]
then
mkdir -p "${FF_PROFILE_DIR}"
cat >${FF_DIR}/profiles.ini <<-END
[General]
StartWithLastProfile=1
[Profile0]
Name=default
IsRelative=1
Path=${FF_PROFILE}
END
for element in ${HOME}/.mozilla/persistent/*
do
test "${element}" == "${HOME}/.mozilla/persistent/*" && break
ln -s "${element}" "${FF_PROFILE_DIR}${element##*/}"
done
fi
source .functions
# vim: set ts=4 sw=4:

9
tools.sh

@ -0,0 +1,9 @@
source ${HOME}/scripts/init/tools/rand_printable
source ${HOME}/scripts/init/tools/diff_no_links
source ${HOME}/scripts/init/tools/tardiff
source ${HOME}/scripts/init/tools/background
source ${HOME}/scripts/init/tools/gcal
source ${HOME}/scripts/init/tools/coltest
source ${HOME}/scripts/init/tools/i3task
source ${HOME}/scripts/init/tools/lxc-start
source ${HOME}/scripts/init/tools/lxc-snapshot

100
tools/background

@ -0,0 +1,100 @@
#!/bin/bash
##
# This one generates a background image for all active xrandr displays
# and sets it via ImageMagick display. The intermediate image will
# be removed as soon as the background ist set.
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
function rand() {
local DD="/bin/dd"
local OD="/usr/bin/od"
local SED="/bin/sed"
${DD} if=/dev/urandom bs=2 count=1 2>/dev/null | \
${OD} -i | ${SED} '2d;s/^0\+ \+//'
}
function background() {
local SED="/bin/sed"
local XRANDR="/usr/bin/xrandr"
local TEMPFILE="/bin/tempfile"
local IDENTIFY="/usr/bin/identify"
local CONVERT="/usr/bin/convert"
local SETROOT="/usr/bin/xsri"
local ECHO="/bin/echo"
local EXPR="/usr/bin/expr"
local WC="/usr/bin/wc"
local LS="/bin/ls"
local BGDIR="${BGDIR:-${HOME}/images/backgrounds}"
local MYDISP="${DISPLAY:-:0}"
local XRANDR_EXP='
/^Screen/{
s/ //g
s/^.*ent\([0-9x]*\).*$/\1/
}
/ conn/s/^.*cted \([^ ]*\).*$/\1/
t
d'
local RESOLUTIONS="`DISPLAY=${MYDISP} ${XRANDR} | ${SED} "${XRANDR_EXP}"`"
local WHOLE="`${ECHO} "${RESOLUTIONS}" | ${SED} '1p;d'`"
local SCREENS="`${ECHO} "${RESOLUTIONS}" | ${SED} '2,$p;d'`"
local BGS="`${LS} -1b "${BGDIR}"`"
local N_BGS=`${ECHO} "${BGS}" | ${WC} -l`
local res img size ofs ofs_x ofs_y screen_asp image_asp image_geom cmd
cmd="-size ${WHOLE} xc:black"
for res in ${SCREENS}
do
img=`rand`
img=`${EXPR} ${img} % ${N_BGS} + 1`
img="${BGDIR}/`${ECHO} "${BGS}" | ${SED} ${img}'p;d'`"
size=${res%%+*}
ofs=${res#*+*}
ofs_x=${ofs%%+*}
ofs_y=${ofs##*+}
screen_asp=`eval ${EXPR} ${size/x/ '\*' 100 \/ }`
image_asp=`eval "${IDENTIFY} -format \"%w '\*' 100 \/ %h\" ${img}"`
image_asp=`eval ${EXPR} $image_asp`
# decide wheter to scale up to screen height or width
# based on previously computed asp's
if [ ${image_asp} -lt ${screen_asp} ]
then
# scale on height!
image_geom="x${size##*x}"
else
# scale on width!
image_geom="${size%%x*}x"
fi
image_geom=`eval "${CONVERT} -scale ${image_geom} ${img} jpeg:- | \
${IDENTIFY} -format \"%wx%h\" jpeg:-"`
ofs_x=`${EXPR} $ofs_x + \( \( ${size%%x*} - ${image_geom%%x*} \) / 2 \)`
ofs_y=`${EXPR} $ofs_y + \( \( ${size##*x} - ${image_geom##*x} \) / 2 \)`
cmd="${cmd} ${img} -geometry ${image_geom}+${ofs_x}+${ofs_y} -composite"
done
img=`${TEMPFILE} -s '.jpg'`
eval "${CONVERT} ${cmd} ${img}"
DISPLAY=${MYDISP} ${SETROOT} --emblem="${img}" --set 2>/dev/null
rm ${img}
}
test "X$(basename -- "$0")" = "Xbackground" && background "$@"
# vim: set ft=sh ts=4 sw=4:

20
tools/coltest

@ -0,0 +1,20 @@
#!/bin/sh
function coltest() {
local ECHO="/bin/echo"
if [ $# -lt 1 ]
then
${ECHO} "coltest 256fg-col [256bg-col]"
return
fi
${ECHO} -en "\033[38;5;${1}m"
[ "$2" ] && ${ECHO} -en "\033[48;5;${2}m"
${ECHO} -n "test"
${ECHO} -e "\033[00m"
}
test "X$(basename -- "$0")" = "Xcoltest" && coltest "$@"
# vim: set ft=sh ts=4 sw=4:

116
tools/dates

@ -0,0 +1,116 @@
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4:

25
tools/diff_no_links

@ -0,0 +1,25 @@
#!/bin/sh
function diff_no_links() {
local FIND="/usr/bin/find"
local SED="/bin/sed"
local CAT="/bin/cat"
local TR="/usr/bin/tr"
local SORT="/usr/bin/sort"
local SRC=$1
local DST=$2
local SRC_SYMS="${FIND} \"${SRC}\" -type l -exec basename {} \;"
local DST_SYMS="${FIND} \"${DST}\" -type l -exec basename {} \;"
local ALL_SYMS="${CAT} <(${SRC_SYMS}) <($DST_SYMS) | ${SORT} -u"
local EXCLUDES="${ALL_SYMS} | ${SED} 's/^/ -x /' | ${TR} -d '\n'"
diff -Naur `eval ${EXCLUDES}` "${SRC}" "${DST}"
return $?
}
test "X$(basename -- "$0")" = "Xdiff_no_links" && diff_no_links "$@"
# vim: set ft=sh ts=4 sw=4:

8
tools/execalias

@ -0,0 +1,8 @@
#!/bin/sh
source ${HOME}/.aliases
source ${HOME}/scripts/init/tools/gcal
test "X$(basename -- "$0")" = "Xmailterms" && mailterms "$@"
# vim: set ft=sh ts=4 sw=4:

116
tools/gcal

@ -0,0 +1,116 @@
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4:

116
tools/hollidays

@ -0,0 +1,116 @@
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4:

67
tools/i3odcnt

@ -0,0 +1,67 @@
#!/bin/sh
alias i3active='task i3active 2>/dev/null | sed '\''4!d'\'''
alias i3next='task i3next 2>/dev/null | sed '\''4!d'\'''
alias i3overdue='task i3overdue 2>/dev/null | sed '\''4!d'\'''
alias odcnt='task overdue 2>/dev/null | sed '\''$!d;s/task.*/overdue/'\'''
function i3odcnt() {
echo "\"color\":\"#FF0000\",\"full_text\":\"$(odcnt)\""
}
function i3tasko() {
_i3print "$(i3overdue)"
}
function i3task() {
local TASK="$(i3active)"
test -z "${TASK}" && TASK="$(i3next)"
_i3print "${TASK}"
}
function _taskdate() {
local TDATE
TDATE="$(echo "${1}" | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3-\2-\1/')"
test "${TDATE}" == "${1}" && TDATE="3000-12-12"
echo "${TDATE}"
}
function _taskmsg() {
echo "${1}" | sed 's/^[0-9.]* *//'
}
function _taskcol() {
local ACTIVE_COL="#4040FF"
local ONEDAY_COL="#FFFF00"
local OVERDUE_COL="#FF0000"
local COLOR="#00FF00"
test "$(i3active)" == "${1}" && {
echo "${ACTIVE_COL}"
return
}
# add one day to due date as the due date has also 24 hours
local DUE=$(($(date -d "$(_taskdate "${1}")" +%s)+(24*60*60)))
local NOW=$(date +%s)
test ${DUE} -le $((${NOW}+(24*60*60))) && COLOR="${ONEDAY_COL}"
test ${DUE} -le ${NOW} && COLOR="${OVERDUE_COL}"
echo "${COLOR}"
}
function _i3print() {
printf "\"color\":\"%s\",\"full_text\":\"%s\"" \
"$(_taskcol "${1}")" \
"$(_taskmsg "${1}")"
}
test "X$(basename -- "$0")" = "Xi3task" && i3task "$@"
test "X$(basename -- "$0")" = "Xi3overdue" && i3tasko "$@"
test "X$(basename -- "$0")" = "Xi3odcnt" && i3odcnt "$@"
# vim: set ft=sh ts=4 sw=4:

67
tools/i3overdue

@ -0,0 +1,67 @@
#!/bin/sh
alias i3active='task i3active 2>/dev/null | sed '\''4!d'\'''
alias i3next='task i3next 2>/dev/null | sed '\''4!d'\'''
alias i3overdue='task i3overdue 2>/dev/null | sed '\''4!d'\'''
alias odcnt='task overdue 2>/dev/null | sed '\''$!d;s/task.*/overdue/'\'''
function i3odcnt() {
echo "\"color\":\"#FF0000\",\"full_text\":\"$(odcnt)\""
}
function i3tasko() {
_i3print "$(i3overdue)"
}
function i3task() {
local TASK="$(i3active)"
test -z "${TASK}" && TASK="$(i3next)"
_i3print "${TASK}"
}
function _taskdate() {
local TDATE
TDATE="$(echo "${1}" | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3-\2-\1/')"
test "${TDATE}" == "${1}" && TDATE="3000-12-12"
echo "${TDATE}"
}
function _taskmsg() {
echo "${1}" | sed 's/^[0-9.]* *//'
}
function _taskcol() {
local ACTIVE_COL="#4040FF"
local ONEDAY_COL="#FFFF00"
local OVERDUE_COL="#FF0000"
local COLOR="#00FF00"
test "$(i3active)" == "${1}" && {
echo "${ACTIVE_COL}"
return
}
# add one day to due date as the due date has also 24 hours
local DUE=$(($(date -d "$(_taskdate "${1}")" +%s)+(24*60*60)))
local NOW=$(date +%s)
test ${DUE} -le $((${NOW}+(24*60*60))) && COLOR="${ONEDAY_COL}"
test ${DUE} -le ${NOW} && COLOR="${OVERDUE_COL}"
echo "${COLOR}"
}
function _i3print() {
printf "\"color\":\"%s\",\"full_text\":\"%s\"" \
"$(_taskcol "${1}")" \
"$(_taskmsg "${1}")"
}
test "X$(basename -- "$0")" = "Xi3task" && i3task "$@"
test "X$(basename -- "$0")" = "Xi3overdue" && i3tasko "$@"
test "X$(basename -- "$0")" = "Xi3odcnt" && i3odcnt "$@"
# vim: set ft=sh ts=4 sw=4:

67
tools/i3task

@ -0,0 +1,67 @@
#!/bin/sh
alias i3active='task i3active 2>/dev/null | sed '\''4!d'\'''
alias i3next='task i3next 2>/dev/null | sed '\''4!d'\'''
alias i3overdue='task i3overdue 2>/dev/null | sed '\''4!d'\'''
alias odcnt='task overdue 2>/dev/null | sed '\''$!d;s/task.*/overdue/'\'''
function i3odcnt() {
echo "\"color\":\"#FF0000\",\"full_text\":\"$(odcnt)\""
}
function i3tasko() {
_i3print "$(i3overdue)"
}
function i3task() {
local TASK="$(i3active)"
test -z "${TASK}" && TASK="$(i3next)"
_i3print "${TASK}"
}
function _taskdate() {
local TDATE
TDATE="$(echo "${1}" | sed 's/^\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3-\2-\1/')"
test "${TDATE}" == "${1}" && TDATE="3000-12-12"
echo "${TDATE}"
}
function _taskmsg() {
echo "${1}" | sed 's/^[0-9.]* *//'
}
function _taskcol() {
local ACTIVE_COL="#4040FF"
local ONEDAY_COL="#FFFF00"
local OVERDUE_COL="#FF0000"
local COLOR="#00FF00"
test "$(i3active)" == "${1}" && {
echo "${ACTIVE_COL}"
return
}
# add one day to due date as the due date has also 24 hours
local DUE=$(($(date -d "$(_taskdate "${1}")" +%s)+(24*60*60)))
local NOW=$(date +%s)
test ${DUE} -le $((${NOW}+(24*60*60))) && COLOR="${ONEDAY_COL}"
test ${DUE} -le ${NOW} && COLOR="${OVERDUE_COL}"
echo "${COLOR}"
}
function _i3print() {
printf "\"color\":\"%s\",\"full_text\":\"%s\"" \
"$(_taskcol "${1}")" \
"$(_taskmsg "${1}")"
}
test "X$(basename -- "$0")" = "Xi3task" && i3task "$@"
test "X$(basename -- "$0")" = "Xi3overdue" && i3tasko "$@"
test "X$(basename -- "$0")" = "Xi3odcnt" && i3odcnt "$@"
# vim: set ft=sh ts=4 sw=4:

44
tools/lxc-snapshot

@ -0,0 +1,44 @@
#!/bin/sh
function lxc-snapshot()
{
local BTRFS=/sbin/btrfs
local CHMOD=/bin/chmod
local CHOWN=/bin/chown
local CUT=/usr/bin/cut
local ECHO=/bin/echo
local GREP=/bin/grep
local ID=/usr/bin/id
local LXC_USERNSEXEC=/usr/bin/lxc-usernsexec
local MKDIR=/bin/mkdir
local SED=/bin/sed
local TEST=/usr/bin/test
local SOURCE=$1
local TARGET=$2
local IP=$3
local SUBUIDS=$(${GREP} ${USER} /etc/subuid)
local SUBGIDS=$(${GREP} ${USER} /etc/subgid)
local SUID_START=$(${ECHO} "${SUBUIDS}" | ${CUT} -d: -f2)
local SGID_START=$(${ECHO} "${SUBGIDS}" | ${CUT} -d: -f2)
local HUID=$(${ID} -u)
local HGID=$(${ID} -g)
${MKDIR} "${HOME}/.local/share/lxc/${TARGET}"
${CHMOD} 770 "${HOME}/.local/share/lxc/${TARGET}"
${SED} 's/'${SOURCE}'/'${TARGET}'/;/lxc.network.ipv4 *=/s/= *.*/= '${IP//\//\\/}'/' \
"${HOME}/.local/share/lxc/${SOURCE}/config" >"${HOME}/.local/share/lxc/${TARGET}/config"
${LXC_USERNSEXEC} -m 'u:0:'${SUID_START}':1' -m 'g:0:'${SGID_START}':1' \
-m 'u:'${HUID}':'${HUID}':1' -m 'g:'${HGID}':'${HGID}':1' -- \
${CHOWN} 0 "${HOME}/.local/share/lxc/${TARGET}"
${LXC_USERNSEXEC} -m 'u:0:'${SUBUIDS#*:} -m 'g:0:'${SUBGIDS#*:} -- \
${BTRFS} subvolume snapshot \
"${HOME}/.local/share/lxc/${SOURCE}/rootfs" \
"${HOME}/.local/share/lxc/${TARGET}/rootfs"
}
export -f lxc-snapshot
# vim: set ft=sh ts=4 sw=4:

40
tools/lxc-start

@ -0,0 +1,40 @@
#!/bin/sh
function lxc-start()
{
local LXC_START=/usr/bin/lxc-start
local TEST=/usr/bin/test
local ECHO=/bin/echo
local MKDIR=/bin/mkdir
local CHOWN=/bin/chown
local SUDO=/usr/bin/sudo
local TEE=/usr/bin/tee
(
PID=$(exec /bin/sh -c 'echo $PPID')
for ctrl in /sys/fs/cgroup/*
do
${TEST} ${ctrl##*/} = 'openrc' && continue
if ${TEST} ! -d ${ctrl}/${USER}
then
${TEST} ${ctrl##*/} = 'cpuset' && \
${ECHO} 1 | ${SUDO} ${TEE} ${ctrl}/cgroup.clone_children >/dev/null
${TEST} ${ctrl##*/} = 'memory' && \
${ECHO} 1 | ${SUDO} ${TEE} ${ctrl}/memory.use_hierarchy >/dev/null
${SUDO} ${MKDIR} ${ctrl}/${USER}/
${SUDO} ${CHOWN} ${USER}: ${ctrl}/${USER}
${SUDO} ${CHOWN} ${USER}: ${ctrl}/${USER}/tasks
${SUDO} ${CHOWN} ${USER}: ${ctrl}/${USER}/cgroup.procs
fi
${ECHO} ${PID} >>"${ctrl}/${USER}/tasks"
done
${LXC_START} $@
)
}
export -f lxc-start
# vim: set ft=sh ts=4 sw=4:

8
tools/mailterms

@ -0,0 +1,8 @@
#!/bin/sh
source ${HOME}/.aliases
source ${HOME}/scripts/init/tools/gcal
test "X$(basename -- "$0")" = "Xmailterms" && mailterms "$@"
# vim: set ft=sh ts=4 sw=4:

116
tools/mdates

@ -0,0 +1,116 @@
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4:

13
tools/rand_printable

@ -0,0 +1,13 @@
#!/bin/sh
function rand_printable() {
local ECHO="/bin/echo"
local TR="/usr/bin/tr"
local HEAD="/usr/bin/head"
${ECHO} -n "`</dev/urandom ${TR} -dc \ -~ | ${HEAD} -c${1:-512}`"
}
test "X$(basename -- "$0")" = "Xrand_printable" && rand_printable "$@"
# vim: set ft=sh ts=4 sw=4:

61
tools/tardiff

@ -0,0 +1,61 @@
#!/bin/bash
##
# Create an unified diff over two tar archives.
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
##
# This one is not POSIX conform. POSIX does not define
# process substitution via <() or >(). The alternative
# I tries is using fifos but doing this with seems to
# be a synchonization nightmare.
#
function tardiff() {
local SED="/bin/sed"
local SORT="/usr/bin/sort"
local TAR="/bin/tar"
local DIFF="/usr/bin/diff"
local XARGS="/usr/bin/xargs"
local BASH="/bin/bash"
if [ 2 -ne $# ]
then
echo "tardiff tar1 tar2"
return 1
fi
local TAR1=$1
local TAR2=$2
local FILES1="${TAR} tfa \"${TAR1}\""
local FILES2="${TAR} tfa \"${TAR2}\""
##
# get the union of all files in both tar's
# Exclude directories.
#
local FILES="${SORT} -u <(${FILES1}) <(${FILES2}) | ${SED} '/\/$/d'"
##
# create a diff over all files and change the /dev/fd/ entries
# with the current filename.
# The resulting diff can be used as a patch on the extracted
# first tar to get the content of the extracted second tar.
#
eval ${FILES} | ${XARGS} -I %file ${BASH} -c "
FILE=\"%file\"
ESC_FILE=\"\${FILE//\//\/}\"
${DIFF} -Nau \
<(${TAR} xfOa \"${TAR1}\" \"%file\" 2>/dev/null) \
<(${TAR} xfOa \"${TAR2}\" \"%file\" 2>/dev/null) | \
${SED} 's/\/dev\/fd\/[0-9]\+/'\${ESC_FILE}'/'"
}
test "X$(basename -- "$0")" = "Xtardiff" && tardiff "$@"
# vim: set ft=sh ts=4 sw=4:

116
tools/tcoming

@ -0,0 +1,116 @@
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4:

116
tools/tcomingf

@ -0,0 +1,116 @@
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4:

116
tools/terms

@ -0,0 +1,116 @@
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4:

116
tools/tpast

@ -0,0 +1,116 @@
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4:

116
tools/ttomorrow

@ -0,0 +1,116 @@
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4:

116
tools/ttomorrowf

@ -0,0 +1,116 @@
#!/bin/sh
##
# various functions and aliases that make gcal more convinient
#
# Author: Georg Hopp <ghopp@bigpoint.net>
# Date: Tue Apr 17 17:19:56 CEST 2012
# Version: 1.0.0
#
alias gcal='LC_MESSAGES=de_DE.UTF-8 /usr/bin/gcal -K -s Monday'
alias hollidays='gcal -qde_hh -n'
alias dates='gcal -c'
alias mdates='gcal -cm'
alias tcomingf='tcoming | sed '\''1!d'\'
alias ttomorrowf='ttomorrow | sed '\''1!d'\'
function terms() {
_terms "all" 1 "$@"
}
function tcoming() {
_terms "coming" 1
}
function tpast() {
_terms "past" 1
}
function ttomorrow() {
_terms "all" 0 -ct
}
function _terms() {
local modifier=${1:-all}
local color=${2:-0}
local current_time=`date +%H:%M`
shift 2
#dates "$@" | sed '1,/^Fixed date/d; /^$/d; s/[^:]*: //'
dates "$@" | awk -v ctime="${current_time}" -v mod="${modifier}" \
-v col=${color} -v format=${DATES_FORMAT} '
BEGIN {
chour = ctime; gsub(/:.*/, "", chour);
cminute = ctime; gsub(/.*:/, "", cminute);
ctime = chour * 60 + cminute
}
NR == 1, /^Fixed date/ {next}
/^$/ {next}
{
gsub(/^[^:]*: /, "");
FS=" ";
hour=$1; gsub(/:.*/, "", hour);
minute=$1; gsub(/.*:/, "", minute);
time = hour * 60 + minute
color=""
if (format == "i3bar") {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\"color\":\"#00FF00\",";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\"color\":\"#FFFF00\",";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\"color\":\"#FF0000\",";
}
else {
if (col != 0 && time != 0 && time-ctime <= 15)
color="\033[38;5;82m";
if (col != 0 && time != 0 && time-ctime <= 5)
color="\033[38;5;190m";
if (col != 0 && time != 0 && time-ctime <= 0)
color="\033[38;5;124m";
}
if ((mod == "all") ||
(mod == "coming" && (time+5 >= ctime || time == 0)) ||
(mod == "past" && (time < ctime || time == 0))) {
gsub(/\\/, "", $0);
if (format == "i3bar") {
gsub(/"/, "\\\"", $0);
out = color "\"full_text\":\"" $0 "\""
}
else {
out = color $0 "\033[00m"
}
print out
}
}
END {
if ("" == out) {
if (format == "i3bar") {
print "\"full_text\":\"none\""
}
else {
print "none"
}
}
}'
}
test "X$(basename -- "$0")" = "Xgcal" && gcal "$@"
test "X$(basename -- "$0")" = "Xhollidays" && hollidays "$@"
test "X$(basename -- "$0")" = "Xdates" && dates "$@"
test "X$(basename -- "$0")" = "Xmdates" && mdates "$@"
test "X$(basename -- "$0")" = "Xtcomingf" && tcomingf "$@"
test "X$(basename -- "$0")" = "Xttomorrowf" && ttomorrowf "$@"
test "X$(basename -- "$0")" = "Xtcoming" && tcoming "$@"
test "X$(basename -- "$0")" = "Xtpast" && tpast "$@"
test "X$(basename -- "$0")" = "Xttomorrow" && ttomorrow "$@"
test "X$(basename -- "$0")" = "Xterms" && terms "$@"
# vim: set ft=sh ts=4 sw=4:

23
vcs.sh

@ -0,0 +1,23 @@
vcs() {
local VCS REF
git_dir() {
[ 'true' != "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ] && return 1
REF=$(git symbolic-ref -q HEAD || git name-rev --name-only HEAD 2>/dev/null)
REF=${REF#refs/heads/}
VCS="git"
}
svn_dir() {
local INFO
INFO="$(svn info 2>/dev/null)" || return 1
REF=$(echo "${INFO}" | awk '/^Repository Root/ { sub(".*/","",$0); r=$0 } /^Revision/ { sub("[^0-9]*","",$0); print r":"$0 }')
VCS="svn"
}
git_dir || svn_dir
echo "${VCS:+[${VCS}|${REF}]}"
}
# vim: set ft=sh ts=4 sw=4:
Loading…
Cancel
Save