sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

.iconlookup (20949B)


      1 #!/usr/bin/env sh
      2 
      3 # Description: Print icons in front of list of directories/files
      4 
      5 # Dependencies: awk
      6 
      7 # Usage
      8 #    1. Set colors and/or icons to your liking
      9 #    2. Pipe any directory listing to iconlookup and it will output prepended icons
     10 #    3. preview-tui uses the script to prepend icon to directory listings
     11 #    4. Aditionally you can consider adding it to your PATH and/or FZF_DEFAULT_COMMAND to
     12 #       make it work with various fzf plugins (make sure you also add --ansi to your FZF_DEFAULT_OPTS)
     13 
     14 # Shell: POSIX compliant
     15 
     16 # Author: Luuk van Baal (https://github.com/luukvbaal/iconlookup)
     17 
     18 icon_lookup() {
     19 awk 'BEGIN {
     20 # Set your ANSI colorscheme below (https://en.wikipedia.org/wiki/ANSI_escape_code#Colors).
     21 # Default uses standard nnn icon colors, 8 and 24-bit nord themes are commented out.
     22     colordepth=8      #colordepth=8        #colordepth=24
     23     color_dirtxt=39   #color_dirtxt=111    #color_dirtxt="129;161;193"
     24     color_filetxt=15  #color_filetxt=111   #color_filetxt="129;161;193"
     25     color_default=39  #color_default=111   #color_default="129;161;193"
     26     color_video=93    #color_video=110     #color_video="136;192;208"
     27     color_audio=220   #color_audio=150     #color_audio="163;190;140"
     28     color_image=82    #color_image=150     #color_image="163;190;140"
     29     color_docs=202    #color_docs=173      #color_docs="208;135;112"
     30     color_archive=209 #color_archive=179   #color_archive="235;203;139"
     31     color_c=81        #color_c=150         #color_c="163;190;140"
     32     color_java=32     #color_java=139      #color_java="180;142;173"
     33     color_js=47       #color_js=109        #color_js="143;188;187"
     34     color_react=39    #color_react=111     #color_react="129;161;193"
     35     color_css=199     #color_css=110       #color_css="136;192;208"
     36     color_python=227  #color_python=68     #color_python="94;129;172"
     37     color_lua=19      #color_lua=167       #color_lua="191;97;106"
     38     color_document=15 #color_document=173  #color_document="208;135;112"
     39     color_fsharp=31   #color_fsharp=179    #color_fsharp="180;142;173"
     40     color_ruby=160    #color_ruby=150      #color_ruby="163;190;140"
     41     color_scala=196   #color_scala=139     #color_scala="143;188;187"
     42     color_shell=47    #color_shell=109     #color_shell="143;188;187"
     43     color_vim=28      #color_vim=109       #color_vim="143;188;187"
     44 
     45 # icons[][1] contains icon and icons[][2] contains color
     46     icons["directory"][1] = ""; icons["directory"][2] = color_default
     47     icons["file"][1] = ""; icons["file"][2] = color_default
     48     icons["exec"][1] = ""; icons["exec"][2] = color_default
     49     icons["manual"][1] = ""; icons["manual"][2] = color_docs
     50     icons["pipe"][1] = "ﳣ"; icons["pipe"][2] = color_default
     51     icons["socket"][1] = "ﳧ"; icons["socket"][2] = color_default
     52     icons["door"][1] = "➡"; icons["door"][2] = color_default
     53 
     54 # top level and common icons
     55     icons[".git"][1] = ""; icons[".git"][2] = color_default
     56     icons["desktop"][1] = "ﲾ"; icons["desktop"][2] = color_default
     57     icons["briefcase"][1] = ""; icons["briefcase"][2] = color_default
     58     icons["document"][1] = ""; icons["document"][2] = color_default
     59     icons["downloads"][1] = ""; icons["downloads"][2] = color_default
     60     icons["music"][1] = ""; icons["music"][2] = color_default
     61     icons["musicfile"][1] = ""; icons["musicfile"][2] = color_audio
     62     icons["pictures"][1] = ""; icons["pictures"][2] = color_default
     63     icons["picturefile"][1] = ""; icons["picturefile"][2] = color_image
     64     icons["public"][1] = ""; icons["public"][2] = color_default
     65     icons["templates"][1] = "陼"; icons["templates"][2] = color_default
     66     icons["videos"][1] = ""; icons["videos"][2] = color_default
     67     icons["videofile"][1] = "ﳜ"; icons["videofile"][2] = color_video
     68     icons["changelog"][1] = ""; icons["changelog"][2] = color_docs
     69     icons["configure"][1] = ""; icons["configure"][2] = color_default
     70     icons["license"][1] = ""; icons["license"][2] = color_docs
     71     icons["makefile"][1] = ""; icons["makefile"][2] = color_default
     72     icons["archive"][1] = ""; icons["archive"][2] = color_archive
     73     icons["script"][1] = ""; icons["script"][2] = color_shell
     74     icons["cplusplus"][1] = ""; icons["cplusplus"][2] = color_c
     75     icons["java"][1] = ""; icons["java"][2] = color_java
     76     icons["clojure"][1] = ""; icons["clojure"][2] = color_default
     77     icons["js"][1] = ""; icons["js"][2] = color_js
     78     icons["linux"][1] = ""; icons["linux"][2] = color_default
     79     icons["fsharp"][1] = ""; icons["fsharp"][2] = color_fsharp
     80     icons["ruby"][1] = ""; icons["ruby"][2] = color_ruby
     81     icons["c"][1] = ""; icons["c"][2] = color_c
     82     icons["chess"][1] = ""; icons["chess"][2] = color_default
     83     icons["haskell"][1] = ""; icons["haskell"][2] = color_vim
     84     icons["html"][1] = ""; icons["html"][2] = color_default
     85     icons["react"][1] = ""; icons["react"][2] = color_react
     86     icons["python"][1] = ""; icons["python"][2] = color_python
     87     icons["database"][1] = ""; icons["database"][2] = color_default
     88     icons["worddoc"][1] = ""; icons["worddoc"][2] = color_document
     89     icons["playlist"][1] = "蘿"; icons["playlist"][2] = color_audio
     90     icons["opticaldisk"][1] = ""; icons["opticaldisk"][2] = color_archive
     91 
     92 # numbers
     93     icons["1"][1] = icons["manual"][1]; icons["1"][2] = icons["manual"][2]
     94     icons["7z"][1] = icons["archive"][1]; icons["7z"][2] = icons["archive"][2]
     95 
     96 # a
     97     icons["a"][1] = icons["manual"][1]; icons["a"][2] = icons["manual"][2]
     98     icons["apk"][1] = icons["archive"][1]; icons["apk"][2] = icons["archive"][2]
     99     icons["asm"][1] = icons["file"][1]; icons["asm"][2] = icons["file"][2]
    100     icons["aup"][1] = icons["musicfile"][1]; icons["aup"][2] = icons["musicfile"][2]
    101     icons["avi"][1] = icons["videofile"][1]; icons["avi"][2] = icons["videofile"][2]
    102 
    103 # b
    104     icons["bat"][1] = icons["script"][1]; icons["bat"][2] = icons["script"][2]
    105     icons["bin"][1] = ""; icons["bin"][2] = color_default
    106     icons["bmp"][1] = icons["picturefile"][1]; icons["bmp"][2] = icons["picturefile"][2]
    107     icons["bz2"][1] = icons["archive"][1]; icons["bz2"][2] = icons["archive"][2]
    108 
    109 # c
    110     icons["cplusplus"][1] = icons["cplusplus"][1]; icons["cplusplus"][2] = icons["cplusplus"][2]
    111     icons["cabal"][1] = icons["haskell"][1]; icons["cab"][2] = icons["haskell"][2]
    112     icons["cab"][1] = icons["archive"][1]; icons["cab"][2] = icons["archive"][2]
    113     icons["cbr"][1] = icons["archive"][1]; icons["cbr"][2] = icons["archive"][2]
    114     icons["cbz"][1] = icons["archive"][1]; icons["cbz"][2] = icons["archive"][2]
    115     icons["cc"][1] = icons["cplusplus"][1]; icons["cc"][2] = icons["cplusplus"][2]
    116     icons["class"][1] = icons["java"][1]; icons["class"][2] = icons["java"][2]
    117     icons["clj"][1] = icons["clojure"][1]; icons["clj"][2] = icons["clojure"][2]
    118     icons["cljc"][1] = icons["clojure"][1]; icons["cljc"][2] = icons["clojure"][2]
    119     icons["cljs"][1] = icons["clojure"][1]; icons["cljs"][2] = icons["clojure"][2]
    120     icons["cmake"][1] = icons["makefile"][1]; icons["cmake"][2] = icons["makefile"][2]
    121     icons["coffee"][1] = ""; icons["coffee"][2] = color_default
    122     icons["conf"][1] = icons["configure"][1]; icons["conf"][2] = icons["configure"][2]
    123     icons["cpio"][1] = icons["archive"][1]; icons["cpio"][2] = icons["archive"][2]
    124     icons["cpp"][1] = icons["cplusplus"][1]; icons["cpp"][2] = icons["cplusplus"][2]
    125     icons["css"][1] = ""; icons["css"][2] = color_css
    126     icons["cue"][1] = icons["playlist"][1]; icons["cue"][2] = icons["playlist"][2]
    127     icons["cvs"][1] = icons["configure"][1]; icons["cvs"][2] = icons["configure"][2]
    128     icons["cxx"][1] = icons["cplusplus"][1]; icons["cxx"][2] = icons["cplusplus"][2]
    129 
    130 # d
    131     icons["db"][1] = icons["database"][1]; icons["db"][2] = icons["database"][2]
    132     icons["deb"][1] = ""; icons["deb"][2] = color_archive
    133     icons["diff"][1] = ""; icons["diff"][2] = color_default
    134     icons["dll"][1] = icons["script"][1]; icons["dll"][2] = icons["script"][2]
    135     icons["doc"][1] = icons["worddoc"][1]; icons["doc"][2] = icons["worddoc"][2]
    136     icons["docx"][1] = icons["worddoc"][1]; icons["docx"][2] = icons["worddoc"][2]
    137 
    138 # e
    139     icons["ejs"][1] = icons["js"][1]; icons["ejs"][2] = icons["js"][2]
    140     icons["elf"][1] = icons["linux"][1]; icons["elf"][2] = icons["linux"][2]
    141     icons["epub"][1] = icons["manual"][1]; icons["epub"][2] = icons["manual"][2]
    142     icons["exe"][1] = icons["exec"][1]; icons["exe"][2] = icons["exec"][2]
    143 
    144 # f
    145     icons["fsharp"][1] = icons["fsharp"][1]; icons["fsharp"][2] = icons["fsharp"][2]
    146     icons["flac"][1] = icons["musicfile"][1]; icons["flac"][2] = icons["musicfile"][2]
    147     icons["fen"][1] = icons["chess"][1]; icons["fen"][2] = icons["chess"][2]
    148     icons["flv"][1] = icons["videofile"][1]; icons["flv"][2] = icons["videofile"][2]
    149     icons["fs"][1] = icons["fsharp"][1]; icons["fs"][2] = icons["fsharp"][2]
    150     icons["fsi"][1] = icons["fsharp"][1]; icons["fsi"][2] = icons["fsharp"][2]
    151     icons["fsscript"][1] = icons["fsharp"][1]; icons["fsscript"][2] = icons["fsharp"][2]
    152     icons["fsx"][1] = icons["fsharp"][1]; icons["fsx"][2] = icons["fsharp"][2]
    153 
    154 # g
    155     icons["gem"][1] = icons["ruby"][1]; icons["gem"][2] = icons["ruby"][2]
    156     icons["gif"][1] = icons["picturefile"][1]; icons["gif"][2] = icons["picturefile"][2]
    157     icons["go"][1] = "ﳑ"; icons["go"][2] = color_default
    158     icons["gz"][1] = icons["archive"][1]; icons["gz"][2] = icons["archive"][2]
    159     icons["gzip"][1] = icons["archive"][1]; icons["gzip"][2] = icons["archive"][2]
    160 
    161 # h
    162     icons["h"][1] = icons["c"][1]; icons["h"][2] = icons["c"][2]
    163     icons["hh"][1] = icons["cplusplus"][1]; icons["hh"][2] = icons["cplusplus"][2]
    164     icons["hpp"][1] = icons["cplusplus"][1]; icons["hpp"][2] = icons["cplusplus"][2]
    165     icons["hs"][1] = icons["haskell"][1]; icons["hs"][2] = icons["haskell"][2]
    166     icons["htaccess"][1] = icons["configure"][1]; icons["htaccess"][2] = icons["configure"][2]
    167     icons["htpasswd"][1] = icons["configure"][1]; icons["htpasswd"][2] = icons["configure"][2]
    168     icons["htm"][1] = icons["html"][1]; icons["htm"][2] = icons["html"][2]
    169     icons["hxx"][1] = icons["cplusplus"][1]; icons["hxx"][2] = icons["cplusplus"][2]
    170 
    171 # i
    172     icons["ico"][1] = icons["picturefile"][1]; icons["ico"][2] = icons["picturefile"][2]
    173     icons["img"][1] = icons["opticaldisk"][1]; icons["img"][2] = icons["opticaldisk"][2]
    174     icons["ini"][1] = icons["configure"][1]; icons["ini"][2] = icons["configure"][2]
    175     icons["iso"][1] = icons["opticaldisk"][1]; icons["iso"][2] = icons["opticaldisk"][2]
    176 
    177 # j
    178     icons["jar"][1] = icons["java"][1]; icons["jar"][2] = icons["java"][2]
    179     icons["java"][1] = icons["java"][1]; icons["java"][2] = icons["java"][2]
    180     icons["jl"][1] = icons["configure"][1]; icons["jl"][2] = icons["configure"][2]
    181     icons["jpeg"][1] = icons["picturefile"][1]; icons["jpeg"][2] = icons["picturefile"][2]
    182     icons["jpg"][1] = icons["picturefile"][1]; icons["jpg"][2] = icons["picturefile"][2]
    183     icons["json"][1] = "ﬥ"; icons["json"][2] = color_js
    184     icons["jsx"][1] = icons["react"][1]; icons["jsx"][2] = icons["react"][2]
    185 
    186 # k
    187 
    188 # l
    189     icons["lha"][1] = icons["archive"][1]; icons["lha"][2] = icons["archive"][2]
    190     icons["lhs"][1] = icons["haskell"][1]; icons["lhs"][2] = icons["haskell"][2]
    191     icons["ilog"][1] = icons["document"][1]; icons["ilog"][2] = icons["document"][2]
    192     icons["lua"][1] = ""; icons["lua"][2] = color_lua
    193     icons["lzh"][1] = icons["archive"][1]; icons["lzh"][2] = icons["archive"][2]
    194     icons["lzma"][1] = icons["archive"][1]; icons["lzma"][2] = icons["archive"][2]
    195 
    196 # m
    197     icons["m"][1] = "ﴜ"; icons["mat"][2] = color_c
    198     icons["m4a"][1] = icons["musicfile"][1]; icons["m4a"][2] = icons["musicfile"][2]
    199     icons["m4v"][1] = icons["videofile"][1]; icons["m4v"][2] = icons["videofile"][2]
    200     icons["mat"][1] = ""; icons["mat"][2] = color_c
    201     icons["markdown"][1] = ""; icons["markdown"][2] = color_docs
    202     icons["md"][1] = ""; icons["md"][2] = color_docs
    203     icons["mk"][1] = icons["makefile"][1]; icons["mk"][2] = icons["makefile"][2]
    204     icons["mkv"][1] = icons["videofile"][1]; icons["mkv"][2] = icons["videofile"][2]
    205     icons["mov"][1] = icons["videofile"][1]; icons["mov"][2] = icons["videofile"][2]
    206     icons["mp3"][1] = icons["musicfile"][1]; icons["mp3"][2] = icons["musicfile"][2]
    207     icons["mp4"][1] = icons["videofile"][1]; icons["mp4"][2] = icons["videofile"][2]
    208     icons["mpeg"][1] = icons["videofile"][1]; icons["mpeg"][2] = icons["videofile"][2]
    209     icons["mpg"][1] = icons["videofile"][1]; icons["mpg"][2] = icons["videofile"][2]
    210     icons["msi"][1] = ""; icons["msi"][2] = color_default
    211 
    212 # n
    213     icons["nix"][1] = ""; icons["nix"][2] = color_fsharp
    214 
    215 # o
    216     icons["o"][1] = icons["manual"][1]; icons["o"][2] = icons["manual"][2]
    217     icons["ogg"][1] = icons["musicfile"][1]; icons["ogg"][2] = icons["musicfile"][2]
    218     icons["odownload"][1] = icons["download"][1]; icons["odownload"][2] = icons["download"][2]
    219     icons["out"][1] = icons["linux"][1]; icons["out"][2] = icons["linux"][2]
    220 
    221 # p
    222     icons["part"][1] = icons["download"][1]; icons["part"][2] = icons["download"][2]
    223     icons["patch"][1] = icons["diff"][1]; icons["patch"][2] = icons["diff"][2]
    224     icons["pdf"][1] = ""; icons["pdf"][2] = color_docs
    225     icons["pgn"][1] = icons["chess"][1]; icons["pgn"][2] = icons["chess"][2]
    226     icons["php"][1] = ""; icons["php"][2] = color_default
    227     icons["png"][1] = icons["picturefile"][1]; icons["png"][2] = icons["picturefile"][2]
    228     icons["ppt"][1] = ""; icons["ppt"][2] = color_default
    229     icons["pptx"][1] = ""; icons["pptx"][2] = color_default
    230     icons["psb"][1] = ""; icons["psb"][2] = color_default
    231     icons["psd"][1] = ""; icons["psd"][2] = color_default
    232     icons["py"][1] = icons["python"][1]; icons["py"][2] = icons["python"][2]
    233     icons["pyc"][1] = icons["python"][1]; icons["pyc"][2] = icons["python"][2]
    234     icons["pyd"][1] = icons["python"][1]; icons["pyd"][2] = icons["python"][2]
    235     icons["pyo"][1] = icons["python"][1]; icons["pyo"][2] = icons["python"][2]
    236 
    237 # q
    238 
    239 # r
    240     icons["rar"][1] = icons["archive"][1]; icons["rar"][2] = icons["archive"][2]
    241     icons["rc"][1] = icons["configure"][1]; icons["rc"][2] = icons["configure"][2]
    242     icons["rom"][1] = ""; icons["rom"][2] = color_default
    243     icons["rpm"][1] = icons["archive"][1]; icons["rpm"][2] = icons["archive"][2]
    244     icons["rss"][1] = "參"; icons["rss"][2] = color_default
    245     icons["rtf"][1] = ""; icons["rtf"][2] = color_default
    246 
    247 # s
    248     icons["sass"][1] = ""; icons["sass"][2] = color_css
    249     icons["scss"][1] = ""; icons["scss"][2] = color_css
    250     icons["so"][1] = icons["manual"][1]; icons["so"][2] = icons["manual"][2]
    251     icons["scala"][1] = ""; icons["scala"][2] = color_scala
    252     icons["sh"][1] = icons["script"][1]; icons["sh"][2] = icons["script"][2]
    253     icons["slim"][1] = icons["script"][1]; icons["slim"][2] = icons["script"][2]
    254     icons["sln"][1] = ""; icons["sln"][2] = color_default
    255     icons["sql"][1] = icons["database"][1]; icons["sql"][2] = icons["database"][2]
    256     icons["srt"][1] = ""; icons["srt"][2] = color_default
    257     icons["isub"][1] = ""; icons["isub"][2] = color_default
    258     icons["svg"][1] = icons["picturefile"][1]; icons["svg"][2] = icons["picturefile"][2]
    259 
    260 # t
    261     icons["tar"][1] = icons["archive"][1]; icons["tar"][2] = icons["archive"][2]
    262     icons["tex"][1] = ""; icons["tex"][2] = color_default
    263     icons["tgz"][1] = icons["archive"][1]; icons["tgz"][2] = icons["archive"][2]
    264     icons["ts"][1] = ""; icons["ts"][2] = color_js
    265     icons["tsx"][1] = icons["react"][1]; icons["tsx"][2] = icons["react"][2]
    266     icons["txt"][1] = icons["document"][1]; icons["txt"][2] = icons["document"][2]
    267     icons["txz"][1] = icons["archive"][1]; icons["txz"][2] = icons["archive"][2]
    268 
    269 # u
    270 
    271 # v
    272     icons["vid"][1] = icons["videofile"][1]; icons["vid"][2] = icons["videofile"][2]
    273     icons["vim"][1] = ""; icons["vim"][2] = color_vim
    274     icons["vimrc"][1] = ""; icons["vimrc"][2] = color_vim
    275     icons["vtt"][1] =  ""; icons["vtt"][2] = color_default
    276 # w
    277     icons["wav"][1] = icons["musicfile"][1]; icons["wav"][2] = icons["musicfile"][2]
    278     icons["webm"][1] = icons["videofile"][1]; icons["webm"][2] = icons["videofile"][2]
    279     icons["wma"][1] = icons["videofile"][1]; icons["wma"][2] = icons["videofile"][2]
    280     icons["wmv"][1] = icons["videofile"][1]; icons["wmv"][2] = icons["videofile"][2]
    281 
    282 # x
    283     icons["xbps"][1] = icons["archive"][1]; icons["xbps"][2] = color_archive
    284     icons["xcf"][1] = icons["picturefile"][1]; icons["xcf"][2] = color_image
    285     icons["xhtml"][1] = icons["html"][1]; icons["xhtml"][2] = icons["html"][2]
    286     icons["xls"][1] = ""; icons["xls"][2] = color_default
    287     icons["xlsx"][1] = ""; icons["xlsx"][2] = color_default
    288     icons["xml"][1] = icons["html"][1]; icons["xml"][2] = icons["html"][2]
    289     icons["xz"][1] = icons["archive"][1]; icons["xz"][2] = icons["archive"][2]
    290 
    291 # y
    292     icons["yaml"][1] = icons["configure"][1]; icons["yaml"][2] = icons["configure"][2]
    293     icons["yml"][1] = icons["configure"][1]; icons["yml"][2] = icons["configure"][2]
    294 # z
    295     icons["zip"][1] = icons["archive"][1]; icons["zip"][2] = icons["archive"][2]
    296     icons["zsh"][1] = icons["script"][1]; icons["zsh"][2] = icons["script"][2]
    297     icons["zst"][1] = icons["archive"][1]; icons["zst"][2] = icons["archive"][2]
    298 
    299     FS = "."
    300     limit = ENVIRON["limit"]
    301     switch (colordepth) {
    302         case "4":
    303             escape="\033["
    304             break;
    305         case "8":
    306             escape="\033[38;5;"
    307             break;
    308         case "24":
    309             escape="\033[38;2;"
    310             break;
    311     }
    312     bstr = ENVIRON["beforestr"]
    313 }
    314 {
    315     # dont print cwd . and leading ./ from tree -f
    316     if ($0 ~/^\.$/)
    317         next
    318     ent = ($0 ~/^\.\//) ? substr($0, 3, length($0) - 2) : $0
    319     ext = $NF
    320 
    321     # Print icons, set color and bold directories by using ansi escape codes
    322     if (ext in icons)
    323         printcolor(icons[ext][1], icons[ext][2], color_filetxt, ent, "10")
    324     else
    325         switch (substr(ent, length(ent), 1)) {
    326             case "/":
    327                 printcolor(icons["directory"][1], color_default, color_dirtxt, ent, "1")
    328                 break;
    329             case "*":
    330                 printcolor(icons["exe"][1], color_default, color_filetxt, ent, "10")
    331                 break;
    332             case "|":
    333                 printcolor(icons["pipe"][1], color_default, color_filetxt, ent, "10")
    334                 break;
    335             case "=":
    336                 printcolor(icons["socket"][1], color_default, color_filetxt, ent, "10")
    337                 break;
    338             case ">":
    339                 printcolor(icons["door"][1], color_default, color_filetxt, ent, "10")
    340                 break;
    341             default:
    342                 printcolor(icons["file"][1], color_default, color_filetxt, ent, "10")
    343         }
    344 }
    345 function printcolor(i, c, d, n, b) {
    346     if (limit != "" && length(n) + 2 > limit)
    347         n = substr(n, 1, limit - 2)
    348     printf "\033[0m"
    349     printf "%s%s%s;%sm%s %s%sm%s\n", bstr, escape, c, b, i, escape, d, n
    350 }'
    351 printf '\033[0m'
    352 }
    353 
    354 print_begin() {
    355     printf '%s\n' "$1" | sed 's/\\n/\n/g'
    356 }
    357 
    358 print_end() {
    359     printf '%s\n' "$1" | sed 's/\\n/\n/g'
    360 }
    361 
    362 print_help() {
    363     printf 'Icon Lookup\n
    364 Usage:
    365     iconlookup [options]
    366     iconlookup [-bBe] [string]
    367     iconlookup -l [number]
    368     iconlookup (-h | --help)
    369 
    370     Prepend icons to list of files based on extension or appended indicator by ls/tree "-F" flag ("/" for directory, "*" for executable etc.)
    371 
    372 Options:
    373     -h --help -?         Show this screen.
    374     -b --before          Prepend str before icon.
    375     -B --begin           Prepend str before output.
    376     -e --end             Append str after output.
    377     -l --limit           Limit line length to [number] characters.'
    378 }
    379 
    380 while :; do
    381     case $1 in
    382         -h|-\?|--help)
    383             print_help
    384             exit ;;
    385         -B|--begin)
    386             if [ -n "$2" ]; then
    387                 print_begin "$2"
    388             fi
    389             shift ;;
    390         -e|--end)
    391             if [ -n "$2" ]; then
    392                 end=1
    393                 endstr="$2"
    394             fi
    395             shift ;;
    396         -b|--before)
    397             if [ -n "$2" ]; then
    398                 export beforestr="$2"
    399             fi
    400             shift ;;
    401         -l|--limit)
    402             if [ -n "$2" ]; then
    403                 export limit="$2"
    404                 shift
    405             else
    406                 printf 'ERROR: "--limit" requires a non-empty option argument.\n'
    407                 exit
    408             fi ;;
    409         --)
    410             shift
    411             break ;;
    412         -?*)
    413             printf 'WARNING: Unknown option ignored: %s\n' "$1" ;;
    414         *) break ;;
    415     esac
    416     shift
    417 done
    418 
    419 if [ ! -t 0 ]; then
    420     [ -n "$beforestr" ] && limit="$((limit - ${#beforestr}))"
    421     icon_lookup
    422 else
    423     printf 'ERROR: no data provided...\nExpecting a directory listing in stdin\n'
    424 fi
    425 
    426 if [ -n "$end" ]; then
    427     print_end "$endstr"
    428 fi