Skip to content

Instantly share code, notes, and snippets.

@samullen
Last active January 30, 2019 18:46
Show Gist options
  • Save samullen/6497129 to your computer and use it in GitHub Desktop.
Save samullen/6497129 to your computer and use it in GitHub Desktop.
The two most productivity increasing Bash functions ever written.
function worktime {
echo "# WORKTIME" | sudo tee -a /etc/hosts > /dev/null
while read -r line; do
echo "127.0.0.1 ${line}"
done < $HOME/.blocked_sites | sudo tee -a /etc/hosts > /dev/null
}
function slacktime {
flag=0
while read -r line; do
[[ $line =~ "# WORKTIME" ]] && flag=1
[[ $flag -eq 1 ]] && continue
echo $line
done < /etc/hosts > /tmp/hosts
sudo cp /tmp/hosts /etc/hosts
}
@mhutter
Copy link

mhutter commented May 15, 2014

Cool stuff! I also added a block and an unblock function (I am super lazy!)

Also, add this to your sudoers-file to avoid typing your password every time you switck to workmode/slackmode:

username ALL=(root) NOPASSWD: /usr/bin/tee -a /etc/hosts
username ALL=(root) NOPASSWD: /bin/cp /tmp/hosts /etc/hosts

@shime You have to set up a local Webserver listening on Port 80, serving said landing page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment