ikz87 / dots-2.0

eww + bspwm rice c:
GNU General Public License v3.0
229 stars 16 forks source link

Disk and partitions #26

Closed ghost closed 2 years ago

ghost commented 2 years ago

on a drive with the following partitions:

/dev/sda1 - boot
/dev/sda2 - system stuff
/dev/sda3 - linux LVM encrypted
  /mapper/lvm_root - 30gb
  /mapper/lvm_home - 220gb

the disk readout provides a fraction of the 30gb allocated to the root file system. It's probably what I want, but for curiosity, how would I configure the drive widget to read another partition?

ikz87 commented 2 years ago

The disk info comes from the script located at .config/eww/mybar/scripts/disk_info which contains the following code:

#!/bin/sh                                                                               

raw=`df -h / | grep /dev/`    

case $1 in    
    "--used" )    
        value=`echo $raw | awk '{printf $3}'`    
        ;;    
    "--all" )    
        value=`echo $raw | awk '{printf $2}'`    
        ;;    
    "--free" )    
        value=`echo $raw | awk '{printf $4}'`    
        ;;    
    * )    
        true    
        ;;    
esac 

As you can see, I store a "raw" line with everything needed, which then I parse differently depending on the flag provided. If you wanna change which partition the script monitors you'd just need to change what line you store in raw Notice that I use df -h / since I wanted to monitor the only partition mounted at /, By only using df -h you can get a list of all partitions currently mounted on your system.

For example, this is my output for df -h:

Filesystem      Size  Used Avail Use% Mounted on
dev             3.7G     0  3.7G   0% /dev
run             3.7G  9.3M  3.7G   1% /run
/dev/nvme0n1p1  173G  120G   45G  73% /
tmpfs           3.7G   51M  3.7G   2% /dev/shm
tmpfs           3.7G  7.7M  3.7G   1% /tmp
/dev/nvme0n1p6  1.1G  440K  1.1G   1% /boot/efi
tmpfs           751M   72K  751M   1% /run/user/1000
/dev/nvme0n1p4   58G   38G   21G  65% /run/media/kz87/AE68C45C68C42545

If I wanted to monitor, let's say, /dev/nvme0n1p4 (which is where I have my windows instalation) I'd change line 3 in disk_info to:

raw=`df -h | grep /dev/nvme0n1p4`

Notice that I pipe to grep to only get the line for the partition I want.

Before change After change
image image

Not sure if my answer fully closes the issue, so I'm leaving it open just in case.

ikz87 commented 2 years ago

aight, closing since there was no activity in like 3 days, and I'd say my answer was sufficient. Feel free to reopen if there are still any questions about the same topic :)