Menu

SpaceFM Dialog Disk Info

Anonymous
2016-02-11
2016-03-20
  • Anonymous

    Anonymous - 2016-02-11

    I have been playing with SpaceFM's Dialog capabilities and have been very impressed with the way it works compared to Yad and Zenity. I'm surprised there are not more examples floating around. The easily implemented ability to watch a file and display changes makes completeing many tasks very straightforward.

    #!/bin/bash
    # version: 2016-02-11 00:29
    # author: James Jordan     james   @  LiXCE.com
    #-------------------------------------------------------------------------------
    
    # Define the tempFile-----------------------------------------------------------
    # need to make a unique temp file and I like to be able to identify them
    # $$ inserts PID of script process
    export tmpFile=/tmp/$USER-$$-df-LiXCE
    
    # Create a function to process disk information---------------------------------
    diskInfo ( ) { 
        # write the DF output to the temp file
        # Only uncomment ONE of the following lines
        # df -H > $tmpFile # Include all filesytems in Human readabel  1000's
        df -H -x devtmpfs -x tmpfs > $tmpFile # Do not include tmp file systems
    
        # Strip off the header row, have to make my own to include spacefm control chars
        sed -i '1d' $tmpFile
    
        # declare an array and pre-load it with my column headings
        declare -a eachWD=("^Filesystem" "^Size" "^Used" "^Avail" "^Percent Full:progress"  "^Mounted")
        # add column widths to the array
        eachWD=("${eachWD[@]}" "--colwidth=230" "--colwidth=50" "--colwidth=50" "--colwidth=50" "--colwidth=250" "--colwidth=150")
        # Load each word of the text file into the array.
        for word in $(<$tmpFile)
        do
            eachWD=("${eachWD[@]}" "$word")
        done
        # everything has been read so we can reuse the temp file
        echo -n "" > $tmpFile
        # get length of array
        numWDs=${#eachWD[@]}
        # iterate through a compund loop to create the proper order
        COUNTA=0
        # we have 6 columns so the outerloop needs to iterate 6 times
        while [ $COUNTA -lt  6 ]; do 
            COUNTB=0
            # the inner loop iterates one time for each line in the file
            # plus once for the header and once for the column widths
            while [ $COUNTB -lt  $numWDs ]; do  
                echo ${eachWD[$COUNTA + $COUNTB]} >> $tmpFile
                # increment the count by 6
                let COUNTB+=6
            done    
            let COUNTA+=1
        done
        return 0
    }
    export -f diskInfo
    
    # Create an autoUpdate function that runs every 11 minutes----------------------
    # 11 minutes keeps it from happening the same time every hour
    autoUpdate () {
        sleep 660
        diskInfo
        autoUpdate
        return 0
    }
    # called from this shell level so do not need to export
    
    
    # PROCESSING BEGINS HERE--------------------------------------------------------
    # call the diskInfo function to provide initial display
    diskInfo 
    
    # Check the command line to see if we should automatically update
    if [ "$1" == "-a" ]; then
        #call the autoUpdate function and continue processing
        autoUpdate &
    fi  
    
    # Present the Spacefm dialog which is really very simple 
    eval "$(spacefm -g \
    --window-size "800x200" --title LiXCE-Disk-Info  \
    --list --font "Roboto Bold 12"  @/$tmpFile \
    --button _Update bash -c diskInfo \
    --button close  2>/dev/null)" 
    # the 2>/dev/null supresses the gtk warnings
    
    # Clean up
    rm $tmpFile
    
    # Turn out the lights
    exit 0
    
     

    Last edit: Anonymous 2016-02-11
  • IgnorantGuru

    IgnorantGuru - 2016-03-19

    Thanks for the example. SpaceFM Dialog could use a How To as the manual is more of a reference (but does contain small examples). Also note that some plugins demonstrate Dialog use.

    Also, I just added an Example Application plugin which demonstrates using a main loop to control a dialog.

     

    Last edit: IgnorantGuru 2016-03-20

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB