Alternate Run command for Ubuntu 11.10

I have a habit of solving problems that have already been solved better by someone else, and I may be guilty of this here, but I wrote my own command prompt script because I didn’t like the default command prompt in Unity. A more sane way to solve the problem might be to install and setup gnome-shell, as described here, but I still like my script.

The script presents a list box with [type command] as the first choice and your command history as all the other choices, with the most recent on top (your command history is blank the first time).

Dropdown box of historical command list, with first choice [type command'

Using Ubuntu 11.10 with Unity, after creating your script with the listing below, save it in an appropriate location and make it executable.

Then choose system settings > keyboard > shortcuts > custom shortcuts, as detailed here: Click the gear in the upper right corner of your screen and choose System Settings. From there, find the keyboard widget (not the keyboard layout widget), choose the shortcuts tab, and click custom shortcuts.

Click the + sign at the bottom, and add the path name of the script file. Then click on the shortcut field (it probably says “Disabled”) and click again if necessary until it says “New shortcut”. Then press the keystroke that you want to assign. You probably want alt+f2.

Keyboard control panel, the selected item from the left menu is Custom Shortcuts

You may have to disable alt+f2 elsewhere to avoid conflicts, but I didn’t disable it for the Unity plugin in CCSM and I’m not having any problems.

Below is the script.


#Filename: launch (or whatever you want to name it)

#Command Launcher
#Brings up a dialog box from which you can choose a command from your history
#Also has a choice to type in a command

#Works in Ubuntu 11.10 with Unity
#Requires zenity

#Make this file executable.
#You can create a hotkey in the "Command" section in CCSM

#You can directly edit this history file

# Setting the field separator to be newline, to preserve whitespace

# Populating the list box with commands
# The first command to appear in the least box is [type command], which brings up a text box
echo "[type command]" > $TEMPFILE

# The remaining commands in the list box come from the history file
for hist in `cat $HISTFILE`; do {
echo "$hist" >> $TEMPFILE ;
} ; done

# Setting the field separator back to normal, to run the command properly

#calling the zenity list box to bring up a choice of commmands
runthis=`cat $TEMPFILE | zenity --list --column='choose' `

#If user chose [type command], bringing up the zenity text box
if [ "$runthis" == "[type command]" ]; then {
runthis=`zenity --entry --text="run"`
} fi

#Running the command, and if successful adding the command to the history file
$runthis && {

# Setting the field separator to be newline, to preserve whitespace

#Putting the new command at the top of the tempfile
echo "$runthis" > $TEMPFILE

#Putting the old commands from the history file into the tempfile
for hist in `cat $HISTFILE`; do {
#But not repeating the newest command
if [ "$runthis" != "$hist" ]; then {
echo "$hist" >> $TEMPFILE;
} ; done
#Saving the tempfile as the history file

#Setting the field separator back to normal before exiting
} ;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.