DEV Community

loading...
Cover image for I've automated my morning routine

I've automated my morning routine

dailydevtips1 profile image Chris Bongers Originally published at daily-dev-tips.com 2 min read

Call me lazy, but I just love automating things.
Today we are automating my morning routine.

You may be wondering what that routine is.

  • Make coffee (Shit, we won't automate this, Yet!)
  • Open 10 tabs

Yes, that last part we are automating using the magic and mighty bash!

See here how cool this project is:

bash chrome opening

Bash opening browser tabs

Note: This script is written/tested on Mac and can differ for you on different machines.

First, we will be making a plain old .txt file that will hold all the pages we want to open:

https://hashnode.com/
https://daily-dev-tips.com/
https://twitter.com/
Enter fullscreen mode Exit fullscreen mode

Now we will be making a bash script to open all browser tabs:

alias google-chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
while read line; do
    google-chrome --new-tab "$line"
done < ~/www/browser-hack/list.txt
Enter fullscreen mode Exit fullscreen mode

I have defined the alias for google-chrome; I think on windows, you can leave the alias out (untested).

Then we will loop through each line defined in list.txt and call google chrome to open a new tab for that website.

Next, we can add an alias to make it even cooler:

alias morning=~/path/to/script/bash.sh
Enter fullscreen mode Exit fullscreen mode

Now in your terminal type: morning and see the magic happen

Voila, we just hacked our morning routine to be that much quicker!

You can find this project on Github: Browser-hack

Thank you for reading, and let's connect!

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter

Discussion (27)

pic
Editor guide
Collapse
darkwiiplayer profile image
DarkWiiPlayer

At work I have a today script that recursively fetches every git repo in my ~/workspace, sets some at timers to remind me of break time and calls fortune at the end :D

It also brings up a list of unpushed repositories at the end of the day and lets me select which ones I want automatically pushed.

Collapse
piotroxp profile image
Collapse
darkwiiplayer profile image
DarkWiiPlayer

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 Author

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

Collapse
dailydevtips1 profile image
Chris Bongers Author

What that sounds amazing actually what a great idea!!

Collapse
crimsonmed profile image
M矇d矇ric Burlet

Technically you could automate the coffee with bash. It has been done before:

github.com/NARKOZ/hacker-scripts

Check the fu*ng-coffee.sh and fu*ng-coffee.rb

Collapse
dailydevtips1 profile image
Chris Bongers Author

Jep, would be lovely to have a internet connected coffee machine

Collapse
nombrekeff profile image
Manolo Edge

Ohh that would be nice, offering some hacker the option to make coffee for you lol

Just kidding, it would be awesome, I thought about it before

Thread Thread
dailydevtips1 profile image
Chris Bongers Author

Haha isnt that what interns are for?

Collapse
mhatvan profile image
Markus Hatvan

Cool post Chris, it makes sense to automate the morning routine if you can save time with it!

I used to automate my routine at the last company too.
When the computer boots:

  • open terminal, launch multiple tabs with frontend/backend/database connection
  • open VSCode
  • open LibreOffice todo notes
  • open Postman
  • open Email client

I just couldn't automate the work unfortunately :P

Collapse
dailydevtips1 profile image
Chris Bongers Author

Seems like a good startup script Markus!

Perhaps GPT-3 could automate your work?
I still want to see if it can write blogposts for me

Collapse
mhatvan profile image
Markus Hatvan

Probably, I am scared of GPT-3 becoming too powerful :P

Yes, I want that too! Tell me about it when a blog post starts writing itself :D

Thread Thread
dailydevtips1 profile image
Collapse
leonardomaier profile image
Leonardo Maier

You could also pin the tabs to chrome, it would have the same behaviour

Collapse
dailydevtips1 profile image
Chris Bongers Author

Yeah, but let cool :P does pinning also work on reboot? (might be, I never use it)

Collapse
leonardomaier profile image
Leonardo Maier

Yes, it works. Actually, I found out this feature recently, that's why I shared it here, I used to make scripts like that too.

Thread Thread
dailydevtips1 profile image
Chris Bongers Author

That's awesome! Nice feature indeed

Collapse
ben profile image
Ben Halpern

This is really cool!

Make coffee (Shit, we won't automate this, Yet!)

I came here for something like this. No reason this can't be automated!

Collapse
dailydevtips1 profile image
Chris Bongers Author

Getting my arduino in soon, might use it for something like that 儭

Collapse
jmr_code_social profile image
Jorge Marquez

Love it man!!
I have my Linux to ask me if I want to check logs from remote servers whenever I turn on my computer.

Automation is life!!!!

Collapse
dailydevtips1 profile image
Chris Bongers Author

That sounds amazing Jorge!
Nice to see so many people into automation

Collapse
mofiqul profile image
Mofiqul Islam

I use a tiling window manager in Linux and Everything is ready in assigned workspaces as soon as I boot my pc.

Collapse
dailydevtips1 profile image
Chris Bongers Author

That's cool! Linux is so much easier though

Collapse
andrewbaisden profile image
Andrew Baisden

Nice living in the future with all of these automated workflows.

Collapse
dailydevtips1 profile image
Chris Bongers Author

It could be way more automated with some raspberry pi's and wifi adopted machines.

Collapse
alekseiberezkin profile image
Aleksei Berezkin

How about just not turning off a computer?

Collapse
dailydevtips1 profile image
Chris Bongers Author

Mac for instance gets so bloated if you don't fully turn them off every now and then