Browse Source

Add variable docstrings

Alois Mahdal 7 years ago
parent
commit
bb42c44988
1 changed files with 21 additions and 13 deletions
  1. 21
    13
      bin/notifirc

+ 21
- 13
bin/notifirc View File

@@ -11,8 +11,8 @@ usage() {
11 11
 }
12 12
 
13 13
 mkcommands() {
14
-    local user="$1"
15
-    local nick="$2"
14
+    local user="$1"     # target user
15
+    local nick="$2"     # our nickname
16 16
     local message
17 17
     echo "NICK $nick"
18 18
     echo "USER $nick 8 * :notifirc bot"
@@ -31,7 +31,7 @@ mknick() {
31 31
 }
32 32
 
33 33
 die() {
34
-    local msg="fatal: $1"
34
+    local msg="fatal: $1"       # message
35 35
     log "$msg"
36 36
     log "-----END *-----"
37 37
     echo "$msg" >&2
@@ -39,13 +39,13 @@ die() {
39 39
 }
40 40
 
41 41
 warn() {
42
-    local msg="warning: $1"
42
+    local msg="warning: $1"     # full message
43 43
     echo "$msg" >&2
44 44
     log "$msg"
45 45
 }
46 46
 
47 47
 log_pipe() {
48
-    local line
48
+    local line      # each line of input
49 49
     while IFS= read -r line;
50 50
     do
51 51
         log "$line"
@@ -57,7 +57,7 @@ log() {
57 57
 }
58 58
 
59 59
 load_defaults() {
60
-    local rcfile=$1
60
+    local rcfile=$1     # RC file to load
61 61
     test -e "$rcfile" || return 0
62 62
     test -f "$rcfile" || {
63 63
         warn "defaults file is not a file: $rcfile"
@@ -78,10 +78,10 @@ load_defaults() {
78 78
 }
79 79
 
80 80
 trim() {
81
-    local limit_l=$1
82
-    local limit_c=$2
83
-    local lines_read=0
84
-    local suff=""
81
+    local limit_l=$1        # max. lines per message
82
+    local limit_c=$2        # max. chars per line
83
+    local lines_read=0      # how many lines we read
84
+    local suff=""           # suffix (ellipsis)
85 85
     while true;
86 86
     do
87 87
         test $lines_read -ge "$limit_l" && break
@@ -94,7 +94,7 @@ trim() {
94 94
 }
95 95
 
96 96
 choose_logfile() {
97
-    local path
97
+    local path      # path to log file
98 98
     {
99 99
         echo /var/log/notifirc.log
100 100
         echo "$HOME/.notifirc.log"
@@ -112,8 +112,16 @@ choose_logfile() {
112 112
 }
113 113
 
114 114
 main() {
115
-    local context nick host port user message logfile msgfile
116
-    local f_maxlines=3 f_maxwidth=80
115
+    local context           # context tag for nickname
116
+    local nick              # bot's nickname
117
+    local host              # IRC server hostname
118
+    local port              # ... ^^ ... port
119
+    local user              # user to notify
120
+    local message           # message to send
121
+    local logfile           # logfile to use
122
+    local msgfile           # file to read message from
123
+    local f_maxlines=3      # maximum number of lines per notification
124
+    local f_maxwidth=80     # maximum characters per notification line
117 125
 
118 126
     logfile=$(choose_logfile)
119 127
     test -n "$logfile" || {