Browse Source

Parametrize maximum line numbers and line length

Alois Mahdal 9 years ago
parent
commit
f52c1baa2a
1 changed files with 9 additions and 4 deletions
  1. 9
    4
      bin/notifirc

+ 9
- 4
bin/notifirc View File

4
 usage() {
4
 usage() {
5
     local self=$(basename "$0")
5
     local self=$(basename "$0")
6
     echo "usage: $self [options] message" >&2
6
     echo "usage: $self [options] message" >&2
7
-    echo "usage: $self [options] -f message_file|-" >&2
7
+    echo "usage: $self [options] [-l max_lines] [-L max_width] -f message_file|-" >&2
8
     echo "options: [-h host] [-p port] [-n nick] [-c context] [-u user]" >&2
8
     echo "options: [-h host] [-p port] [-n nick] [-c context] [-u user]" >&2
9
     exit 2
9
     exit 2
10
 }
10
 }
77
 }
77
 }
78
 
78
 
79
 trim() {
79
 trim() {
80
-    local limit_l=3
81
-    local limit_c=80
80
+    local limit_l=$1
81
+    local limit_c=$2
82
     local lines_read=0
82
     local lines_read=0
83
     local suff=""
83
     local suff=""
84
     while true;
84
     while true;
112
 
112
 
113
 main() {
113
 main() {
114
     local context nick host port user message logfile msgfile
114
     local context nick host port user message logfile msgfile
115
+    local f_maxlines=3 f_maxwidth=80
115
 
116
 
116
     logfile=$(choose_logfile)
117
     logfile=$(choose_logfile)
117
     test -n "$logfile" || {
118
     test -n "$logfile" || {
127
         -c) context=$2; shift 2 || usage ;;
128
         -c) context=$2; shift 2 || usage ;;
128
         -f) msgfile=$2; shift 2 || usage ;;
129
         -f) msgfile=$2; shift 2 || usage ;;
129
         -h) host=$2;    shift 2 || usage ;;
130
         -h) host=$2;    shift 2 || usage ;;
131
+        -l) f_maxlines=$2; shift 2 || usage ;;
132
+        -L) f_maxwidth=$2; shift 2 || usage ;;
130
         -n) nick=$2;    shift 2 || usage ;;
133
         -n) nick=$2;    shift 2 || usage ;;
131
         -p) port=$2;    shift 2 || usage ;;
134
         -p) port=$2;    shift 2 || usage ;;
132
         -u) user=$2;    shift 2 || usage ;;
135
         -u) user=$2;    shift 2 || usage ;;
149
     log "context='$context'"
152
     log "context='$context'"
150
     log "user='$user'"
153
     log "user='$user'"
151
     log "msgfile='$msgfile'"
154
     log "msgfile='$msgfile'"
155
+    log "f_maxlines='$f_maxlines'"
156
+    log "f_maxwidth='$f_maxwidth'"
152
     log "message='$message'"
157
     log "message='$message'"
153
     {
158
     {
154
         test -n "$message" && printf '%s\n' "$message"
159
         test -n "$message" && printf '%s\n' "$message"
155
-        test -n "$msgfile" && grep . "$msgfile" | trim
160
+        test -n "$msgfile" && grep . "$msgfile" | trim "$f_maxlines" "$f_maxwidth"
156
     } \
161
     } \
157
       | mkcommands "$user" "$(mknick)" \
162
       | mkcommands "$user" "$(mknick)" \
158
       | nc "$host" "$port" 2>&1 \
163
       | nc "$host" "$port" 2>&1 \