aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2022-04-05 11:31:50 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2022-04-05 11:31:50 +0200
commit75f55585aaeaa7bd9fcf2ec144ee8e890128a32a (patch)
treecf049b898b6fad321cdc057758a49d567135d837
parentMan update (diff)
downloadgo2work-75f55585aaeaa7bd9fcf2ec144ee8e890128a32a.tar.gz
go2work-75f55585aaeaa7bd9fcf2ec144ee8e890128a32a.tar.bz2
go2work-75f55585aaeaa7bd9fcf2ec144ee8e890128a32a.tar.xz
go2work-75f55585aaeaa7bd9fcf2ec144ee8e890128a32a.tar.zst
go2work-75f55585aaeaa7bd9fcf2ec144ee8e890128a32a.zip
Added README.org
-rw-r--r--README.org36
-rw-r--r--src/c_defs.go1
-rw-r--r--src/c_go2work.go16
-rw-r--r--src/c_player.go2
-rw-r--r--src/u_checks.go19
-rw-r--r--src/u_prints.go2
6 files changed, 59 insertions, 17 deletions
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..6796918
--- /dev/null
+++ b/README.org
@@ -0,0 +1,36 @@
+#+TITLE: go2work
+
+*go2work* is a small command-line program to help you get up in the morning
+so you can work. It is very inspired from
+[shalarm][https://github.com/jahendrie/shalarm] made originally to learn
+the Go programming language and also because ~shalarm~ didn't work out
+of the box on FreeBSD.
+
+*go2work* has several options and is configurable though a configuration file.
+Refer to
+#+BEGIN_SRC shell
+man go2work
+#+END_SRC
+to get a list of all options.
+
+* Dependencies
+- Go
+- GNU Make
+
+* Installation
+You can get *go2work* through ~git~. The installation is straight forward:
+#+BEGIN_SRC shell
+git clone git://jozanofastora.xyz/jozan/go2work.git
+cd go2work
+make
+sudo make install clean
+#+END_SRC
+Note that on BSD systems you want to use ~gmake~ instead of ~make~:
+#+BEGIN_SRC shell
+gmake
+sudo gmake install clean
+#+END_SRC
+
+* Uninstall
+If you are unhappy with *go2work* because you don't like to work,
+navigate to the
diff --git a/src/c_defs.go b/src/c_defs.go
index 111597b..2815711 100644
--- a/src/c_defs.go
+++ b/src/c_defs.go
@@ -56,6 +56,7 @@ const (
INTERVAL = 500
LOG_FORMAT = "bad time format"
OPTIONS_FILE = PROGNAME + "/" + PROGNAME + ".toml"
+ FORTUNE_BIN = "fortune"
DEF_MEDIA_PLAYER = "mpv"
DEF_RANDOM = false
DEF_FORTUNE = true
diff --git a/src/c_go2work.go b/src/c_go2work.go
index 1103c92..bda98f3 100644
--- a/src/c_go2work.go
+++ b/src/c_go2work.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* go2work: src/c_go2work.go
- * Mon Apr 4 19:31:34 CEST 2022
+ * Tue Apr 5 11:11:13 CEST 2022
* Joe
*
* The main.
@@ -61,7 +61,7 @@ func main() {
var options Options
log.SetPrefix(PROGNAME + ": ")
log.SetFlags(0)
- if len(os.Args[0:]) == 1 {
+ if len(os.Args) == 1 {
print_help()
os.Exit(1)
return
@@ -90,17 +90,7 @@ func main() {
dest_t[SECS] = 0
}
options = parse_options()
- if check_time_format(dest_t) == false {
- log.Fatal(LOG_FORMAT)
- return
- }
- if check_media_player(options.Media_player) == false {
- log.Fatal("media player (" + options.Media_player + ") not found")
- return
- }
- if options.Fortune == true && check_fortune() == false {
- print_fortune_not_found()
- }
+ first_checks(dest_t, options)
curr_t = get_time()
print_time_left(curr_t, dest_t)
main_loop(dest_t, options)
diff --git a/src/c_player.go b/src/c_player.go
index f3485be..1f8130b 100644
--- a/src/c_player.go
+++ b/src/c_player.go
@@ -73,7 +73,7 @@ func exec_player(
var cmd *exec.Cmd
if show_fortune == true && has_rang == false {
fmt.Print("\n\n")
- cmd = exec.Command("fortune", "-s")
+ cmd = exec.Command(FORTUNE_BIN, "-s")
var out bytes.Buffer
cmd.Stdout = &out
cmd.Run()
diff --git a/src/u_checks.go b/src/u_checks.go
index 9a12608..2a67211 100644
--- a/src/u_checks.go
+++ b/src/u_checks.go
@@ -39,7 +39,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* go2work: src/u_checks.go
- * Fri Apr 1 18:30:55 CEST 2022
+ * Tue Apr 5 11:13:23 CEST 2022
* Joe
*
* Useful checks.
@@ -49,6 +49,7 @@ package main
import (
"fmt"
+ "log"
"os"
"os/exec"
)
@@ -63,7 +64,7 @@ func check_media_player(media_player string) bool {
}
func check_fortune() bool {
- cmd := exec.Command("command", "-v", "fortune")
+ cmd := exec.Command("command", "-v", FORTUNE_BIN)
err := cmd.Run()
if err != nil {
return false
@@ -91,3 +92,17 @@ func check_file_exists(file string) bool {
}
return true
}
+
+func first_checks(dest_t [3]byte, options Options) {
+ if check_time_format(dest_t) == false {
+ log.Fatal(LOG_FORMAT)
+ return
+ }
+ if check_media_player(options.Media_player) == false {
+ log.Fatal("media player (" + options.Media_player + ") not found")
+ return
+ }
+ if options.Fortune == true && check_fortune() == false {
+ print_fortune_not_found()
+ }
+}
diff --git a/src/u_prints.go b/src/u_prints.go
index 3831d6b..c2e98b0 100644
--- a/src/u_prints.go
+++ b/src/u_prints.go
@@ -58,6 +58,7 @@ func print_time(t [3]byte) {
func print_time_left(curr_t [3]byte, dest_t [3]byte) {
var left_secs uint
+ curr_t = get_time()
curr_secs := time_to_seconds(curr_t)
dest_secs := time_to_seconds(dest_t)
if curr_secs <= dest_secs {
@@ -111,7 +112,6 @@ func print_version() {
}
func print_fortune_not_found() {
- fmt.Print("\n\n")
log.Println("beware, fortune is set on but was not found")
}