sistema_progs

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

.iconlookup (22016B)


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