File: nossui

package info (click to toggle)
noss 1.10-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 704 kB
  • sloc: perl: 6,571; sh: 569; xml: 294; makefile: 2
file content (736 lines) | stat: -rw-r--r-- 16,727 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
#!/bin/sh

PRGNAM=nossui

NOSS_CONFIG=
NOSS_FEEDS=
NOSS_DATA=

export DIALOG_CANCEL=1
export DIALOG_ERROR=-1
export DIALOG_ESC=255
export DIALOG_EXTRA=3
export DIALOG_HELP=2
export DIALOG_ITEM_HELP=2
export DIALOG_TIMEOUT=5
export DIALOG_OK=0

export DIALOGOPTS="--backtitle $PRGNAM"

SORT_OPT='--reverse --sort date'

# Disable globbing
set -f

print_help() {

    cat <<HERE
Usage: $PRGNAM [options] ...

Options:
  -c <file>   Specify path to configuration file
  -D <dir>    Specify path to data directory
  -f <file>   Specify path to feeds file

  -h   Print this usage message
  -v   Print nossui version/copyright info
HERE

}

print_version() {

    noss -v | sed -e 's/noss/nossui/'

}

die() {
    printf "%s\n" "$1" 1>&2
    exit 1
}

wnoss() {

    if [ -n "$NOSS_CONFIG" ]
    then
        set -- '--config' "$NOSS_CONFIG" "$@"
    fi

    if [ -n "$NOSS_FEEDS" ]
    then
        set -- '--feeds' "$NOSS_FEEDS" "$@"
    fi

    if [ -n "$NOSS_DATA" ]
    then
        set -- '--data' "$NOSS_DATA" "$@"
    fi

    noss --autoclean 0 "$@"


}

dialog_read_post() {

    wnoss read $(printf "%s" "$1" | sed -e 's/:/ /')

}

dialog_open_post() {

    wnoss open $(printf "%s" "$1" | sed -e 's/:/ /')

}

dialog_update() {

    wnoss update "$@" 2>&1 | dialog \
        --title 'Updating' \
        --programbox 'Updating...' -1 -1

}

dialog_reload() {

    wnoss reload "$@" 2>&1 | dialog \
        --title 'Reloading' \
        --programbox 'Reloading...' -1 -1

}

dialog_mark_read() {

    wnoss mark read "$@"

    if [ "$?" = '0' ]
    then
        dialog --msgbox "$* has been marked as read." 0 0
    else
        dialog --msgbox "Could not mark $* as read." 0 0
    fi

}

dialog_mark_unread() {

    wnoss mark unread "$@"

    if [ "$?" = '0' ]
    then
        dialog --msgbox "$* has been marked as unread." 0 0
    else
        dialog --msgbox "Could not mark $* as unread." 0 0
    fi


}

dialog_info_post() {

    dialog \
        --no-collapse \
        --msgbox "$(wnoss post $(printf "%s" "$1" | sed -e 's/:/ /'))" 0 0

}

dialog_select_post() {

    dialog_select_post_tmpsel="$(mktemp)"

    while true; do

        dialog \
            --title "$1" \
            --erase-on-exit \
            --menu 'Please select an action for this post.' 0 0 0 \
            'Read'        'Read post in pager' \
            'Open'        'Open post in browser' \
            'Mark Read'   'Mark post as read' \
            'Mark Unread' 'Mark post as unread' \
            'Info'        'View more post information' \
            2> "$dialog_select_post_tmpsel"

        if [ "$?" != "$DIALOG_OK" ]
        then
            break
        fi

        case "$(cat "$dialog_select_post_tmpsel")" in
            'Read')
                dialog_read_post "$1"
            ;;
            'Open')
                dialog_open_post "$1"
            ;;
            'Mark Read')
                dialog_mark_read $(printf "%s" "$1" | sed -e 's/:/ /')
            ;;
            'Mark Unread')
                dialog_mark_unread $(printf "%s" "$1" | sed -e 's/:/ /')
            ;;
            'Info')
                dialog_info_post "$1"
            ;;
        esac

    done

    rm -f "$dialog_select_post_tmpsel"

}

dialog_select_sort() {

    dialog_select_sort_tmpsel="$(mktemp)"

    dialog \
        --menu "How would you like $PRGNAM to sort posts?" 0 0 0 \
        'Date'  'Sort posts by date (default)' \
        'Feed'  'Sort posts by their feed alphabetically' \
        'Title' 'Sort posts by their titles alphabetically' \
        2> "$dialog_select_sort_tmpsel"

    if [ "$?" != "$DIALOG_OK" ]
    then
        rm -f "$dialog_select_sort_tmpsel"
        return
    fi

    case "$(cat "$dialog_select_sort_tmpsel")" in
        'Date')
            SORT_OPT='--reverse --sort date'
        ;;
        'Feed')
            SORT_OPT='--sort feed'
        ;;
        'Title')
            SORT_OPT='--sort title'
        ;;
    esac

    rm -f "$dialog_select_sort_tmpsel"

}

dialog_posts() {

    dialog_posts_tmpposts="$(mktemp)"
    dialog_posts_tmpsel="$(mktemp)"

    remember_post=

    while true; do

        wnoss list "$@" \
            --list-format "$(printf "%%f:%%i\n(%%s) %%t")" \
            --list-limit 0 \
            $SORT_OPT | \
            perl -plE '$_ = "\"" . s/\"/\\"/gr . "\""' \
            > "$dialog_posts_tmpposts"

        if [ ! -s "$dialog_posts_tmpposts" ]
        then
            dialog --msgbox 'No posts were found' 0 0
            rm -f "$dialog_posts_tmpposts" "$dialog_posts_tmpsel"
            return
        fi

        dialog \
            --erase-on-exit \
            --ok-label 'Read' \
            --extra-button --extra-label 'Actions' \
            --cancel-label 'Sort' \
            --help-button --help-label 'Cancel' \
            $remember_post \
            --menu 'Please select a post to view' 0 0 0 \
            --file "$dialog_posts_tmpposts" \
            2> "$dialog_posts_tmpsel"

        case "$?" in
            "$DIALOG_OK")
                remember_post="--default-item $(cat "$dialog_posts_tmpsel")"
                dialog_read_post "$(cat "$dialog_posts_tmpsel")"
            ;;
            "$DIALOG_EXTRA")
                remember_post="--default-item $(cat "$dialog_posts_tmpsel")"
                dialog_select_post "$(cat "$dialog_posts_tmpsel")"
            ;;
            "$DIALOG_CANCEL")
                remember_post=
                dialog_select_sort
            ;;
            *)
                break
            ;;
        esac

    done

    rm -f "$dialog_posts_tmpsel" "$dialog_posts_tmpposts"

}

dialog_search() {

    search_title=
    search_content=
    search_feedgroup=
    search_tags=
    search_status=
    search_hidden='0'

    dialog_search_tmpform="$(mktemp)"

    while true; do

        dialog \
            --ok-label 'Search' \
            --form 'Please enter your search parameters.' 0 0 0 \
            'Title'      1 0 "$search_title"     1 12 18 255 \
            'Content'    2 0 "$search_content"   2 12 18 255 \
            'Feed/Group' 3 0 "$search_feedgroup" 3 12 18 255 \
            'Tags'       4 0 "$search_tags"      4 12 18 255 \
            'Status'     5 0 "$search_status"    5 12 18 255 \
            'Hidden'     6 0 "$search_hidden"    6 12 18 1 \
            2> "$dialog_search_tmpform"

        if [ "$?" != "$DIALOG_OK" ]
        then
            break
        fi

        set --

        while IFS= read -r line; do
            set -- "$@" "$line"
        done < "$dialog_search_tmpform"

        search_title="$1"
        search_content="$2"
        search_feedgroup="$3"
        search_tags="$4"
        search_status="$5"
        search_hidden="$6"

        set --

        if [ -n "$search_title" ]
        then
            set -- "$@" '--title' "$search_title"
        fi

        if [ -n "$search_content" ]
        then
            set -- "$@" '--content' "$search_content"
        fi

        if [ -n "$search_tags" ]
        then
            for tag in $search_tags; do
                set -- "$@" '--tag' "$tag"
            done
        fi

        if [ "$search_status" = 'read' ]
        then
            set -- "$@" '--status' 'read'
        elif [ "$search_status" = 'unread' ]
        then
            set -- "$@" '--status' 'unread'
        elif [ -n "$search_status" ]
        then
            dialog --msgbox "'status' must either be 'read' or 'unread'." 0 0
            continue
        fi

        if [ "$search_hidden" = '1' ]
        then
            set -- "$@" '--hidden'
        elif [ -n "$search_hidden" ] && [ "$search_hidden" != '0' ]
        then
            dialog --msgbox "'hidden' must either be '1' or '0'" 0 0
            continue
        fi

        if [ -n "$search_feedgroup" ]
        then
            for feedgroup in $search_feedgroup; do
                set -- "$@" "$feedgroup"
            done
        fi

        dialog_posts "$@"

    done

    rm -f "$dialog_search_tmpform"

}

dialog_info_feed() {

    dialog \
        --no-collapse \
        --msgbox "$(wnoss feeds "$1")" 0 0

}

dialog_open_feed() {

    dialog_open_feed_err="$(mktemp)"

    wnoss open "$1" 2> "$dialog_open_feed_err"

    if [ "$?" != '0' ]
    then
        dialog \
            --title "Failed to open $1" \
            --msgbox "$(cat "$dialog_open_feed_err")" 0 0
    fi

    rm -f "$dialog_open_feed_err"

}

dialog_select_feed() {

    dialog_select_feed_tmpsel="$(mktemp)"

    while true; do

        dialog \
            --title "$1" \
            --ok-label 'Select' \
            --menu 'Please select an action to perform.' 0 0 0 \
            'Posts'       "View all posts in $1" \
            'Open'        "Open $1's homepage in a browser" \
            'Mark Read'   "Mark all posts in $1 as read" \
            'Mark Unread' "Mark all posts in $1 as unread" \
            'Update'      "Update $1" \
            'Reload'      "Reload $1" \
            'Info'        "View $1 feed information" \
            2> "$dialog_select_feed_tmpsel"

        if [ "$?" != '0' ]
        then
            break
        fi

        case "$(cat "$dialog_select_feed_tmpsel")" in
            'Posts')
                dialog_posts "$1"
            ;;
            'Open')
                dialog_open_feed "$1"
            ;;
            'Mark Read')
                dialog_mark_read "$1"
            ;;
            'Mark Unread')
                dialog_mark_unread "$1"
            ;;
            'Update')
                dialog --yesno "Would you like to update $1?" 0 0
                if [ "$?" != '0' ]
                then
                    continue
                fi
                dialog_update "$1"
            ;;
            'Reload')
                dialog --yesno "Would you like to reload $1?" 0 0
                if [ "$?" != '0' ]
                then
                    continue
                fi
                dialog_reload "$1"
            ;;
            'Info')
                dialog_info_feed "$1"
            ;;
        esac

    done

    rm -f "$dialog_select_feed_tmpsel"

}

dialog_feeds() {

    dialog_feeds_tmpsel="$(mktemp)"
    dialog_feeds_tmpfeeds="$(mktemp)"

    while true; do

        wnoss feeds "$@" \
            --feeds-format "$(printf "%%f\n%%t")" | \
            perl -plE '$_ = "\"" . s/\"/\\"/gr . "\""' \
            > "$dialog_feeds_tmpfeeds"

        if [ ! -s "$dialog_feeds_tmpfeeds" ]
        then
            dialog --msgbox 'No feeds were found' 0 0
            break
        fi

        dialog \
            --ok-label 'Posts' \
            --extra-button --extra-label 'Actions' \
            --menu 'Please select a feed to view' 0 0 0 \
            --file "$dialog_feeds_tmpfeeds" \
            2> "$dialog_feeds_tmpsel"

        case "$?" in
            "$DIALOG_OK")
                dialog_posts "$(cat "$dialog_feeds_tmpsel")"
            ;;
            "$DIALOG_EXTRA")
                dialog_select_feed "$(cat "$dialog_feeds_tmpsel")"
            ;;
            *)
                break
            ;;
        esac

    done

    rm -f "$dialog_feeds_tmpsel" "$dialog_feeds_tmpfeeds"

}

dialog_select_group() {

    dialog_select_group_tmpsel="$(mktemp)"

    while true; do

        dialog \
            --ok-label 'Select' \
            --menu 'Please select an action to perform for this group.' 0 0 0 \
            'Posts'       'View list of posts from this group' \
            'Feeds'       'View list of feeds in this group' \
            'Mark Read'   'Mark all posts in this group as read' \
            'Mark Unread' 'Mark all posts in this group as unread' \
            'Update'      'Update all feeds in this group' \
            'Reload'      'Reload all feeds in this group' \
            2> "$dialog_select_group_tmpsel"

        if [ "$?" != "$DIALOG_OK" ]
        then
            break
        fi

        case "$(cat "$dialog_select_group_tmpsel")" in
            'Posts')
                dialog_posts "$1"
            ;;
            'Feeds')
                dialog_feeds "$1"
            ;;
            'Mark Read')
                dialog_mark_read "$1"
            ;;
            'Mark Unread')
                dialog_mark_unread "$1"
            ;;
            'Update')
                dialog --yesno "Would you like to update the feeds in $1?" 0 0
                if [ "$?" != '0' ]
                then
                    continue
                fi
                dialog_update "$1"
            ;;
            'Reload')
                dialog --yesno "Would you like to reload the feeds in $1?" 0 0
                if [ "$?" != '0' ]
                then
                    continue
                fi
                dialog_reload "$1"
            ;;
        esac

    done

    rm -f "$dialog_select_group_tmpsel"

}

dialog_groups() {

    dialog_groups_tmpsel="$(mktemp)"
    dialog_groups_tmpgroups="$(mktemp)"

    while true; do

        wnoss groups --brief > "$dialog_groups_tmpgroups"

        if  [ ! -s "$dialog_groups_tmpgroups" ]
        then
            dialog --msgbox 'No feed groups were found' 0 0
            break
        fi

        dialog \
            --ok-label 'Posts' \
            --extra-button --extra-label 'Actions' \
            --no-items \
            --menu 'Please select a group to view.' 0 0 0 \
            --file "$dialog_groups_tmpgroups" \
            2> "$dialog_groups_tmpsel"

        case "$?" in
            "$DIALOG_OK")
                dialog_posts "$(cat "$dialog_groups_tmpsel")"
            ;;
            "$DIALOG_EXTRA")
                dialog_select_group "$(cat "$dialog_groups_tmpsel")"
            ;;
            *)
                break
            ;;
        esac

    done

    rm -f "$dialog_groups_tmpsel" "$dialog_groups_tmpgroups"

}

dialog_clean() {

    dialog --infobox 'Cleaning up...' 0 0

    wnoss clean

    dialog --msgbox 'Finished cleanup.' 0 0

}

dialog_main() {

    dialog_main_tmpsel="$(mktemp)"

    while true; do

        dialog \
            --erase-on-exit \
            --menu 'Please select a menu item.' 0 0 0 \
            'Posts' 'View all posts' \
            'Unread' 'View unread posts' \
            'Search' 'Search for posts that match given parameters' \
            'Feeds' 'Browse your feeds' \
            'Groups' 'Browse your feed groups' \
            'Update' 'Fetch and load feed updates' \
            'Reload' 'Reload feed cache' \
            'Clean' 'Clean up feed cache and database' \
            2> "$dialog_main_tmpsel"

        if [ "$?" != "$DIALOG_OK" ]
        then
            rm -f "$dialog_main_tmpsel"
            exit 0
        fi

        case "$(cat "$dialog_main_tmpsel")" in
            'Posts')
                dialog_posts
            ;;
            'Unread')
                dialog_posts --status 'unread'
            ;;
            'Search')
                dialog_search
            ;;
            'Feeds')
                dialog_feeds
            ;;
            'Groups')
                dialog_groups
            ;;
            'Update')
                dialog --yesno "Would you like to update all of your feeds?" 0 0
                if [ "$?" != '0' ]
                then
                    continue
                fi
                dialog_update
            ;;
            'Reload')
                dialog --yesno "Would you like to reload all of your feeds?" 0 0
                if [ "$?" != '0' ]
                then
                    continue
                fi
                dialog_reload
            ;;
            'Clean')
                dialog_clean
            ;;
        esac

    done

    rm -f "$dialog_main_tmpsel"

}

main() {

    if [ ! -x "$(command -v noss)" ]
    then
        die "noss is not installed or is not in PATH"
    fi

    if [ ! -x "$(command -v "dialog")" ]
    then
        die "dialog is not installed or is not in PATH"
    fi

    while getopts 'c:D:f:hv' opt
    do
        case "$opt" in
            'c')
                NOSS_CONFIG="$OPTARG"
            ;;
            'D')
                NOSS_DATA="$OPTARG"
            ;;
            'f')
                NOSS_FEEDS="$OPTARG"
            ;;
            'h')
                print_help
                exit 0
            ;;
            'v')
                print_version
                exit 0
            ;;
            '?')
                print_help 1>&2
                exit 1
            ;;
        esac
    done

    if [ -n "$NOSS_CONFIG" ] && [ ! -f "$NOSS_CONFIG" ]
    then
        die "$NOSS_CONFIG does not exist"
    fi

    if [ -n "$NOSS_FEEDS" ] && [ ! -f "$NOSS_FEEDS" ]
    then
        die "$NOSS_FEEDS does not exist"
    fi

    dialog_main

}

main "$@"

# vim: expandtab shiftwidth=4