ROX-Desktop drive icons: show free space in tooltips

Window managers, icon programs, widgets, etc.
Post Reply
Message
Author
User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

ROX-Desktop drive icons: show free space in tooltips

#1 Post by SFR »

Ok, so today I definitively got tired of necessity to launch Pmount (or go to /mnt, terminal or wherever) every time I want to check free space on my drives.
Anyone tired either? :wink: Here's the "cure":

Code: Select all

#!/bin/bash

INFO_PATH=/root/.pup_event

while true; do
  df -h | grep -vE "/dev/loop|tmpfs|unionfs|shmfs|truecrypt" | grep "/mnt" | sed 's|/dev/|drive_|g' | awk '{print $1"| Size: "$2" Free: "$4}' | \
  while read i; do
    NAME="${i%%|*}"
    SIZE="${i##*|}"
    LINE=`grep "<Summary>" "$INFO_PATH/$NAME/AppInfo.xml" 2>/dev/null`
    NEW_LINE="`echo ${LINE%%Size: *}`$SIZE</Summary>"
    if [ "$LINE" != "$NEW_LINE" ] && [ ! "$(pidof snapmergepuppy)" ]; then
      #sed -i 's|'"$LINE"'|'"$NEW_LINE"'|' "$INFO_PATH/$NAME/AppInfo.xml"   
      cat "$INFO_PATH/$NAME/AppInfo.xml" | sed -e 's|'"$LINE"'|'"$NEW_LINE"'|' > /tmp/roxdrvfreespace_temp
      mv -f /tmp/roxdrvfreespace_temp "$INFO_PATH/$NAME/AppInfo.xml"
    fi
  done
  sleep 5
done
This short script updates periodically (5 sec.) tooltips for ROX drive icons, by adding current amount of available space.
I used 'dh -h' which rounds up the size, but it's sufficient to get overall insight.
That's it. Barely tested (only in Slacko-5.4), but so far works fine with internal and external (USB) drives. YMMV, of course.

BTW, if a drive will be unmounted, the tooltip won't be updated anymore (until mounted again) and its recent "Free: ..." value remains there.
This may be considered as a downside, but I don't mind that it's that way (and the code is much more simple).

If one try it and think "nah, I don't like it":
1. Kill the script
2. Delete everything from /root/.pup_event/ dir
3. Restart X

_________

WARNING: I have noticed that if I copy/paste the code using Opera browser, it (Opera) has unpleasant habit of adding leading and trailing spaces to pasted text.
So if it will happen, make sure that this line:
df -h | grep -vE "/dev/loop|tmpfs|unionfs|shmfs" | grep "/mnt" | sed 's|/dev/|drive_|g' | awk '{print $1"| Size: "$2" Free: "$4}' | \
doesn't contain any extra space after \ or else script won't work.

Enjoy & Greetings!
Attachments
screenshot.png
(25.64 KiB) Downloaded 1406 times
Last edited by SFR on Wed 20 Nov 2013, 22:30, edited 3 times in total.
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#2 Post by vovchik »

Dear SFR,

What a nice, useful and simple idea. It workes nicely under Lucid, too.

Thanks.

With kind regards,
vovchik

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#3 Post by rhadon »

Hi SFR,

tried your program, but no success :cry: . I also use Slacko 5.4, with and without save file.
I allways get:

Code: Select all

sed: -e expression #1, char 54: unknown option to `s'
added echo's to see the variables, so I think, it's the last sed command:

Code: Select all

# ./freespace
NAME=drive_sda5
SIZE= Size: 14G Free: 583M
LINE= <Summary>Filesystem: ext3 Size: 13,9GB</Summary>
NEW_LINE=<Summary>Filesystem: ext3 Size: 14G Free: 583M</Summary>
sed: -e expression #1, char 54: unknown option to `s'
Any idea?

Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#4 Post by SFR »

Thanks for the info, Vovchik!

Rhadon, yes! I think I see what went wrong.
It's decimal comma separator in "13,9GB" and I also used comma as a separator in the second 'sed' (I have left my "Country Settings" default - English, i.e. dot as separator).

Ok, I corrected the code, how about now?

Thanks for spotting this, btw.
PS. Rolf, maybe this is also the reason why <spinbutton> doesn't work for you when floating point values are in use..?

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#5 Post by rhadon »

Great! It works fine now. :D
And it's much more comfortable than using pmount or partview.

Thanks for sharing,

Rolf

Will test spinbuttons with english country settings soon :wink: .

Edit: Yes. Again, your'e right. Spinbutton and bdraw 1.6 are working fine with english country settings. :roll:
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

carenrose
Posts: 36
Joined: Tue 11 Dec 2012, 03:22

#6 Post by carenrose »

This is really cool! Thank you :D

I never really used the tooltips because I already know the overall size of whatever disk/drive I have, so it wasn't much useful to me before.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#7 Post by SFR »

Hey Carenrose

Thanks for reminding me about this lil' app - I was going to update it a bit.
Three changes:
1. 'truecrypt' added to items that are screened out from 'df -h' results.
2. Direct 'sed -i' replaced with 'cat ... | sed -e ...' + 'mv -f ...'
3. Updating is suspended during saving the session.

First post updated.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#8 Post by Karl Godt »

Cowardly refusing to sed -i ..
Missing [ $? = 0 ] && mv file file-new , then .

[/dev/|/mnt/TYPE] truecrypt where did you got that one ..?
Do you mean lvmcrypt ? Low-Level Virtual Machine (LLVM) v2, v3 ..

Otherwise was playing with it just to display it into console without sed 'ing any files .

Nice !

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#9 Post by SFR »

Hey Karl
Missing [ $? = 0 ] && mv file file-new , then .
You mean after 'cat ... | sed ...' ?
Sounds good, unfortunately it seems that sed returns 0 even if there's no stuff to process. :?

Code: Select all

# cat blahblah; echo $?
cat: blahblah: No such file or directory
1
# 
# cat blahblah | sed 's|abc|def|'; echo $?
cat: blahblah: No such file or directory
0
#
[/dev/|/mnt/TYPE] truecrypt where did you got that one ..?
Do you mean lvmcrypt ? Low-Level Virtual Machine (LLVM) v2, v3 ..
Just TrueCrypt:

Code: Select all

## without the use of kernel cryptographic services it's a loop device:
# df -h | grep truecrypt
/dev/loop2      334G  319G   16G  96% /mnt/truecrypt1
# 
## but _with_ kernel services it's:
# df -h | grep truecrypt
/dev/mapper/truecrypt1  334G  319G   16G  96% /mnt/truecrypt1
#
Hmm, maybe I should exclude the whole /dev/mapper instead..? The new pup_event doesn't seem to handle it at all, anyway...
BTW, should I exclude some more items or the 'grep "/mnt"' is sufficient precaution..?

Anyway, a bit more polished version:

Code: Select all

#!/bin/bash

# ROX_DrivesFreeSpace v0.3

INFO_PATH=/root/.pup_event

while true; do
  df -h | grep -vE "^/dev/loop|^tmpfs|^unionfs|^shmfs|^/dev/mapper" | grep "/mnt" | awk 'sub("/dev/","drive_",$1) {print $1"| Size: "$2" Free: "$4}' | \
  while read i; do
    NAME="${i%%|*}"
    SIZE="${i##*|}"
    if [ -f "${INFO_PATH}/${NAME}/AppInfo.xml" ]; then
      OLD_LINE=`grep "<Summary>" "${INFO_PATH}/${NAME}/AppInfo.xml"`
      NEW_LINE="`echo ${OLD_LINE%%Size: *}`$SIZE</Summary>"
      if [ "$OLD_LINE" != "$NEW_LINE" ] && [ ! "`pidof snapmergepuppy`" ]; then
        #sed -i 's|'"$OLD_LINE"'|'"$NEW_LINE"'|' "${INFO_PATH}/${NAME}/AppInfo.xml"   
        cat "${INFO_PATH}/${NAME}/AppInfo.xml" | sed 's|'"$OLD_LINE"'|'"$NEW_LINE"'|' > /tmp/roxdrvfreespace_temp
        mv -f /tmp/roxdrvfreespace_temp "${INFO_PATH}/${NAME}/AppInfo.xml"
      fi
    fi
  done
  sleep 5
done
Thanks &
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#10 Post by 01micko »

Looks like a nice option, but maybe not as default.

Scenario: Have the script lurking in /usr/bin (or wherever, even in $HOME) chmod -x then as an option to the right clicks for the drive icons "enable free space bubble" (or whatever), upon click we have chmod +x, then change the option to "disable bubble" in the right click menu then point that at chmod -x.

Just a random thought :)
Puppy Linux Blog - contact me for access

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#11 Post by mikeb »

gtk tooltips come in handy...one short df did the trick here.
http://www.murga-linux.com/puppy/viewto ... 381#729381
Those binary icons
http://www.murga-linux.com/puppy/viewtopic.php?t=78881
just lack such info... one to play with.

mike

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#12 Post by SFR »

01micko wrote:Looks like a nice option, but maybe not as default.

Scenario: Have the script lurking in /usr/bin (or wherever, even in $HOME) chmod -x then as an option to the right clicks for the drive icons "enable free space bubble" (or whatever), upon click we have chmod +x, then change the option to "disable bubble" in the right click menu then point that at chmod -x.

Just a random thought :)
Yeah, that would be neat, but of course it'd involve some modifications of the pup_event scripts (/usr/local/pup_event/frontend_func & /usr/local/bin/drive_all, I guess).
BTW, I personally am still using the old, "all-in-one" pup_event_frontend_d, because the new version won't refresh desktop drives' icons after creating/deleting partitions in GParted. :(
mikeb wrote:gtk tooltips come in handy...one short df did the trick here.
http://www.murga-linux.com/puppy/viewto ... 381#729381
Looks pretty cool!
___________

In the meantime, a little more optimized version (2 lines + 2 pipes + 1 cat less):

Code: Select all

#!/bin/bash

# ROX_DrivesFreeSpace v0.4

INFO_PATH=/root/.pup_event

while true; do
  df -h | awk '!/^Filesystem|^\/dev\/loop|^\/dev\/mapper\/|^tmpfs|^shmfs|^unionfs/, sub("/dev/","drive_",$1) {print $1" Size: "$2" Free: "$4}' | while read NAME SIZE; do
    if [ -f "${INFO_PATH}/${NAME}/AppInfo.xml" ]; then
      OLD_LINE=`grep "<Summary>" "${INFO_PATH}/${NAME}/AppInfo.xml"`
      NEW_LINE="${OLD_LINE%Size: *}$SIZE</Summary>"
      if [ "$OLD_LINE" != "$NEW_LINE" ] && [ ! "`pidof snapmergepuppy`" ]; then
        #sed -i 's|'"$OLD_LINE"'|'"$NEW_LINE"'|' "${INFO_PATH}/${NAME}/AppInfo.xml"   
        sed 's|'"$OLD_LINE"'|'"$NEW_LINE"'|' "${INFO_PATH}/${NAME}/AppInfo.xml" > /tmp/roxdrvfreespace_temp
        [ $? -eq 0 ] && mv -f /tmp/roxdrvfreespace_temp "${INFO_PATH}/${NAME}/AppInfo.xml"
      fi
    fi
  done
  sleep 5
done
Oh, in case anyone's curious why I've resigned from using 'sed -i ...' - well, I had suspicions that on some very rare occasions the direct 'sed -i' may cause that one or more processes go into D state (uninterruptible sleep) for good.
So far no more D processes since I've changed that a couple of months ago, so probably that was it...


EDIT: I merged 'while read...' line with the previous line to prevent the script from failure if additional space has been added after \, what may happen during copy/paste operation.

Greetings!
Last edited by SFR on Thu 21 Nov 2013, 18:50, edited 1 time in total.
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#13 Post by amigo »

#!/bin/bash
....
sleep 5

The only problem is that this polling process is pretty expensive running all the time. There are much cleaner ways to accomplish this with traditional tools like cron or even from a udev rule.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#14 Post by SFR »

Hey Amigo

I've never played with cron, but it seems that min. interval is 1 minute:
http://askubuntu.com/questions/800/how- ... using-cron
As for udev (never played as well), how could such a rule look like?
I suppose it'd be possible to call the script on device mounting, but what when free space changes..?

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#15 Post by sunburnt »

What`s the chances of this ( and sooo many other items...) getting into mainstream Puppy.?

So many improvements come and go here that it`s impossible to keep track of them all.

Also... amigo, I`ve suspected timed polling processes and thought there must be a better way.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#16 Post by amigo »

As far as getting free-space info into the tooltips for the icon, I don't think there is another way -unless one patched the filer itself to show such info for mount points.
Personally, I just use gtkdiskfree. It has a dynamic display, which means that it is also polling, but less expensively than a bash script would be.

The problem with using the tooltips is that the AppInfo.xml must be re-written every cycle and could be corrupted while doing so. I think a right-click action (to launch some indicator) would be a better solution.

Polling should be avoided like the plague.

Pelo

i use gtkdiskfree too with my Toutou Wolx 2014

#17 Post by Pelo »

i use gtkdiskfree too with my Toutou Wolx 2014
Attachments
kingston.png
(24.4 KiB) Downloaded 138 times

User avatar
sunburnt
Posts: 5090
Joined: Wed 08 Jun 2005, 23:11
Location: Arizona, U.S.A.

#18 Post by sunburnt »

Amigo is correct as always. Avoid polling!
Sadly there is no common way to trigger other code like this.
Perhaps an inet type damon that polls /sys and /proc for triggers,
then reads a list of apps, etc. to activate or write to.

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#19 Post by musher0 »

If you're a bit of a masochist, would the info given by partview make you happy? :roll:
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

User avatar
LazY Puppy
Posts: 1934
Joined: Fri 21 Nov 2014, 18:14
Location: Germany

#20 Post by LazY Puppy »

In my T.O.P.L.E.S.S. LazY Puppy 5 Systems I had made patches of

- /usr/local/bin/drive_all
- /usr/local/pup_event/frontend_funcs

It is to enable/disable by the config files and has option to refresh/update manually by right-clicking the drive icon - besides some more options not yet in standard Puppy.

Works in all of my T.O.P.L.E.S.S. LazY Puppy Systems (tahr, unicorn, vivid, xenial, slacko - 32bit/64bit all WoofCE).

See attached images.
Attachments
Screenshot-2016-05-14-13-37-20.jpg
(38.94 KiB) Downloaded 94 times
Screenshot-2016-05-14-13-36-32.jpg
(23.69 KiB) Downloaded 97 times
RSH

"you only wanted to work your Puppies in German", "you are a separatist in that you want Germany to secede from Europe" (musher0) :lol:

No, but I gave my old drum kit away for free to a music store collecting instruments for refugees! :wink:

Post Reply