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