Advertisement
viktorstrate

disk usage widget modified

Feb 25th, 2018
4,472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Modified version of https://github.com/felixhageloh/uebersicht-widgets/tree/master/disk-usage
  2.  
  3. # You may exclude certain drives (separate with a pipe)
  4. # Example: exclude = 'MyBook' or exclude = 'MyBook|WD Passport'
  5. # Set as something obscure to show all drives (strange, but easier than editing the command)
  6. exclude   = 'VM'
  7.  
  8. # Use base 10 numbers, i.e. 1GB = 1000MB. Leave this true to show disk sizes as
  9. # OS X would (since Snow Leopard)
  10. base10       = true
  11.  
  12. # appearance
  13. filledStyle  = false # set to true for the second style variant. bgColor will become the text color
  14.  
  15. width        = '367px'
  16. barHeight    = '36px'
  17. labelColor   = '#fff'
  18. #usedColor    = '#d7051d'
  19. usedColor    = '#d7051d'
  20. freeColor    = '#525252'
  21. bgColor      = '#fff'
  22. borderRadius = '3px'
  23. bgOpacity    = 0.9
  24.  
  25. # You may optionally limit the number of disk to show
  26. maxDisks: 10
  27.  
  28. localDisksAmount = "df -H | grep '/dev/' | wc -l | awk '{$1=$1};1'"
  29. localDisks = "df -#{if base10 then 'H' else 'h'} | grep '/dev/' | while read -r line; do fs=$(echo $line | awk '{print $1}'); name=$(diskutil info $fs | grep 'Volume Name' | awk '{print substr($0, index($0,$3))}'); echo $(echo $line | awk '{print $2, $3, $4, $5}') $(echo $name | awk '{print substr($0, index($0,$1))}'); done | grep -vE '#{exclude}'"
  30.  
  31. # ######## SERVER SETUP ########
  32.  
  33. # Enable server setup
  34. serverDisksEnabled = false
  35.  
  36. # Regex of what disks to show
  37. serverDisks = "/dev/sda1|/dev/sdb1"
  38.  
  39. # Edit 'sshHost' to match your SSH credentials
  40. sshHost = "user@host"
  41.  
  42. serverDisksCmd = ""
  43. if (serverDisksEnabled)
  44.   serverDisksCmd = " && ssh -t #{sshHost} df -H 2> /dev/null | egrep '#{serverDisks}'"
  45. #serverDisks = "ssh -t qpqp df -H 2> /dev/null | egrep '/dev/mapper/(qpqp--vg-(data|root|home)|backup--vg-backup)' | grep '/dev/' | while read -r line; do fs=$(echo $line | awk '{print $1}'); name=$(diskutil info $fs | grep 'Volume Name' | awk '{print substr($0, index($0,$3))}'); echo $(echo $line | awk '{print $2, $3, $4, $5}') $(echo $name | awk '{print substr($0, index($0,$1))}'); done"
  46.  
  47.  
  48. command: localDisksAmount + ' && ' + localDisks +  serverDisksCmd
  49.  
  50. refreshFrequency: 60000 * 60 # 1h
  51.  
  52. style: """
  53.  bottom: 50px
  54.  left: 50px
  55.  font-family: Helvetica Neue
  56.  font-weight: 200
  57.  
  58.  h2
  59.    color: #{labelColor}
  60.    padding: 0
  61.    margin: 20px 0 -10px
  62.    font-weight: 200
  63.  
  64.  .label
  65.    font-size: 12px
  66.    color: #{labelColor}
  67.    margin-left: 1px
  68.    font-style: italic
  69.    font-family: Myriad Set Pro, Helvetica Neue
  70.  
  71.    .total
  72.      display: inline-block
  73.      margin-left: 8px
  74.      font-weight: bold
  75.  
  76.  .disk:not(:first-child)
  77.    margin-top: 16px
  78.  
  79.  .wrapper
  80.    height: #{barHeight}
  81.    font-size: #{Math.round(parseInt(barHeight)*0.8)}px
  82.    line-height: 1
  83.    width: #{width}
  84.    max-width: #{width}
  85.    margin: 4px 0 0 0
  86.    position: relative
  87.    overflow: hidden
  88.    border-radius: #{borderRadius}
  89.    background: rgba(#{bgColor}, #{bgOpacity})
  90.    #{'background: none' if filledStyle }
  91.  
  92.  .wrapper:first-of-type
  93.    margin: 0px
  94.  
  95.  .bar
  96.    position: absolute
  97.    top: 0
  98.    bottom: 0px
  99.  
  100.    &.used
  101.      border-radius: #{borderRadius} 0 0 #{borderRadius}
  102.      background: rgba(#{usedColor}, #{ if filledStyle then bgOpacity else 0.1 })
  103.      border-bottom: 1px solid #{usedColor}
  104.      #{'border-bottom: none' if filledStyle }
  105.  
  106.    &.free
  107.      right: 0
  108.      border-radius: 0 #{borderRadius} #{borderRadius} 0
  109.      background: rgba(#{freeColor}, #{ if filledStyle then bgOpacity else 0.05 })
  110.      border-bottom:  1px solid #{freeColor}
  111.      #{'border-bottom: none' if filledStyle }
  112.  
  113.  
  114.  .stats
  115.    display: inline-block
  116.    font-size: 0.5em
  117.    line-height: 1
  118.    word-spacing: -2px
  119.    text-overflow: ellipsis
  120.    vertical-align: middle
  121.    position: relative
  122.  
  123.    span
  124.      font-size: 0.8em
  125.      margin-left: 2px
  126.  
  127.    .free, .used
  128.      display: inline-block
  129.      white-space: nowrap
  130.  
  131.  
  132.    .free
  133.      margin-left: 12px
  134.      color: #{if filledStyle then bgColor else freeColor}
  135.  
  136.    .used
  137.      color: #{if filledStyle then bgColor else usedColor}
  138.      margin-left: 6px
  139.      font-size: 0.9em
  140.  
  141.  .needle
  142.    width: 0
  143.    border-left: 1px dashed rgba(#{usedColor}, 0.2)
  144.    position: absolute
  145.    top: 0
  146.    bottom: -2px
  147.    display: #{'none' if filledStyle}
  148.  
  149.    &:after, &:before
  150.      content: ' '
  151.      border-top: 5px solid #{usedColor}
  152.      border-left: 4px solid transparent
  153.      border-right: 4px solid transparent
  154.      position: absolute
  155.      left: -4px
  156. """
  157.  
  158. humanize: (sizeString) ->
  159.   sizeString + 'B'
  160.  
  161.  
  162. renderInfo: (total, used, free, pctg, name) -> """
  163.  <div class='disk'>
  164.    <div class='label'>#{name} <span class='total'>#{@humanize(total)}</span></div>
  165.    <div class='wrapper'>
  166.      <div class='bar used' style='width: #{pctg}'></div>
  167.      <div class='bar free' style='width: #{100 - parseInt(pctg)}%'></div>
  168.  
  169.      <div class='stats'>
  170.        <div class='free'>#{@humanize(free)} <span>free</span> </div>
  171.        <div class='used'>#{@humanize(used)} <span>used</span></div>
  172.      </div>
  173.      <div class='needle' style="left: #{pctg}"></div>
  174.    </div>
  175.  </div>
  176. """
  177.  
  178. update: (output, domEl) ->
  179.   commands = output.split('\n')
  180.  
  181.   localDisksAmount = commands[0]
  182.   localDisks = commands[1..localDisksAmount]
  183.  
  184.   serverDisks = commands[localDisksAmount..]
  185.  
  186.   $(domEl).html ''
  187.  
  188.   $(domEl).append("<h2>Local</h2>")
  189.  
  190.   # Local
  191.   for disk, i in localDisks[..(@maxDisks - 1)]
  192.     args = disk.split(' ')
  193.  
  194.     if (args[4])
  195.       args[4] = args[4..].join(' ')
  196.       $(domEl).append @renderInfo(args...)
  197.  
  198.   # Server
  199.   if (serverDisksEnabled)
  200.     $(domEl).append("<h2>Server</h2>")
  201.  
  202.     for disk, i in serverDisks
  203.       args = disk.split(' ')
  204.  
  205.       args = args.filter (x) -> x != ''
  206.       args = args[1..]
  207.  
  208.       if (args[4])
  209.         args[4] = args[4..].join(' ')
  210.         $(domEl).append @renderInfo(args...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement