Guest User

cmdfetch_edit

a guest
May 20th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 33.63 KB | None | 0 0
  1. --[[
  2. TO DO:
  3. - Option to center logo vertically
  4. - Richard Stallman face logo
  5. - Brackets
  6. - IRC option
  7. - Fancy text option
  8. - Several information thingy's
  9. - MPD albums
  10. - % CPU,GPU usage
  11. ]]
  12. --___________________________CONFIG___________________________--
  13.  
  14. local       useLineName = true
  15. local     useLineKernel = false
  16. local         useLineOS = true
  17. local     useLineMemory = false
  18. local     useLineUptime = false
  19. local      useLineTheme = true
  20. local        useLineRes = true
  21. local        useLineCPU = false
  22. local        useLineGPU = false
  23. local        useLineHDD = false
  24. local     useLineBblean = true --If possible
  25. --____________________________________________________________--
  26.  
  27. function warning()
  28.     print("\nThis version of CMDFetch uses Ansicon.")
  29.     print("For all you loyal CMDFetch users, Ansicon replaces \"colous.exe\"")
  30.     print("  Download Ansicon here:")
  31.     print("  http://adoxa.3eeweb.com/ansicon/")
  32.     print("Alternatively, a Cygwin PTY can be used. We recommend Mintty,")
  33.     print("It comes with Cygwin.\n")
  34.     print("If none of these options work for you, you can try it out with")
  35.     print("the \"-c none\" flag\n")
  36.     print("NOTICE: Windows 8 Users should use Ansicon x86 regardless of")
  37.     print("their architecture")
  38.     return
  39. end
  40.  
  41. local failedAnsiconTest = (io.popen("echo.%ANSICON%","r"):read() == "%ANSICON%")
  42. local terminal = io.popen("2>nul bash -c \"echo $TERM\""):read()
  43. if terminal then
  44.     local failedCygwinTest = not (terminal:find("xterm") or terminal:find("rxvt"))
  45. else
  46.     failedCygwinTest = true
  47. end
  48. local canColor = not (failedCygwinTest and failedAnsiconTest)
  49.  
  50. local          resetColor = "\027[0m"
  51. local                logo = "windows7"
  52. local    black,lightBlack = "\027[0;30m","\027[1;30m"
  53. local        red,lightRed = "\027[0;31m","\027[1;31m"
  54. local    green,lightGreen = "\027[0;32m","\027[1;32m"
  55. local  yellow,lightYellow = "\027[0;33m","\027[1;33m"
  56. local      blue,lightBlue = "\027[0;34m","\027[1;34m"
  57. local  violet,lightViolet = "\027[0;35m","\027[1;35m"
  58. local      cyan,lightCyan = "\027[0;36m","\027[1;36m"
  59. local    white,lightWhite = "\027[0;37m","\027[1;37m"
  60. local              colors = {}
  61.            colors["blue"] = {blue,lightBlue}
  62.          colors["yellow"] = {yellow,lightYellow}
  63.             colors["red"] = {red,lightRed}
  64.           colors["green"] = {green,lightGreen}
  65.          colors["violet"] = {violet,lightViolet}
  66.            colors["cyan"] = {cyan,lightCyan}
  67.           colors["black"] = {black,lightBlack}
  68.           colors["white"] = {white,lightWhite}
  69.            colors["none"] = {}
  70. local          colorNames = {"blue","yellow","red","green","violet","cyan","black","white","none"}
  71. local              bright = false
  72. local             minimal = false
  73. local                dull = false
  74. local     moreThanOneLine = true
  75. local               align = false
  76. local               lefty = false
  77. local                 gay = false
  78.    
  79. local logos = {
  80.  
  81.  
  82. ["windows7"] = {
  83.         "${c1} xxxxxxxxxxxxxxxxxxxxxx ${c3}xxxxxxxxxxxxxxxxxxxxxx %s",
  84.         "${c1} xxxxxxxxxxxxxxxxxxxxxx ${c3}xxxxxxxxxxxxxxxxxxxxxx %s",
  85.         "${c1} xxxxxxxxxxxxxxxxxxxxxx ${c3}xxxxxxxxxxxxxxxxxxxxxx %s",
  86.         "${c1} xxxxxxxxxxxxxxxxxxxxxx ${c3}xxxxxxxxxxxxxxxxxxxxxx %s",
  87.         "${c1} xxxxxxxxxxxxxxxxxxxxxx ${c3}xxxxxxxxxxxxxxxxxxxxxx %s",
  88.         "${c1} xxxxxxxxxxxxxxxxxxxxxx ${c3}xxxxxxxxxxxxxxxxxxxxxx %s",
  89.        
  90.         "${c3} xxxxxxxxxxxxxxxxxxxxxx ${c1}xxxxxxxxxxxxxxxxxxxxxx %s",
  91.         "${c3} xxxxxxxxxxxxxxxxxxxxxx ${c1}xxxxxxxxxxxxxxxxxxxxxx %s",
  92.         "${c3} xxxxxxxxxxxxxxxxxxxxxx ${c1}xxxxxxxxxxxxxxxxxxxxxx %s",
  93.         "${c3} xxxxxxxxxxxxxxxxxxxxxx ${c1}xxxxxxxxxxxxxxxxxxxxxx %s",
  94.         "${c3} xxxxxxxxxxxxxxxxxxxxxx ${c1}xxxxxxxxxxxxxxxxxxxxxx %s",
  95.         "${c3} xxxxxxxxxxxxxxxxxxxxxx ${c1}xxxxxxxxxxxxxxxxxxxxxx %s",
  96.         "${c1}                       ${c3}                      %s",
  97.         ["colors"] = {lightWhite,lightGreen,red,lightYellow}
  98. },
  99.  
  100.     ["windows"] = {
  101.         "${c1}              ##               %s",
  102.         "${c1}            ######             %s",
  103.         "${c1}          ##########           %s",
  104.         "${c1}        ##############         %s",
  105.         "${c3}      ##  ${c1}##########  ${c2}##       %s",
  106.         "${c3}    ######  ${c1}######  ${c2}######     %s",
  107.         "${c3}  ##########  ${c1}##  ${c2}##########   %s",
  108.         "${c3}##############  ${c2}############## %s",
  109.         "${c3}  ##########  ${c4}##  ${c2}##########   %s",
  110.         "${c3}    ######  ${c4}######  ${c2}######     %s",
  111.         "${c3}      ##  ${c4}##########  ${c2}##       %s",
  112.         "${c4}        ${c4}##############         %s",
  113.         "${c4}          ##########           %s",
  114.         "${c4}            ######             %s",
  115.         "${c4}              ##               %s",
  116.         ["colors"] = {lightRed,lightGreen,lightCyan,lightYellow}
  117.     },
  118.     ["legacy"] = {
  119.         "${c1}   ____              %s",
  120.         "${c1} _/    \\_  ${c2}_      _  %s",
  121.         "${c1}|        |${c2}| \\____/ | %s",
  122.         "${c1}|        |${c2}|        | %s",
  123.         "${c1}|  ____  |${c2}|        | %s",
  124.         "${c1}|_/${c3}____${c1}\\_|${c2}|_      _| %s",
  125.         "${c3} _/    \\_  ${c4}_${c2}\\____/${c4}_  %s",
  126.         "${c3}|        |${c4}| \\____/ | %s",
  127.         "${c3}|        |${c4}|        | %s",
  128.         "${c3}|  ____  |${c4}|        | %s",
  129.         "${c3}|_/    \\_|${c4}|_      _| %s",
  130.         "${c4}            \\____/   %s",
  131.         ["colors"] = {lightRed,lightGreen,lightCyan,lightYellow}
  132.     },
  133.     ["windows8"] = {
  134.         "${c1}                         ....:::: %s",
  135.         "${c1}                 ....:::::::::::: %s",
  136.         "${c1}        ....:::: :::::::::::::::: %s",
  137.         "${c1}....:::::::::::: :::::::::::::::: %s",
  138.         "${c1}:::::::::::::::: :::::::::::::::: %s",
  139.         "${c1}:::::::::::::::: :::::::::::::::: %s",
  140.         "${c1}:::::::::::::::: :::::::::::::::: %s",
  141.         "${c1}:::::::::::::::: :::::::::::::::: %s",
  142.         "${c1}................ ................ %s",
  143.         "${c1}:::::::::::::::: :::::::::::::::: %s",
  144.         "${c1}:::::::::::::::: :::::::::::::::: %s",
  145.         "${c1}:::::::::::::::: :::::::::::::::: %s",
  146.         "${c1}:::::::::::::::: :::::::::::::::: %s",
  147.         "${c1}'''':::::::::::: :::::::::::::::: %s",
  148.         "${c1}        '''':::: :::::::::::::::: %s",
  149.         "${c1}                 '''':::::::::::: %s",
  150.         "${c1}                         '''':::: %s",
  151.         ["colors"] = {lightBlue}
  152.     },
  153.     ["none"] = {
  154.         "%s",
  155.         ["colors"] = {resetColor}
  156.     },
  157.     ["gentoo"] = {
  158.         "${c2}         -/oyddmdhs+:.               %s",
  159.         "${c2}     -o${c1}dNMMMMMMMMNNmhy+${c2}-\`            %s",
  160.         "${c2}   -y${c1}NMMMMMMMMMMMNNNmmdhy${c2}+-          %s",
  161.         "${c2} \`o${c1}mMMMMMMMMMMMMNmdmmmmddhhy${c2}/\`       %s",
  162.         "${c2} om${c1}MMMMMMMMMMMN${c2}hhyyyo${c1}hmdddhhhd${c2}o\`     %s",
  163.         "${c2}.y${c1}dMMMMMMMMMMd${c2}hs++so/s${c1}mdddhhhhdm${c2}+\`   %s",
  164.         "${c2} oy${c1}hdmNMMMMMMMN${c2}dyooy${c1}dmddddhhhhyhN${c2}d.  %s",
  165.         "${c2}  :o${c1}yhhdNNMMMMMMMNNNmmdddhhhhhyym${c2}Mh  %s",
  166.         "${c2}    .:${c1}+sydNMMMMMNNNmmmdddhhhhhhmM${c2}my  %s",
  167.         "${c2}       /m${c1}MMMMMMNNNmmmdddhhhhhmMNh${c2}s:  %s",
  168.         "${c2}    \`o${c1}NMMMMMMMNNNmmmddddhhdmMNhs${c2}+\`   %s",
  169.         "${c2}  \`s${c1}NMMMMMMMMNNNmmmdddddmNMmhs${c2}/.     %s",
  170.         "${c2} /N${c1}MMMMMMMMNNNNmmmdddmNMNdso${c2}:\`       %s",
  171.         "${c2}+M${c1}MMMMMMNNNNNmmmmdmNMNdso${c2}/-          %s",
  172.         "${c2}yM${c1}MNNNNNNNmmmmmNNMmhs+/${c2}-\`            %s",
  173.         "${c2}/h${c1}MMNNNNNNNNMNdhs++/${c2}-\`               %s",
  174.         "${c2}\`/${c1}ohdmmddhys+++/:${c2}.\`                  %s",
  175.         "${c2}  \`-//////:--.                       %s",
  176.         ["colors"] = {lightWhite,lightViolet}
  177.     },
  178.     ["linux"] = {
  179.         "${c2}         #####              %s",
  180.         "${c2}        #######             %s",
  181.         "${c2}        ##${c1}O${c2}#${c1}O${c2}##             %s",
  182.         "${c2}        #${c3}#####${c2}#             %s",
  183.         "${c2}      ##${c1}##${c3}###${c1}##${c2}##           %s",
  184.         "${c2}     #${c1}##########${c2}##          %s",
  185.         "${c2}    #${c1}############${c2}##         %s",
  186.         "${c2}    #${c1}############${c2}###        %s",
  187.         "${c3}   ##${c2}#${c1}###########${c2}##${c3}#        %s",
  188.         "${c3} ######${c2}#${c1}#######${c2}#${c3}######      %s",
  189.         "${c3} #######${c2}#${c1}#####${c2}#${c3}#######      %s",
  190.         "${c3}   #####${c2}#######${c3}#####        %s",
  191.         ["colors"] = {lightWhite,lightBlack,lightYellow}
  192.     },
  193.     ["openbsd"] = {
  194.         "                                       ${c3} _  %s",
  195.         "                                       ${c3}(_) %s",
  196.         "${c1}              |    .                       %s",
  197.         "${c1}          .   |L  /|   .         ${c3} _        %s",
  198.         "${c1}      _ . |\\ _| \\--+._/| .       ${c3}(_)       %s",
  199.         "${c1}     / ||\\| Y J  )   / |/| ./              %s",
  200.         "${c1}    J  |)'( |        \` F\`.'/       ${c3} _      %s",
  201.         "${c1}  -<|  F         __     .-<        ${c3}(_)     %s",
  202.         "${c1}    | /       .-'${c3}. ${c1}\`.  /${c3}-. ${c1}L___            %s",
  203.         "${c1}    J \\      <    ${c3}\\ ${c1} | | ${c5}O${c3}\\${c1}|.-' ${c3} _         %s",
  204.         "${c1}  _J \\  .-    \\${c3}/ ${c5}O ${c3}| ${c1}| \\  |${c1}F    ${c3}(_)        %s",
  205.         "${c1} '-F  -<_.     \\   .-'  \`-' L__            %s",
  206.         "${c1}__J  _   _.     >-'  ${c2})${c4}._.   ${c1}|-'            %s",
  207.         "${c1} \`-|.'   /_.          ${c4}\\_|  ${c1} F              %s",
  208.         "${c1}  /.-   .                _.<               %s",
  209.         "${c1} /'    /.'             .'  \`\\              %s",      
  210.         "${c1}  /L  /'   |/      _.-'-\\                  %s",
  211.         "${c1} /'J       ___.---'\\|                      %s",
  212.         "${c1}   |\\  .--' V  | \`. \`                      %s",
  213.         "${c1}   |/\`. \`-.     \`._)                       %s",
  214.         "${c1}      / .-.\\                               %s",
  215.         "${c1}      \\ (  \`\\                              %s",
  216.         "${c1}       \`.\\                                 %s",
  217.         ["colors"] = {lightYellow,yellow,lightCyan,lightRed,lightBlack}
  218.     },
  219.     ["dragonflybsd"] = {
  220.         "                     ${c1} |                     %s",
  221.         "                    ${c1} .-.                    %s",
  222.         "                   ${c3} ()${c1}I${c3}()                   %s",
  223.         "              ${c1} \"==.__:-:__.==\"              %s",
  224.         "              ${c1}\"==.__/~|~\\__.==\"             %s",
  225.         "              ${c1}\"==._(  Y  )_.==\"             %s",
  226.         "   ${c2}.-'~~\"\"~=--...,__${c1}\\/|\\/${c2}__,...--=~\"\"~~'-.  %s",
  227.         "  ${c2}(               ..=${c1}\\=${c1}/${c2}=..               ) %s",
  228.         "   ${c2}\`'-.        ,.-\"\`;${c1}/=\\${c2} ;\"-.,_        .-'\` %s",
  229.         "      ${c2} \`~\"-=-~\` .-~\` ${c1}|=|${c2} \`~-. \`~-=-\"~\`      %s",
  230.         "       ${c2}     .-~\`    /${c1}|=|${c2}\\    \`~-.           %s",
  231.         "       ${c2}  .~\`       / ${c1}|=|${c2} \\       \`~.        %s",
  232.         " ${c2}    .-~\`        .'  ${c1}|=|${c2}  \\\`.        \`~-.   %s",
  233.         " ${c2}  (\`     _,.-=\"\`  ${c1}  |=|${c2}    \`\"=-.,_     \`)  %s",
  234.         " ${c2}   \`~\"~\"\`        ${c1}   |=|${c2}           \`\"~\"~\`   %s",
  235.         "                   ${c1}  /=\\                    %s",
  236.         "                   ${c1}  \\=/                           %s",
  237.         "                   ${c1}   ^                            %s",
  238.         ["colors"] = {lightRed,lightWhite,lightYellow}
  239.     },
  240.     ["trisquel"] = {
  241.         "${c1}                          \220\220\220\220\220\220      %s",
  242.         "${c1}                       \220\219\219\219\219\219\219\219\219\219\220    %s",
  243.         "${c1}       \220\220\220\220\220\220         \219\219\219\219\223   \223\219\219\219\219   %s",
  244.         "${c1}    \220\219\219\219\219\219\219\219\219\219\219\220     \219\219\219\219\223   \220\220 \223\219\219\219  %s",
  245.         "${c1}  \220\219\219\219\223\223   \223\223\219\219\219\219     \219\219\219\220   \220\219   \219\219\219 %s",
  246.         "${c1} \220\219\219\219   \220\220\220   \219\219\219\219\220    \223\219\219\219\219\219\219   \220\219\219\219 %s",
  247.         "${c1} \219\219\219   \219\223\223\219\219\220  \219\219\219\219\219\220     \223\223   \220\219\219\219\219  %s",
  248.         "${c1} \223\219\219\219      \219\219\219  \219\219\219\219\219\219\219\220\220  \220\220\219\219\219\219\219\219   %s",
  249.         "${c1}  \223\219\219\219\220   \220\219\219\219  \219\219\219\219\219\219\219\219\219\219\219\219\219${c2}\219\219\219\219\223    %s",
  250.         "${c1}   \223\219\219\219\219\219\219\219\219\219    \219\219\219\219\219\219\219${c2}\219\219\219\223\223\223        %s",
  251.         "${c1}     \223\223\219\219\219\223\223     \219\219${c2}\219\219\219\219\223\223             %s",
  252.         "${c2}                \219\219\219\219\219\219\223   \220\220\220\220        %s",
  253.         "${c2}               \219\219\219\219\219\223   \219\219\219\219\219\219\219\219      %s",
  254.         "${c2}               \219\219\219\219\219   \219\219\219\223  \223\219\219\219     %s",
  255.         "${c2}                \219\219\219\219\220   \219\219\220\220\220  \219\219\219    %s",
  256.         "${c2}                 \219\219\219\219\219\220   \223\223  \220\219\219     %s",
  257.         "${c2}                   \219\219\219\219\219\219\220\220\220\219\219\219\219      %s",
  258.         "${c2}                      \223\223\219\219\219\219\219\223\223       %s",
  259.         ["colors"] = {lightBlue,blue}
  260.     },
  261.     ["debian"] = {
  262.         "${c1}       _,met$$$\$$gg.        %s",
  263.         "${c1}    ,g$$$$$$$$$$$$$$$P.     %s",
  264.         "${c1}  ,g$$P\"\"       \"\"\"Y$$.\".   %s",
  265.         "${c1} ,$$P'              `$$$.   %s",
  266.         "${c1}',$$P       ,ggs.     `$$b: %s",
  267.         "${c1}`d$$'     ,$P\"\'   ${c2}.${c1}    $$$  %s",
  268.         "${c1} $$P      d$\'     ${c2},${c1}    $$P  %s",
  269.         "${c1} $$:      $$.   ${c2}-${c1}    ,d$$'  %s",
  270.         "${c1} $$\;      Y$b._   _,d\$P'    %s",
  271.         "${c1} Y$$.    ${c2}`.${c1}`\"Y$$$$P\"'       %s",
  272.         "${c1} `$$b      ${c2}\"-.__            %s",
  273.         "${c1}  `Y$$                      %s",
  274.         "${c1}   `Y$$.                    %s",
  275.         "${c1}     `$$b.                  %s",
  276.         "${c1}       `Y$$b.               %s",
  277.         "${c1}          `\"Y$b._           %s",
  278.         "${c1}              `\"\"\"\"         %s",
  279.         ["colors"] = {lightRed,red}
  280.     },
  281.     ["scientific"] = {
  282.     "${c1}                  =/;;/-                    %s",
  283.     "${c1}                 +:    //                   %s",
  284.     "${c1}                /;      /;                  %s",
  285.     "${c1}               -X        H.                 %s",
  286.     "${c1} .//;;;:;;-,   X=        :+   .-;:=;:;#;.   %s",
  287.     "${c1} M-       ,=;;;#:,      ,:#;;:=,       ,@   %s",
  288.     "${c1} :#           :#.=/++++/=.$=           #=   %s",
  289.     "${c1}  ,#;         #/:+/;,,/++:+/         ;+.    %s",
  290.     "${c1}    ,+/.    ,;@+,        ,#H;,    ,/+,      %s",
  291.     "${c1}       ;+;;/= @.  ${c2}.H${c3}#${c2}#X   ${c1}-X :///+;         %s",
  292.     "${c1}       ;+=;;;.@,  ${c3}.X${c2}M${c3}@$.  ${c1}=X.//;=#/.        %s",
  293.     "${c1}    ,;:      :@#=        =$H:     .+#-      %s",
  294.     "${c1}  ,#=         #;-///==///-//         =#,    %s",
  295.     "${c1} ;+           :#-;;;:;;;;-X-           +:   %s",
  296.     "${c1} @-      .-;;;;M-        =M/;;;-.      -X   %s",
  297.     "${c1}  :;;::;;-.    #-        :+    ,-;;-;:==    %s",
  298.     "${c1}               ,X        H.                 %s",
  299.     "${c1}                ;/      #=                  %s",
  300.     "${c1}                 //    +;                   %s",
  301.     "${c1}                  '////'                    %s",
  302.         ["colors"] = {lightBlue,lightRed,lightWhite}
  303.     },
  304.     ["arch"] = {
  305.         "${c1}                   -`                 %s",
  306.         "${c1}                  .o+`                %s",
  307.         "${c1}                 `ooo/                %s",
  308.         "${c1}                `+oooo:               %s",
  309.         "${c1}               `+oooooo:              %s",
  310.         "${c1}               -+oooooo+:             %s",
  311.         "${c1}             `/:-:++oooo+:            %s",
  312.         "${c1}            `/++++/+++++++:           %s",
  313.         "${c1}           `/++++++++++++++:          %s",
  314.         "${c1}          `/+++o${c2}oooooooo${c1}oooo/`        %s",
  315.         "${c2}         ${c1}./${c2}ooosssso++osssssso${c1}+`       %s",
  316.         "${c2}        .oossssso-````/ossssss+`      %s",
  317.         "${c2}       -osssssso.      :ssssssso.     %s",
  318.         "${c2}      :osssssss/        osssso+++.    %s",
  319.         "${c2}     /ossssssss/        +ssssooo/-    %s",
  320.         "${c2}   `/ossssso+/:-        -:/+osssso+-  %s",
  321.         "${c2}  `+sso+:-`                 `.-/+oso: %s",
  322.         "${c2} `++:.                           `-/+/ %s",
  323.         "${c2} .`                                 `/ %s",
  324.         ["colors"] = {lightCyan,cyan}
  325.     },
  326.     ["oldarch"] = {
  327.         "${c1}              __                     %s",
  328.         "${c1}          _=(SDGJT=_                 %s",
  329.         "${c1}        _GTDJHGGFCVS)                %s",
  330.         "${c1}       ,GTDJGGDTDFBGX0               %s",
  331.         "${c1}      JDJDIJHRORVFSBSVL${c2}-=+=,_        %s",
  332.         "${c1}     IJFDUFHJNXIXCDXDSV,${c2}  \"DEBL      %s",
  333.         "${c1}    [LKDSDJTDU=OUSCSBFLD.${c2}   '?ZWX,   %s",
  334.         "${c1}   ,LMDSDSWH'     `DCBOSI${c2}     DRDS], %s",
  335.         "${c1}   SDDFDFH'         !YEWD,${c2}   )HDROD  %s",
  336.         "${c1}  !KMDOCG            &GSU|${c2}\\_GFHRGO\\' %s",
  337.         "${c1}  HKLSGP'${c2}           __${c1}\\TKM0${c2}\\GHRBV)'  %s",
  338.         "${c1} JSNRVW'${c2}       __+MNAEC${c1}\\IOI,${c2}\\BN'     %s",
  339.         "${c1} HELK['${c2}    __,=OFFXCBGHC${c1}\\FD)         %s",
  340.         "${c1} ?KGHE ${c2}\\_-#DASDFLSV='${c1}    'EF         %s",
  341.         "${c1} 'EHTI                    !H         %s",
  342.         "${c1}  `0F'                    '!         %s",
  343.         ["colors"] = {lightWhite,lightBlue}
  344.     }
  345. }
  346.  
  347. function errorString(str)
  348.     if canColor then
  349.         print(lightRed.."Error: "..str)
  350.         print("See --help"..resetColor)
  351.     else
  352.         print("Error: "..str)
  353.         print("See --help")
  354.     end
  355. end
  356.  
  357. function lineFromFile(file,num)
  358.     it=1
  359.     for line in file:lines() do
  360.         if num == it then
  361.             return line
  362.         end
  363.         it = it+1
  364.     end
  365. end
  366.  
  367. local OS = lineFromFile(io.popen("wmic os get caption"),2)
  368. if OS:find("2012") or OS:find("8") then
  369.     logo = "windows8"
  370. end
  371.  
  372. helpLines = {
  373.     "\nUsage: [-h] [-c color] [-l logo] [-b] [-d] [-o OoMm]",
  374.     "Write an OS logo to the output with OS information.\n",
  375.     "  -h, --help            Write what you're looking at to the output",
  376.     "  -c, --color COLOR     Change the color of the logo",
  377.     lightWhite.."                             red, yellow, green, blue, violet",
  378.     "                             black, white"..resetColor,
  379.     "  -l, --logo LOGO       Change the logo",
  380.     lightWhite.."                             Windows8, Windows7, None, OpenBSD",
  381.     "                             Linux, Debian, Trisquel, DragonFlyBSD",
  382.     "                             Windows, Legacy, Arch, Oldarch"..resetColor,
  383.     "  -b, --bright          Use only bright colors",
  384.     "  -d, --dull            Use only dull colors",
  385.     "  -o, --option OPTIONS  Use the following options",
  386.     lightWhite.."                             M = Minimal",
  387.     "                             m = Not Minimal",
  388.     "                             O = Use comma separated lists",
  389.     "                             o = Use multiple lines"..resetColor,
  390.     "      --showWarning     Show the Ansicon/Cygwin PTY warning.",
  391.     "  -a, --align           Align the lines",
  392.     "  -L, --lefty           Flip the logo and information",
  393.     "  -g, --gay             Gay-ify the logo a la toilet",
  394.     "\nv.2.1.4",
  395.     "By Hal, Zanthas, tested (and approved) by KittyKatt, other people",
  396. }
  397.  
  398. for i = 1,#arg do
  399.     if arg[i] == "--help" or arg[i] == "-h" then
  400.         for i = 1,#helpLines do
  401.             if canColor then
  402.                 print(helpLines[i])
  403.             else
  404.                 print(helpLines[i]:gsub("\027%[%d-%;-%d-m",""))
  405.             end
  406.         end
  407.         return
  408.     elseif arg[i] == "--logo" or arg[i] == "-l" then
  409.         if arg[i+1] then
  410.             if logos[string.lower(arg[i+1])] then
  411.                 logo = string.lower(arg[i+1])
  412.             else
  413.                 errorString("flag for logo is not valid")
  414.                 return
  415.             end
  416.         else
  417.             errorString("logo flag requires argument")
  418.             return
  419.         end
  420.     elseif arg[i] == "--color" or arg[i] == "-c" then
  421.         if arg[i+1] then
  422.             if colors[string.lower(arg[i+1])] then
  423.                 color = string.lower(arg[i+1])
  424.             else
  425.                 errorString("invalid color flag")
  426.                 return
  427.             end
  428.         else
  429.             errorString("color flag requires an argument")
  430.             return
  431.         end
  432.     elseif arg[i] == "--bright" or arg[i] == "-b" then
  433.         bright = true
  434.         dull = false
  435.     elseif arg[i] == "--dull" or arg[i] == "-d" then
  436.         bright = false
  437.         dull = true
  438.     elseif arg[i] == "--align" or arg[i] == "-a" then
  439.         align = true
  440.     elseif arg[i] == "--lefty" or arg[i] == "-L" then
  441.         lefty = true
  442.     elseif arg[i] == "--gay" or arg[i] == "-g" then
  443.         gay = true
  444.     elseif arg[i] == "--option" or arg[i] == "-o" then
  445.         local args = arg[i+1]
  446.         if args then
  447.             local ConflictO = (args:find("O") and args:find("o"))
  448.             local ConflictM = (args:find("M") and args:find("m"))
  449.             if ConflictO or ConflictM then
  450.                 errorString("option flag has conflicting options")
  451.                 return
  452.             else
  453.                 if args:find("[^OoMm]") then
  454.                     errorString("option flag has invalid options")
  455.                     return             
  456.                 end
  457.                 if args:find("o") then
  458.                     moreThanOneLine = true
  459.                 end
  460.                 if args:find("O") then
  461.                     moreThanOneLine = false
  462.                 end
  463.                 if args:find("M") then
  464.                     minimal = true
  465.                 end
  466.                 if args:find("m") then
  467.                     minimal = false
  468.                 end
  469.             end
  470.         else
  471.             errorString("option flag requires an argument")
  472.             return
  473.         end
  474.     elseif arg[i] == "--showWarning" then
  475.         warning()
  476.         return
  477.     end
  478. end
  479.  
  480. if (not canColor) and ((color and color ~= "none") or (not color)) then
  481.     warning()
  482.     return
  483. end
  484.  
  485. if color then
  486.     if color == "none" then
  487.         for i = 1,#logos[logo]["colors"] do
  488.             logos[logo]["colors"][i] = ""
  489.         end
  490.     else
  491.         for i = 1,#logos[logo]["colors"] do
  492.             if colors[color][i] then
  493.                 logos[logo]["colors"][i] = colors[color][i]
  494.             else
  495.                 logos[logo]["colors"][i] = colors[color][(i%2)+1]
  496.             end
  497.         end
  498.     end
  499. end
  500.  
  501. local bools = {[true]=1,[false]=2}
  502. if bright or dull then
  503.     for color = 1,#logos[logo]["colors"] do
  504.         for i = 1,#colorNames do
  505.             if logos[logo]["colors"][color] == colors[colorNames[i]][bools[bright]] then
  506.                 logos[logo]["colors"][color] = colors[colorNames[i]][bools[dull]]
  507.             end
  508.         end
  509.     end
  510. end
  511.  
  512. --local name = io.popen("echo.%USERNAME%@%USERDOMAIN%","r"):read()--
  513. local name = io.popen("echo.%USERNAME%","r"):read()
  514. local kernelOS = io.popen("echo.%OS%","r"):read()
  515. local kernel = lineFromFile(io.popen("wmic os get version"),2)
  516. local ramSize = lineFromFile(io.popen("wmic os get totalvisiblememorysize"),2)
  517. local ramFree = lineFromFile(io.popen("wmic os get freephysicalmemory"),2)
  518. local architecture = lineFromFile(io.popen("wmic os get osarchitecture"),2)
  519. ramUsed = ramSize - ramFree
  520. ramUsed = math.floor((tonumber(ramUsed)/1024)+.5)
  521. ramSize = math.floor((tonumber(ramSize)/1024)+.5)
  522. usedPercentage = ramUsed/ramSize*100
  523. if canColor then
  524.     if usedPercentage <= 25 then
  525.         memoryColor = white
  526.     elseif usedPercentage <= 50 then
  527.         memoryColor = white
  528.     elseif usedPercentage <= 75 then
  529.         memoryColor = white
  530.     else
  531.         memoryColor = white
  532.     end
  533. else
  534.     memoryColor = ""
  535. end
  536.  
  537. local lastBootUp = lineFromFile(io.popen("wmic os get lastbootuptime"),2)
  538. local year,month,day,hour,min,sec=(lastBootUp):match("(%d%d%d%d)(%d%d)(%d%d)(%d%d)(%d%d)(%d%d)")
  539. time1 = os.time({
  540.     year = tonumber(year),
  541.     month = tonumber(month),
  542.     day = tonumber(day),
  543.     hour = tonumber(hour),
  544.     min = tonumber(min),
  545.     sec = tonumber(sec)
  546. })
  547. local seconds = os.difftime(os.time(),time1)
  548. local hours = (seconds-(seconds%3600))/3600
  549. local remainingSeconds = (seconds-(hours*3600))
  550. local minutes = (remainingSeconds-(remainingSeconds%60))/60
  551. local seconds = seconds-(hours*3600+minutes*60)
  552. local firstColor = logos[logo]["colors"][1]
  553.  
  554. local theme
  555. dir = {
  556.     "HKCU","Software","Microsoft","Windows",
  557.     "CurrentVersion","ThemeManager"
  558. }
  559. local stringToMatch1 = "[%w%_]+%s+[%w%_]+%s+([%w%_%-%s%%%p]+)"
  560. local stringToMatch2 = "([%:%p%w%s%\\]+%\\)([%w%_%-%s%%%p]+)"
  561. local regKey = "reg query "..table.concat(dir,"\\").." /v DllName"
  562. local themeFileName = lineFromFile(io.popen("2>nul "..regKey),3)
  563. if themeFileName == nil then
  564.     --There isn't a visual style found, just use the theme file
  565.     --Often in the case of Windows Classic
  566.     dir[6] = "Themes"
  567.     local regKey = "reg query "..table.concat(dir,"\\").." /v CurrentTheme"
  568.     themeName = lineFromFile(io.popen("2>nul "..regKey),3)
  569.     themeName = themeName:match(stringToMatch1)
  570.     pathToTheme,themeName = themeName:match(stringToMatch2)
  571.     --This is more difficult, currently reads the .theme file, if it is
  572.     --determined that it is Windows Classic, use "Windows Classic",
  573.     --otherwise trim the file extension from the theme file and use that.
  574.     for line in io.popen("type \""..pathToTheme..themeName.."\""):lines() do
  575.         found,result = line:find("ColorStyle")
  576.         if found then
  577.             if line:find("Classic") then
  578.                 theme = "Windows Classic"
  579.             else
  580.                 theme = themeName:match("([%s%w]+)")
  581.                 if theme:lower() == "classic" then
  582.                     theme = "Windows Classic"
  583.                 end
  584.             end
  585.         end
  586.     end
  587. else
  588.     local themeFileName = themeFileName:match(stringToMatch1)
  589.     pathToTheme,themeName = themeFileName:match(stringToMatch2)
  590.     theme = themeName:match("([%p%w%s%_%$-]+).msstyle")
  591.     --Trimming the file extension should be fine for this.
  592. end
  593.  
  594. local OS = OS:gsub("[^\032%w%p_]","")
  595. local kernel = kernel:gsub("[^\032%w%p_]","")
  596. local architecture = architecture:gsub("[^\032%w%p_]","")
  597. --Weird issue with trimming spaces and line resets with these,
  598. --don't know cause. Look into it. Likely an issue with wmic?
  599. --This seems to fix it.
  600. while OS:sub(-1) == " " do
  601.     OS = OS:sub(1,OS:len()-1)
  602. end
  603. while kernel:sub(-1) == " " do
  604.     kernel = kernel:sub(1,kernel:len()-1)
  605. end
  606. while architecture:sub(-1) == " " do
  607.     architecture = architecture:sub(1,architecture:len()-1)
  608. end
  609.  
  610. lines = {}
  611. if useLineName then
  612.     table.insert(lines,firstColor.."Name: "..resetColor..name..resetColor)
  613. end
  614. if useLineKernel then
  615.     table.insert(lines,firstColor.."Kernel: "..resetColor..kernelOS.." "..kernel..resetColor)
  616. end
  617. if useLineOS then
  618.     table.insert(lines,firstColor.."OS: "..resetColor.."".."Win7HP 64bit"..resetColor)
  619. end
  620. if useLineMemory then
  621.     table.insert(lines,firstColor.."Memory: "..memoryColor..ramUsed..resetColor.."/"..ramSize .. " MB")
  622. end
  623. if useLineUptime then
  624.     table.insert(lines,firstColor.."Uptime: "..resetColor..hours.."h "..minutes.."m "..seconds.."s")
  625. end
  626. if useLineTheme then
  627.     table.insert(lines,firstColor.."Theme: "..resetColor..theme)
  628. end --Pretty dirty, clean up later
  629.  
  630. local bbLeanTheme
  631. local tasks = io.popen("tasklist")
  632. for line in tasks:lines() do
  633.     task = line:match("(%w+)%.exe")
  634.     if task == "blackbox" then
  635.         --Check for bbLean
  636.         local dir = io.popen("2>&1 dir /b C:\\bbLean"):read()
  637.         if not dir:find("File Not Found") then
  638.             bbLeanTheme = "Not Found"
  639.             for line in io.open("C:/bbLean/blackbox.rc","r"):lines() do
  640.                 key, val = line:match("([%w%.]+): (.+)")
  641.                 if key == "session.styleFile" then
  642.                     bbLeanTheme = val:match("[\\/](.+)")
  643.                 end
  644.             end
  645.         else
  646.             bbLeanTheme = "Not Found"
  647.         end
  648.     end
  649. end
  650. if bbLeanTheme and useLineBblean then
  651.     table.insert(lines,firstColor.."bbLean Theme: "..resetColor..bbLeanTheme)
  652. end
  653.  
  654. local height,heightLines = io.popen("wmic desktopmonitor get screenheight"),{}
  655. local width,widthLines = io.popen("wmic desktopmonitor get screenwidth"),{}
  656. local cpu,cpuLines = io.popen("wmic cpu get name"),{}
  657. local gpu,gpuLines = io.popen("wmic path Win32_VideoController get caption"),{}
  658. local hdd,hddLines = io.popen("wmic logicaldisk get size"),{}
  659. local freeHDD,freeHDDLines = io.popen("wmic logicaldisk get freespace"),{}
  660. local objects = {cpu,gpu,height,width,hdd,freeHDD}
  661. local objectsLines = {cpuLines,gpuLines,heightLines,widthLines,hddLines,freeHDDLines}
  662. for i = 1,#objects do
  663.     for line in objects[i]:lines() do
  664.         table.insert(objectsLines[i],line)
  665.     end
  666. end
  667.  
  668. local it = 1
  669. for i = 1,#heightLines do
  670.     if heightLines[i]:match("%d+") then
  671.         local a = widthLines[i]:match("%d+")
  672.         local b = heightLines[i]:match("%d+")
  673.         if moreThanOneLine then
  674.             if heightLines[i] ~= "ScreenHeight" and heightLines[i]:match("%d+") then
  675.                 if i == 2 then
  676.                     if useLineRes then
  677.                         table.insert(lines,firstColor..string.format("Res: %s%sx%s",resetColor,a,b))
  678.                     end
  679.                 else
  680.                     if useLineRes then
  681.                         table.insert(lines,string.format("     %s%sx%s",resetColor,a,b))
  682.                     end
  683.                 end
  684.             end
  685.         elseif heightLines[i]:match("%d+") then
  686.             if i == 2 then
  687.                 res = firstColor..string.format("Res: %s%sx%s",resetColor,a,b)
  688.             else
  689.                 res = res..","..string.format("%sx%s",a,b)
  690.             end
  691.         end
  692.     end
  693. end
  694.  
  695. local names = {"CPU: ","GPU: "}
  696. for x = 1,2 do
  697.     local it = 1
  698.     for i = 1,#objectsLines[x] do
  699.         if objectsLines[x][i]:match("%a+") and it > 1 then
  700.             local object = objectsLines[x][i]:gsub("%(%w%)",""):gsub("%s+"," ")
  701.             if moreThanOneLine then
  702.                 if it == 2 then
  703.                     if not ((x == 1 and not useLineCPU) or (x == 2 and not useLineGPU))then
  704.                         table.insert(lines,firstColor..names[x]..resetColor..object)
  705.                     end
  706.                 else
  707.                     if not ((x == 1 and not useLineCPU) or (x == 2 and not useLineGPU))then
  708.                         table.insert(lines,"     "..resetColor..object)
  709.                     end
  710.                 end
  711.             else
  712.                 if it == 2 then
  713.                     line = firstColor..names[x]..resetColor..object
  714.                 else
  715.                     line = line:match("(.-)%s*$")..","..object:match("(.-)%s*$")
  716.                 end
  717.             end
  718.         end
  719.         it = it + 1
  720.     end
  721.     if x == 1 then
  722.         cpuline = line
  723.     else
  724.         gpuline = line
  725.     end
  726. end
  727.  
  728. local it = 1
  729. local newHDDLines = {}
  730. for i = 1,#hddLines do
  731.     if hddLines[i]:match("%d+") then
  732.         newHDDLines[it] = hddLines[i]
  733.         it = it + 1
  734.     end
  735. end
  736. hddLines = newHDDLines
  737.  
  738. local it = 1
  739. local newFreeHDDLines = {}
  740. for i = 1,#freeHDDLines do
  741.     if freeHDDLines[i]:match("%d+") then
  742.         newFreeHDDLines[it] = freeHDDLines[i]
  743.         it = it + 1
  744.     end
  745. end
  746. freeHDDLines = newFreeHDDLines
  747.  
  748. for i = 1,#hddLines do
  749.     if hddLines[i]:match("%d+") and it > 1 then
  750.         local hddUsed = tonumber(hddLines[i])-tonumber(freeHDDLines[i])
  751.         local hddPercent = hddUsed/hddLines[i]*100
  752.         if canColor then
  753.             if hddPercent <= 25 then
  754.                 color = lightGreen
  755.             elseif hddPercent <= 50 then
  756.                 color = green
  757.             elseif hddPercent <= 75 then
  758.                 color = lightYellow
  759.             else
  760.                 color = red
  761.             end
  762.         else
  763.             color = ""
  764.         end
  765.         hddLines[i] = math.floor(tonumber(hddLines[i])/1024^3+.5)
  766.         hddUsed = math.floor(hddUsed/1024^3+.5)
  767.         if moreThanOneLine then
  768.             if i == 1 then
  769.                 if useLineHDD then
  770.                     table.insert(lines,firstColor.."Disk space: "..color..hddUsed..resetColor.."/"..hddLines[i].." GB")
  771.                 end
  772.             else
  773.                 if useLineHDD then
  774.                     table.insert(lines,"            "..color..hddUsed..resetColor.."/"..hddLines[i].." GB")
  775.                 end
  776.             end
  777.         else
  778.             if it == 2 then
  779.                 hddline = firstColor.."Disk space: "..color..hddUsed..resetColor.."/"..hddLines[i].." GB"
  780.             else
  781.                 hddline = hddline..", "..color..hddUsed..resetColor.."/"..hddLines[i].." GB"
  782.             end
  783.         end
  784.     end
  785. end
  786.  
  787. if not moreThanOneLine then
  788.     if useLineRes then
  789.         table.insert(lines,res..resetColor)
  790.     end
  791.     if useLineCPU then
  792.         table.insert(lines,cpuline..resetColor)
  793.     end
  794.     if useLineGPU then
  795.         table.insert(lines,gpuline..resetColor)
  796.     end
  797.     if useLineHDD then
  798.         table.insert(lines,hddline..resetColor)
  799.     end
  800. end
  801.  
  802. if minimal then
  803.     lines = {
  804.         firstColor.."Name: "..resetColor..name..resetColor,
  805.         firstColor.."OS: "..resetColor..OS..resetColor,
  806.         firstColor.."Uptime: "..resetColor..hours.."h "..minutes.."m "..seconds.."s",
  807.     }
  808. end
  809.  
  810. local min
  811. if align then
  812.     min = 0
  813.     for i = 1,#lines do
  814.         local line = lines[i]:gsub("\027%[%d-%;-%d-m",""):find(":")
  815.         if line then
  816.             min = math.max(min,line)
  817.         end
  818.     end
  819.     for i = 1,#lines do
  820.         local colon = lines[i]:gsub("\027%[%d-%;-%d-m",""):find(":")
  821.         if colon then
  822.             lines[i] = (" "):rep(min-colon)..lines[i]
  823.         else
  824.             lines[i] = (" "):rep(min+1)..lines[i]:match("%s*(.*)")
  825.         end
  826.     end
  827. end
  828.  
  829. local gaycolors = {lightViolet,lightRed,lightYellow,lightGreen,lightCyan,lightBlue}
  830. if dull then
  831.     gaycolors = {violet,red,yellow,green,cyan,blue}
  832. end
  833.  
  834. if gay then
  835.     for i = 1,#lines do
  836.         local currentline = lines[i]
  837.         local newline = ""
  838.         stat,info = currentline:match("(.+:)(.+)")
  839.         if stat and info then
  840.             stat = stat:gsub("\027%[%d-%;-%d-m","")
  841.             local it = 6
  842.             for i = 1,#stat do --violet,red,yellow,green,cyan,blue
  843.                 if it == #gaycolors then
  844.                     it = 1
  845.                 else
  846.                     it = it + 1
  847.                 end
  848.                 if not (stat:sub(i,i) == " ") then
  849.                     newline = newline .. gaycolors[it] .. stat:sub(i,i)
  850.                 else
  851.                     newline = newline .. " "
  852.                 end
  853.             end
  854.             newline = newline .. resetColor .. info
  855.             lines[i] = newline
  856.         end
  857.     end
  858. end
  859.  
  860. local space = 0
  861. if lefty then
  862.     for i = 1,#lines do
  863.         line = lines[i]:gsub("\027%[%d-%;-%d-m","")
  864.         space = math.max(space,line:len())
  865.     end
  866.     for i = 1,#lines do
  867.         line = lines[i]:gsub("\027%[%d-%;-%d-m","")
  868.         lines[i] = lines[i] .. (" "):rep(space-line:len())
  869.     end
  870. end
  871.  
  872. for line = 1,#logos[logo] do
  873.     local currentLine = logos[logo][line]
  874.     if not gay then
  875.         for inc = 1,#logos[logo]["colors"] do
  876.             currentLine = currentLine:gsub(("%s{c%s}"):format("%$",inc),logos[logo]["colors"][inc])
  877.             currentLine = currentLine:match("(.-)%s*$")
  878.         end
  879.     else
  880.         currentLine = logos[logo][line]:gsub("%$%{c%d%}",""):sub(0,-3)
  881.         local newline = ""
  882.         local it = 6
  883.         for i = 1,#currentLine do
  884.             if it == #gaycolors then
  885.                 it = 1
  886.             else
  887.                 it = it + 1
  888.             end
  889.             if not (currentLine:sub(i,i) == " ") then
  890.                 newline = newline .. gaycolors[it] .. currentLine:sub(i,i)
  891.             else
  892.                 newline = newline .. " "
  893.             end
  894.         end
  895.         currentLine = newline .. "%s"
  896.     end
  897.     if lines[line] then
  898.         if not lefty then
  899.             currentLine = currentLine:format(lines[line])
  900.         else
  901.             currentLine = lines[line] .. currentLine:format("")
  902.         end
  903.     else
  904.         if not lefty then
  905.             currentLine = currentLine:format("")
  906.         else
  907.             currentLine = (" "):rep(space)..currentLine:format("")
  908.         end
  909.     end
  910.     if lefty then
  911.         currentLine = " " .. currentLine:match("(.+)%s")
  912.     end
  913.     if canColor then
  914.         print(currentLine..resetColor)
  915.     else
  916.         local currentLine = currentLine:gsub("\027%[%d-%;-%d-m","")
  917.         print(currentLine)
  918.     end
  919. end
  920. --gsub("\027%[%d-%;-%d-m","") removes ansi escape codes for color
  921. --gsub("%$%{c%d%}","") removes color codes in the logos
  922. local spaces = (" "):rep(logos[logo][1]:gsub("%$%{c%d%}",""):len()-2) --The -2 is for "%s"
  923. if #lines > #logos[logo] then
  924.     for i = #lines-(#lines - #logos[logo])+1,#lines do
  925.         if canColor then
  926.             if not lefty then
  927.                 print(spaces..lines[i]:match("(.-)%s*$"))
  928.             else
  929.                 print(lines[i]:match("(.-)%s*$"))
  930.             end
  931.         else
  932.             if not lefty then
  933.                 local currentLine = spaces..lines[i]:gsub("\027%[%d-%;-%d-m","")
  934.                 print(currentLine:match("(.-)%s*$"))
  935.             else
  936.                 local currentLine = lines[i]:gsub("\027%[%d-%;-%d-m","")
  937.                 print(currentLine:match("(.-)%s*$"))
  938.             end
  939.         end
  940.     end
  941. end
Advertisement
Add Comment
Please, Sign In to add comment