0

I'm a Drupal/WordPress developer, and I use Ubuntu for editing PHP, HTML, javascript and CSS files. I typically work with a local XAMPP stack with staging copies of my production environments.

I'd really like to be able to open a file I'm working on in a web browser. Obviously I can open the browser and visit the localhost/whatever URL, but I'm hoping there might be some sort of nifty right-click type solution.

Anyone know of anything. Or do I have to dust off the old C skills and try to programme a plugin myself?

Thanks for your help.

J

  • 1
    Can't you just right-click on such a file, chose proporties and set deafult program as Chromium or something? – dhpasta Dec 13 '13 at 16:39
  • 1
    you just want to open it right and not editing – rɑːdʒɑ Dec 13 '13 at 16:42
  • 1
    What is more you can just right-click on file and chose option: "Open with" and chose your web browser. – dhpasta Dec 13 '13 at 16:46
0

yes you can do it. Just type the file path in the URL area and then it will loads. as you said you just want to open the text file.

0

I am not allowed to comment for clarification yet, so I will answer. It sounds like you are looking to open source files you are editing, .php .css .js in your browser instead of gedit.

To do this, in Nautilus, right click on a file you want to open in your browser, a .php file for example. From the drop-down menu, choose 'Properties'

In the window that opens, click the third tab over "Open with"

From this tab you may choose your desired program, firefox, chromium, etc, and then click the 'Set as default' button. If you do not see the browser you want to open them with, you can click 'Show other applications'

After this .php files will open in your browser, and if you right click, there should be a "Open with Text Editor" to open them in gedit for editing. Hope this helps

  • Opening a php file in a web browser wont actually run it on the XAMPP server so this is no use. He clearly says in the question he needs to navigate to the local host. – Julian Stirling Dec 13 '13 at 16:50
  • As I mentioned I am not allowed to ask for clarification before answering yet. He clearly states he has the ability to navigate to the localhost url, but this is what he is trying to avoid. – grinch Dec 13 '13 at 16:59
  • Yes but open with runs the filepath not the localhost/url on an XAMPP server! It will open the .php file directly in firefox, which will prompt firefox to ask you if you want to open in in gedit! – Julian Stirling Dec 13 '13 at 17:33
  • Sorry, guys, I should have been more specific - and thanks everyone so far for your answers. I currently use the filebrowser sidebar in Gedit - so what I'd like to be able to do is right-click (or something similar) a file from there, select "Open in browser" (or something similar), so's I can quickly see the browser view of a file on which I'm working. Julian - your bash script solution below looks like just the job. I'll check it out properly and let you know how it goes. Thanks again for your help. – jamesdesq Dec 27 '13 at 16:43
0

I don't think this is possible "out of the box". But it should be pretty easy to do with a bash script.

If you look at the nautilus page for making a bash script appear in the context menu.

You should be able to use NAUTILUS_SCRIPT_CURRENT_URI to check if the file is inside the correct folder for your server to run it. Then be able to use NAUTILUS_SCRIPT_SELECTED_FILE_PATHS to get the file you selected. An example which should work as long as you don't select more than one file is (And if you are in the wrong directory it will open your local host!):

#!/bin/bash
serverloc=/path/to/server
NAUTILUS_SCRIPT_SELECTED_FILE_PATHS=$(echo "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS"| grep  "$serverloc")
firefox localhost${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS:${#serverloc}} > file.txt

Just save that as LoadOnServer.sh in ~/.gnome2/nautilus-scripts or ~/.local/share/nautilus/scripts (depending on verion of nautilus, see comment below). And open this directory in the terminal and run: chmod +x LoadOnServer.sh

Now right click on a file. You should have the option LoadOnServer under scripts

  • Beware that if your version of nautluls is 3.6 or newer (nautilus --version) then you need to use the folder ~/.local/share/nautilus/scripts instead of the one in the link! – Julian Stirling Dec 13 '13 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.