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
|
||||
|
||||
> 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!
|
||||
|
||||
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.
165
main.go
165
main.go
@ -16,18 +16,15 @@ import (
|
||||
"github.com/akamensky/argparse"
|
||||
)
|
||||
|
||||
const (
|
||||
redirectTo = "127.0.0.1"
|
||||
marker = "## MANAGED BY HYPERFOCUS ##\n"
|
||||
runningOS = runtime.GOOS
|
||||
var (
|
||||
marker string = "## MANAGED BY HYPERFOCUS ##\n"
|
||||
distractorsFile string = "/etc/hyperfocus_distractors"
|
||||
)
|
||||
|
||||
var distractorsFile string = os.Getenv("HOME") + ".hyperfocus_distractors"
|
||||
|
||||
func getHostFile() string {
|
||||
|
||||
var hostFile string
|
||||
switch runningOS {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
hostFile = "/Windows/System32/drivers/etc/hosts"
|
||||
|
||||
@ -40,7 +37,7 @@ func getHostFile() string {
|
||||
|
||||
func resetNetwork(message string) {
|
||||
|
||||
switch runningOS {
|
||||
switch runtime.GOOS {
|
||||
case "windows":
|
||||
cmd := exec.Command("ipconfig /flushdns")
|
||||
if err := cmd.Run(); err != nil {
|
||||
@ -58,7 +55,6 @@ func resetNetwork(message string) {
|
||||
fmt.Println(message)
|
||||
|
||||
case "linux":
|
||||
|
||||
var (
|
||||
usingDnsmasq bool = false
|
||||
usingResolved bool = false
|
||||
@ -176,13 +172,13 @@ func takeBreak(minutes int) {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
|
||||
s := <-c
|
||||
sig := <-c
|
||||
t := minutes * 60
|
||||
for i := t; i > 0; i-- {
|
||||
fmt.Printf("%d seconds remaining", i)
|
||||
time.Sleep(time.Second)
|
||||
|
||||
if s == os.Interrupt {
|
||||
if sig == os.Interrupt {
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -210,6 +206,115 @@ func listDistractors() {
|
||||
// Adds predefined distractors to .hyperfocus_distractors file
|
||||
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() {
|
||||
@ -222,26 +327,30 @@ func main() {
|
||||
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."})
|
||||
|
||||
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")
|
||||
|
||||
err := parser.Parse(os.Args)
|
||||
if err != nil {
|
||||
fmt.Print(parser.Usage(err))
|
||||
}
|
||||
if isRoot() {
|
||||
|
||||
if improveCmd.Happened() {
|
||||
improveFocus()
|
||||
} else if loseCmd.Happened() {
|
||||
loseFocus()
|
||||
} else if breakCmd.Happened() {
|
||||
takeBreak(*minutesForBreak)
|
||||
} else if listCmd.Happened() {
|
||||
listDistractors()
|
||||
} else if predefinedCmd.Happened() {
|
||||
addPredefinedDistractors()
|
||||
err := parser.Parse(os.Args)
|
||||
if err != nil {
|
||||
fmt.Print(parser.Usage(err))
|
||||
}
|
||||
|
||||
if improveCmd.Happened() {
|
||||
improveFocus()
|
||||
} else if loseCmd.Happened() {
|
||||
loseFocus()
|
||||
} else if breakCmd.Happened() {
|
||||
takeBreak(*minutesForBreak)
|
||||
} else if listCmd.Happened() {
|
||||
listDistractors()
|
||||
} else if predefinedCmd.Happened() {
|
||||
addPredefinedDistractors()
|
||||
} else {
|
||||
fmt.Println("Enter a subcommand; use --help or -h for details.")
|
||||
}
|
||||
} else {
|
||||
log.Fatalln("Unknown command")
|
||||
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