fzf-urlview (1025B)
1 #!/usr/bin/env bash 2 # via fzf wiki 3 # https://github.com/D630/bin/ 4 # 5 # Simple replacement for urlview using fzf in X. 6 # 7 # Usage: 8 # 9 # $ furlview FILE1 ... FILEn 10 # $ foo | furlview 11 # $ furlview < FILE 12 # $ furlview <<< "foo" 13 # $ furlview <<URIS 14 ## foo 15 ## URIS 16 # 17 # FILE is regular or piped, that is also <(foo) 18 19 function __x_web_browser { 20 setsidw x-web-browser "$1"; 21 }; 22 23 function __fzf { 24 fzf --tac -e -i -m; 25 }; 26 27 function __ugrep { 28 grep-urls; 29 }; 30 31 function __select { 32 __ugrep | 33 __fzf; 34 }; 35 36 function __is_file [[ -p $1 || -f $1 ]]; 37 38 if 39 __is_file /dev/stdin; 40 then 41 mapfile -t furls < <(__select); 42 else 43 (($#)) || { 44 printf %s\\n aaarg? 1>&2; 45 exit 1; 46 }; 47 mapfile -t furls < <( 48 for a; do 49 if 50 __is_file "$a"; 51 then 52 cat -- "$a"; 53 else 54 printf 'File %s is neather a regular file nor a named pipe, that is executable' "$a" 1>&2; 55 exit 1; 56 fi; 57 done | 58 __select; 59 ); 60 fi; 61 62 case $DISPLAY in 63 ('') 64 ! :;; 65 (*) 66 for u in "${furls[@]}"; do 67 __x_web_browser "$u" & 68 done; 69 wait;; 70 esac; 71 72 # vim: set ft=sh :