Last active
January 30, 2019 18:46
-
-
Save samullen/6497129 to your computer and use it in GitHub Desktop.
The two most productivity increasing Bash functions ever written.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
@samullen very helpful, thanks. what's the setup needed for the landing page you describe on your blog post?
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
Two Bash functions to help with productivity:
worktime
appends the contents of$HOME/.blocked_sites
to the end of/etc/hosts
.slacktime
removes the contents added by worktimethe contents of
.blocked_sites
just need to be the domains you want to avoid. One per line.Example:
Attempting to go to sites included in
.blocked_sites
once worktime has been called will send the user to localhost until/etc/hosts
has had those lines removed either manually or by callingslacktime