4

Instead of copying it from the web and pasting it in the terminal, I want to be able to select a command displayed in a web page and with right click context menu to add it and run it in terminal.

Some Firefox addons were supposed to do this, as described here, but they do not seem to work in latest Firefox.

Are there other solutions for this?

The result should look like this

enter image description here

  • Counting clicks/keypresses, it takes exactly the same amount of work to select a command, open a terminal, paste the command and run it compared to selecting a command, right-clicking to open a context menu, and clicking on "Run in terminal" menu item... – Sergey Jan 07 '13 at 23:34
  • @Sergey: from my calculation it would mean more than 2 actions less (now i select, copy, open terminal, paste and run, not to mention that copy and paste each involve right click and selecting in a context menu: with what i ask i would just have to select, right click and "run in terminal"). mainly i want to ask the terminal from firefox to start with the command i have just selected already pasted and running. it may not seem much but as i use that a lot it is much for me given the fact that i already use all sort of gadgets for less than this. –  Jan 07 '13 at 23:50
  • 3
    Aha... I suspected you're doing something like this... you're using a wrong copy-paste :) The workflow I propose is: 1. Select text with mouse; 2. Press Alt-Ctrl-T to open terminal (or click on terminal icon to avoid switching to keyboard) 3. Middle-click in the terminal window. Done! If the copied text includes a caret return at the end you won't even need to press Enter. It also works in any browser (or, in fact, any app) and allows to paste code into any other app. – Sergey Jan 07 '13 at 23:58
  • @Sergei: thnx for the great tip, i'll use it. you see asking stupid questions can make me smarter. or not: i still want something like TerminalRun that would give me this: http://technostripe.com/wp-content/uploads/2010/12/scr3.png. –  Jan 08 '13 at 00:04
  • 1
    Sure, I just don't know the answer to your question as asked, that's why I added it as a comment. Hope someone will be able to answer your question. – Sergey Jan 08 '13 at 00:12
  • 1
    There is a way to force installation on the latest firefox- I'll do an answer in a minute. –  Jan 08 '13 at 00:12
  • I came here looking for something similar. Highlight some command in Firefox and run it in the terminal. Sergey's tip works well enough. – Natetronn Feb 17 '19 at 00:03

1 Answers1

3

The addon you mention hasn't been updated for a while, but it is possible to run it in Firefox 17 using the hack I mention below, which I have used for other addons.

However, be very careful when using it to copy, paste, and run commands, as some forums other than this one have malicious code. However, it may be very useful for a good site like askubuntu.

Note: This method below merely edits the install file so it can be installed in the latest firefox, as xpi files are basically like zip archives, which can be manipulated.

The developer did not test it with Firefox 17, so it is unsupported, but it does seem to work. However, it will not be updated again and will receive no updates or fixes, so you must only use it on trusted sites like askubuntu.

How to edit the xpi and install it

(After writing this article myself, I noticed that a similar method for another addon was also used in this question, so the basics of the trick documented below is well known and usually works fine.)

Download the xpi file from gnome's archive:

wget "http://ftp.gnome.org/pub/mozilla.org/addons/9738/terminalrun-0.6-fx-linux.xpi"
unzip -d terminalrun terminalrun-0.6-fx-linux.xpi
cd terminalrun
gedit install.rdf

Now, just edit the Firefox version numbers in install.rdf so they look like this- choose any version of Firefox from 17 onwards to put in the MaxVersion (I chose an arbitrary number like 23.0, but you can choose a much higher one, up to 99.0.)

<em:minVersion>3.0</em:minVersion>
        <em:maxVersion>23.0.*</em:maxVersion>

After saving the file, but while still in the terminalrun folder, run

zip -r terminalrun *
mv terminalrun.zip terminalrun.xpi

Now just drag the xpi file into Firefox and it will install it; restart firefox and you will be able to highlight code with your mouse and right click to open in terminal.

Usually when you highlight code it works fine (as long as the command you highlight makes sense for your system), so please test this one that gives you system information:

uname -a

Here's the firefox context menu that you should see:

enter image description here