2

One of my favorite features of unity is the progress bar the launcher overlays on the icons for various programs like the file manager, or firefox. Gnome-terminal does not have a progress bar. What do I need to do for unity to display the status of apt-get or dd etc?

If this is not possible can we at least change the icon when a prompt is available?

1 Answer 1

2

Getting a progress bar to work will (I believe) be hard, and will have to be implemented on a case by case basis for different applications (apt-get, dd, etc.).


On the other hand, changing the icon when a prompt is available is easier. Assume that there exist two scripts iconprompt and iconnoprompt which change gnome-terminal's icon on execution. [I've added sample iconprompt and iconnoprompt in the end]

So, all that remains to be done is to

  1. Execute iconprompt when a prompt becomes available.

  2. Execute iconnoprompt when a command starts executing.

These can be accomplished by adding the lines

export PROMPT_COMMAND='iconprompt'
trap 'iconnoprompt' DEBUG

to the .bashrc file in your homefolder.


The behaviour will not be as desired when you have more than one terminal open - one terminal running apt-get and another on which you're working. In this case icon changes will not be indicators of process completion. To handle this consider the following alternative solution:

Add

monitor() { iconnoprompt; "$@"; iconprompt; }

to .bashrc. To do sudo apt-get ... you'll have to type monitor sudo apt-get .... The icon will be different only while the monitored command is running.

I recommend this solution, also because my iconprompt and iconnoprompt scripts take about 0.1 second to execute which will create a noticeable lag for commands like ls and cd.


(Sample) Content of iconnoprompt:

#!/usr/bin/python

from gi.repository import Unity, GObject
import threading, time

launcher = Unity.LauncherEntry.get_for_desktop_id ("gnome-terminal.desktop")
launcher.set_property("progress", 0.5)
launcher.set_property("progress_visible", True)

GObject.threads_init()
loop = GObject.MainLoop()

t = threading.Thread()
t.daemon = True
t.run = loop.run
t.start()

time.sleep(0.1)

(Sample) Content of iconprompt:

#!/usr/bin/python

from gi.repository import Unity, GObject
import threading, time

launcher = Unity.LauncherEntry.get_for_desktop_id ("gnome-terminal.desktop")
launcher.set_property("progress", 0.)
launcher.set_property("progress_visible", False)

GObject.threads_init()
loop = GObject.MainLoop()

t = threading.Thread()
t.daemon = True
t.run = loop.run
t.start()

time.sleep(0.1)

Set executable permissions to iconnoprompt and iconprompt and put them in your PATH. iconnoprompt will add a progress-bar to the gnome-terminal icon - but the progress value has no correlation with actual progress.

2
  • 1
    Regarding the monitor function, $@ is a bug; it should always be enclosed in double quotes, "$@".
    – geirha
    May 21, 2013 at 12:33
  • @geirha Thanks. Will update answer accordingly.
    – Prasanth S
    May 21, 2013 at 15:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .