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 | |
} |
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
@samullen very helpful, thanks. what's the setup needed for the landing page you describe on your blog post?