mirror of
https://codeberg.org/hyperreal/hyperfocus
synced 2024-11-25 12:13:43 +01:00
Implement addPredefinedDistractors; Update README
This commit is contained in:
parent
cea4163dd6
commit
6be135b895
@ -1,7 +1,7 @@
|
|||||||
# go-hyperfocus
|
# go-hyperfocus
|
||||||
|
|
||||||
> Work-In-Progress: Do not use this software. It doesn't work yet. I haven't even compiled it once, so there are likely to be logic errors, and some features aren't fully implemented.
|
> Work-In-Progress: Do not use this software. It doesn't work yet. There are likely to be logic errors, and some features aren't fully implemented.
|
||||||
|
|
||||||
Block distracting websites and hyperfocus on your tasks!
|
Block distracting websites and hyperfocus on your tasks!
|
||||||
|
|
||||||
This is a Go implementation of the Python-written [concentration](https://github.com/timothycrosley/concentration) program. This program aims to be memory-efficient and to allow the user somewhat more freedom in defining distractors than its predecessor.
|
This is a Go implementation of the Python-written [concentration](https://github.com/timothycrosley/concentration) program. This program aims to allow the user somewhat more freedom in defining distractors than its predecessor.
|
||||||
|
BIN
go-hyperfocus
Executable file
BIN
go-hyperfocus
Executable file
Binary file not shown.
137
main.go
137
main.go
@ -16,18 +16,15 @@ import (
|
|||||||
"github.com/akamensky/argparse"
|
"github.com/akamensky/argparse"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
var (
|
||||||
redirectTo = "127.0.0.1"
|
marker string = "## MANAGED BY HYPERFOCUS ##\n"
|
||||||
marker = "## MANAGED BY HYPERFOCUS ##\n"
|
distractorsFile string = "/etc/hyperfocus_distractors"
|
||||||
runningOS = runtime.GOOS
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var distractorsFile string = os.Getenv("HOME") + ".hyperfocus_distractors"
|
|
||||||
|
|
||||||
func getHostFile() string {
|
func getHostFile() string {
|
||||||
|
|
||||||
var hostFile string
|
var hostFile string
|
||||||
switch runningOS {
|
switch runtime.GOOS {
|
||||||
case "windows":
|
case "windows":
|
||||||
hostFile = "/Windows/System32/drivers/etc/hosts"
|
hostFile = "/Windows/System32/drivers/etc/hosts"
|
||||||
|
|
||||||
@ -40,7 +37,7 @@ func getHostFile() string {
|
|||||||
|
|
||||||
func resetNetwork(message string) {
|
func resetNetwork(message string) {
|
||||||
|
|
||||||
switch runningOS {
|
switch runtime.GOOS {
|
||||||
case "windows":
|
case "windows":
|
||||||
cmd := exec.Command("ipconfig /flushdns")
|
cmd := exec.Command("ipconfig /flushdns")
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
@ -58,7 +55,6 @@ func resetNetwork(message string) {
|
|||||||
fmt.Println(message)
|
fmt.Println(message)
|
||||||
|
|
||||||
case "linux":
|
case "linux":
|
||||||
|
|
||||||
var (
|
var (
|
||||||
usingDnsmasq bool = false
|
usingDnsmasq bool = false
|
||||||
usingResolved bool = false
|
usingResolved bool = false
|
||||||
@ -176,13 +172,13 @@ func takeBreak(minutes int) {
|
|||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
signal.Notify(c, os.Interrupt)
|
signal.Notify(c, os.Interrupt)
|
||||||
|
|
||||||
s := <-c
|
sig := <-c
|
||||||
t := minutes * 60
|
t := minutes * 60
|
||||||
for i := t; i > 0; i-- {
|
for i := t; i > 0; i-- {
|
||||||
fmt.Printf("%d seconds remaining", i)
|
fmt.Printf("%d seconds remaining", i)
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
if s == os.Interrupt {
|
if sig == os.Interrupt {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -210,6 +206,115 @@ func listDistractors() {
|
|||||||
// Adds predefined distractors to .hyperfocus_distractors file
|
// Adds predefined distractors to .hyperfocus_distractors file
|
||||||
func addPredefinedDistractors() {
|
func addPredefinedDistractors() {
|
||||||
|
|
||||||
|
distractors := []string{
|
||||||
|
"ycombinator.com",
|
||||||
|
"slashdot.com",
|
||||||
|
"facebook.com",
|
||||||
|
"reddit.com",
|
||||||
|
"gawker.com",
|
||||||
|
"theverge.com",
|
||||||
|
"techcrunch.com",
|
||||||
|
"thenextweb.com",
|
||||||
|
"wired.com",
|
||||||
|
"gizmodo.com",
|
||||||
|
"slickdeals.net",
|
||||||
|
"mashable.com",
|
||||||
|
"digitaltrends.com",
|
||||||
|
"techradar.com",
|
||||||
|
"twitter.com",
|
||||||
|
"tumblr.com",
|
||||||
|
"technorati.com",
|
||||||
|
"digg.com",
|
||||||
|
"buzzfeed.com",
|
||||||
|
"twitter.com",
|
||||||
|
"youtube.com",
|
||||||
|
"netflix.com",
|
||||||
|
"iwastesomuchtime.com",
|
||||||
|
"pinterest.com",
|
||||||
|
"ebay.com",
|
||||||
|
"thepointsguy.com",
|
||||||
|
"imgur.com",
|
||||||
|
"woot.com",
|
||||||
|
"flyertalk.com",
|
||||||
|
"instagram.com",
|
||||||
|
"medium.com",
|
||||||
|
"meetup.com",
|
||||||
|
"distrowatch.com",
|
||||||
|
"arstechnica.com",
|
||||||
|
"phoronix.com",
|
||||||
|
"arstechnica.com",
|
||||||
|
"failblog.com",
|
||||||
|
"redfin.com",
|
||||||
|
"realtor.com",
|
||||||
|
"zillow.com",
|
||||||
|
"trulia.com",
|
||||||
|
"cnn.com",
|
||||||
|
"fox.com",
|
||||||
|
"realclearpolitics.com",
|
||||||
|
"yelp.com",
|
||||||
|
"opentable.com",
|
||||||
|
"slashdot.org",
|
||||||
|
"xkcd.com",
|
||||||
|
"cnet.com",
|
||||||
|
"tomshardware.com",
|
||||||
|
"engadget.com",
|
||||||
|
"zdnet.com",
|
||||||
|
"techrepublic.com",
|
||||||
|
"gizmag.com",
|
||||||
|
"anandtech.com",
|
||||||
|
"imore.com",
|
||||||
|
"gsmarena.com ",
|
||||||
|
"geek.com",
|
||||||
|
"firstpost.com",
|
||||||
|
"wearables.com",
|
||||||
|
"stripgenerator.com",
|
||||||
|
"fmylife.com",
|
||||||
|
"liveplasma.com",
|
||||||
|
"cracked.com",
|
||||||
|
"befunky.com",
|
||||||
|
"pcworld.com",
|
||||||
|
"typepad.com",
|
||||||
|
"pogo.com",
|
||||||
|
"omegle.com",
|
||||||
|
"lifehacker.com",
|
||||||
|
"answerbag.com",
|
||||||
|
"cheezburger.com",
|
||||||
|
"fark.com",
|
||||||
|
"popurls.com",
|
||||||
|
"sho.com",
|
||||||
|
"hulu.com",
|
||||||
|
"myparentsjoinedfacebook.com",
|
||||||
|
"homestarrunner.com",
|
||||||
|
"petsinclothes.com",
|
||||||
|
"freerice.com",
|
||||||
|
"everypoet.com",
|
||||||
|
"mono-1.com",
|
||||||
|
"mcsweeneys.net",
|
||||||
|
"postsecret.com",
|
||||||
|
"textsfromlastnight.com",
|
||||||
|
"awkwardfamilyphotos.com",
|
||||||
|
"myspace.com",
|
||||||
|
"lunchtimers.com",
|
||||||
|
"twitterfall.com",
|
||||||
|
"break.com",
|
||||||
|
"passiveaggressivenotes.com",
|
||||||
|
"sciencemag.org",
|
||||||
|
"bbc.com",
|
||||||
|
"notalwaysright.com",
|
||||||
|
}
|
||||||
|
|
||||||
|
userDistractorsFile, err := os.OpenFile(distractorsFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
defer userDistractorsFile.Close()
|
||||||
|
|
||||||
|
dataWriter := bufio.NewWriter(userDistractorsFile)
|
||||||
|
|
||||||
|
for _, v := range distractors {
|
||||||
|
_, _ = dataWriter.WriteString(v + "\n")
|
||||||
|
}
|
||||||
|
dataWriter.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -222,9 +327,11 @@ func main() {
|
|||||||
breakCmd := parser.NewCommand("break", "Take a break for a number of minutes")
|
breakCmd := parser.NewCommand("break", "Take a break for a number of minutes")
|
||||||
minutesForBreak := breakCmd.Int("", "minutes", &argparse.Options{Help: "Number of minutes to break for."})
|
minutesForBreak := breakCmd.Int("", "minutes", &argparse.Options{Help: "Number of minutes to break for."})
|
||||||
|
|
||||||
listCmd := parser.NewCommand("list", "List the distractors defined in the block file (~/.hyperfocus_distractors)")
|
listCmd := parser.NewCommand("list", "List the distractors defined in the block file (/etc/hyperfocus_distractors)")
|
||||||
predefinedCmd := parser.NewCommand("predefined", "Add predefined set of distractors to block file")
|
predefinedCmd := parser.NewCommand("predefined", "Add predefined set of distractors to block file")
|
||||||
|
|
||||||
|
if isRoot() {
|
||||||
|
|
||||||
err := parser.Parse(os.Args)
|
err := parser.Parse(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Print(parser.Usage(err))
|
fmt.Print(parser.Usage(err))
|
||||||
@ -241,7 +348,9 @@ func main() {
|
|||||||
} else if predefinedCmd.Happened() {
|
} else if predefinedCmd.Happened() {
|
||||||
addPredefinedDistractors()
|
addPredefinedDistractors()
|
||||||
} else {
|
} else {
|
||||||
log.Fatalln("Unknown command")
|
fmt.Println("Enter a subcommand; use --help or -h for details.")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Println("Super user not detected. This program requires root privileges; please re-run with sudo or become root.")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user