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
 }
11
 }
12
 
12
 
13
 mkcommands() {
13
 mkcommands() {
14
-    local user="$1"
15
-    local nick="$2"
14
+    local user="$1"     # target user
15
+    local nick="$2"     # our nickname
16
     local message
16
     local message
17
     echo "NICK $nick"
17
     echo "NICK $nick"
18
     echo "USER $nick 8 * :notifirc bot"
18
     echo "USER $nick 8 * :notifirc bot"
31
 }
31
 }
32
 
32
 
33
 die() {
33
 die() {
34
-    local msg="fatal: $1"
34
+    local msg="fatal: $1"       # message
35
     log "$msg"
35
     log "$msg"
36
     log "-----END *-----"
36
     log "-----END *-----"
37
     echo "$msg" >&2
37
     echo "$msg" >&2
39
 }
39
 }
40
 
40
 
41
 warn() {
41
 warn() {
42
-    local msg="warning: $1"
42
+    local msg="warning: $1"     # full message
43
     echo "$msg" >&2
43
     echo "$msg" >&2
44
     log "$msg"
44
     log "$msg"
45
 }
45
 }
46
 
46
 
47
 log_pipe() {
47
 log_pipe() {
48
-    local line
48
+    local line      # each line of input
49
     while IFS= read -r line;
49
     while IFS= read -r line;
50
     do
50
     do
51
         log "$line"
51
         log "$line"
57
 }
57
 }
58
 
58
 
59
 load_defaults() {
59
 load_defaults() {
60
-    local rcfile=$1
60
+    local rcfile=$1     # RC file to load
61
     test -e "$rcfile" || return 0
61
     test -e "$rcfile" || return 0
62
     test -f "$rcfile" || {
62
     test -f "$rcfile" || {
63
         warn "defaults file is not a file: $rcfile"
63
         warn "defaults file is not a file: $rcfile"
78
 }
78
 }
79
 
79
 
80
 trim() {
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
     while true;
85
     while true;
86
     do
86
     do
87
         test $lines_read -ge "$limit_l" && break
87
         test $lines_read -ge "$limit_l" && break
94
 }
94
 }
95
 
95
 
96
 choose_logfile() {
96
 choose_logfile() {
97
-    local path
97
+    local path      # path to log file
98
     {
98
     {
99
         echo /var/log/notifirc.log
99
         echo /var/log/notifirc.log
100
         echo "$HOME/.notifirc.log"
100
         echo "$HOME/.notifirc.log"
112
 }
112
 }
113
 
113
 
114
 main() {
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
     logfile=$(choose_logfile)
126
     logfile=$(choose_logfile)
119
     test -n "$logfile" || {
127
     test -n "$logfile" || {