DEV Community

Discussion on: I've automated my morning routine 🤖

Collapse
 
piotroxp profile image
Piotr Słupski

share

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Here's the main script that does most of the stuff:

#!/bin/bash

pushd darkrc
git pull
popd

at 11:55 <<'BASH' 2>/dev/null
  DISPLAY=:0 notify-send 'Pause in 5 minuten'
BASH

at 12:00 <<'BASH' 2>/dev/null
  playerctl pause
  aplay gong.wav &
  DISPLAY=:0 zenity --warning --text 'Es ist 12:00' --title 'Pause!' --width=300 --height=100
BASH

if [ $(date +%w) -lt 5 ];
then
  h_end=16
else
  h_end=14
fi

at $h_end:20 <<'BASH' 2>/dev/null
  export DISPLAY=:0
  notify-send 'Feierabend in 10 minuten'
  GIT_ASKPASS=askpass git-push-pending $HOME/workspace & disown
BASH

at $h_end:30 <<'BASH' 2>/dev/null
  DISPLAY=:0 zenity --warning --text 'Feierabend! JETZT! 🍻' --title 'Feierabend!' --width=300 --height=100
BASH

farfetched ~/workspace

echo ───────────────────────────────────
fortune
echo ───────────────────────────────────

Most of the output is in German, but otherwise it should be fairly easy to follow.

The git-push-pending script is a bit more complex:

#!/bin/sh

(for name in $@; do find -L $name -name '*.git' -type d | sed 's/\/.git$//'; done) \
    | xargs git-pending \
    | grep '^ahead' \
    | lua -e 'for line in io.lines() do print(line:match("[^/]+$")); print((line:gsub("^[^ ]* ", ""))) end' \
    | zenity --list --column Repository --column Path --text "Repositories that need pushing:" --multiple --title "Git" --separator ';' --width 800 --height 300 --print-column=2 2>/dev/null \
    | tr ';' '\n' \
    | xargs -L 1 -I€ sh -c 'cd € && git push'

and it makes use of the git-pending script which looks like this:

#!/bin/sh

for line in $@
do
    dir=$(pwd)
    cd "$line"
    if git log -0 2>/dev/null
    then
        stat=$(git branch -vv | grep -P '^\*' | grep -Po '\[.*\]')
        if echo $stat | grep -P 'behind' > /dev/null
            then echo behind $line
        fi
        if echo $stat | grep -P 'ahead' > /dev/null
            then echo ahead $line
        fi
    fi
    cd $dir
done
Thread Thread
 
dailydevtips1 profile image
Chris Bongers

Awesome, ssst. but I'm posting my GIT status script tomorrow, all build in bash to tell you what your git statusses are.