Xfce Forum

Sub domains
 

You are not logged in.

#1 2012-08-30 12:45:28

mtbrandao
Member
Registered: 2012-08-30
Posts: 6

Disable "Execute" option on .sh files?

Hi.
I'm using Thunar 1.2.3 (Xfce 4.8)

When editing .sh files, I find very annoying that everytime I double click an .sh file, thunar executes it instead of opening with the default editor.
I can't find anywhere to change this.
Looks like shell scripts will always execute (if they have execute permission) when trying to open via Thunar.

Is there any way to change this behaviour?

Last edited by mtbrandao (2012-08-30 12:46:14)

Offline

#2 2012-09-28 20:27:03

greg-nz
Member
From: New Zealand
Registered: 2011-11-22
Posts: 12
Website

Re: Disable "Execute" option on .sh files?

Hi.

If you right-click on the file in Thunar and go to Properties > Permissions, you should be able to uncheck the box that says "All this file to run as a program." It will then open in whichever text editor you have specified.

But I imagine you've already tried this. Does it not work? It certainly works for me with Thunar 1.4.0.

Greg

Offline

#3 2012-09-29 01:11:17

mtbrandao
Member
Registered: 2012-08-30
Posts: 6

Re: Disable "Execute" option on .sh files?

Yes, but then I can't execute it in terminal either using by calling the script directly.

Offline

#4 2012-09-29 05:08:23

greg-nz
Member
From: New Zealand
Registered: 2011-11-22
Posts: 12
Website

Re: Disable "Execute" option on .sh files?

Good point. I guess all you can do then is to right click the file in Thunar and use the "open with" option. But it's a bit inconvenient. Perhaps someone else has a solution.

Greg

Offline

#5 2012-09-29 08:29:00

gnome_refugee
Member
Registered: 2010-01-15
Posts: 169

Re: Disable "Execute" option on .sh files?

Hi, mtbranao.

I have about a dozen scripts, most of which get modified now and then, so I know what you mean. Sometimes I forget to right-click the script in Thunar to Open with... when I want to edit it, and the script executes.

A simple workaround for me, anyway, would be to create a Zenity list of the scripts which is called up by a simple keyboard shortcut. The command for each script in the list would be (in my case) gedit path/to/script. This way I would execute the scripts when I clicked on them in Thunar, and edit the scripts by using the Zenity trick.

For an example of a similar Zenity chooser, see

http://www.freesoftwaremagazine.com/art … ing_zenity

Offline

#6 2012-09-29 17:03:09

mtbrandao
Member
Registered: 2012-08-30
Posts: 6

Re: Disable "Execute" option on .sh files?

Today I right click and Open With text editor.

But I think a more correct approach would be remove the execution bit and open the script using bash / perl / whatever the script is made. in terminal ("bash script.sh")
What happens is that many times I just forget to "open with" and double click the script, executing it when I really want to edit. And some scripts can't be executed at any time (because they generate log, rename files, whatever).

Offline

#7 2014-01-25 10:15:43

Boosh
Member
Registered: 2014-01-25
Posts: 4

Re: Disable "Execute" option on .sh files?

Bump.

I hope these forums don't succumb to commonplace misconceptions about reviving old threads.

Has this issue been solved?  I searched the github commits but was unable to find anything to that effect.  I'm using Thunar 1.2.3 on the latest Debian Stable, so I can't confirm the latest version.

The topic I was going to start wrote:

Thunar executes scripts when you click them, and there is no way to change this.  Setting the "always open with" option does nothing.

This can be dangerous.  It would be more friendly of Thunar to provide an easily accessible option to disable this behavior.  And it would be downright nice if Thunar disabled the behavior by default.

Both Nautilus and Caja include such options, allowing scripts to open in an editor instead.  I have no experience with other file managers, but I hope they would do the same.

Bug report 575385 mentions this problem.

Offline

#8 2014-01-25 14:09:25

mtbrandao
Member
Registered: 2012-08-30
Posts: 6

Re: Disable "Execute" option on .sh files?

Boosh wrote:

Bump.

I hope these forums don't succumb to commonplace misconceptions about reviving old threads.

Has this issue been solved?  I searched the github commits but was unable to find anything to that effect.  I'm using Thunar 1.2.3 on the latest Debian Stable, so I can't confirm the latest version.


Not yet. I just lost the habit of double clicking an script. I just open it with "Open With" or "Send To" and execute it in terminal.

Offline

#9 2014-01-25 14:21:23

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,931

Re: Disable "Execute" option on .sh files?

This bug report/enhancement request exists for this particular issue. Perhaps you can post there to give it a friendly bump.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#10 2014-01-25 17:18:57

Boosh
Member
Registered: 2014-01-25
Posts: 4

Re: Disable "Execute" option on .sh files?

Thanks, guys.  That was helpful.

I gave the report as friendly a bump as I could muster.  Here's hoping someone takes notice.

Offline

#11 2014-01-25 18:31:20

MountainDewManiac
Member
From: Where Mr. Bankruptcy is Prez
Registered: 2013-03-24
Posts: 1,115

Re: Disable "Execute" option on .sh files?

Boosh wrote:

Thanks, guys.  That was helpful.

I gave the report as friendly a bump as I could muster.  Here's hoping someone takes notice.

I certainly took notice. I cannot do anything to help, but I thought about the issue that you describe and I agree that it's a valid thing to be concerned about. I do not (to my knowledge) have any malicious scripts on any of my devices. But I am not "every single Thunar user" and cannot say that others do not - especially since the second thing new linux users hear is that "you no longer have to worry about viruses and such" so they might not be as vigilant as they, perhaps, should be. (The first thing new linux users seem to "hear" is a warm welcome smile .)

Thank you for pursuing this issue.

Regards,
MDM


Mountain Dew Maniac

How to Ask for Help <=== Click on this link

Offline

#12 2014-02-02 19:25:16

Xen2050
Member
Registered: 2014-02-02
Posts: 4

Re: Disable "Execute" option on .sh files?

Hello, I've recently swtiched to XFCE and I can't stand this "Execute" scripts either, especially that there's no warning or confirmation and they're NOT executed in a terminal window, and I've accidentally had some scripts get executed by mistake and didn't even realize until later. Much like the bug report ToZ mentioned I also would love it if Thunar would act like Nautilus and Caja and provide options for editing, executing, or confirming upon activating a script file. Since Thunar completely ignores any Open With "use as default" settings and always Executes on double-click I had to either stop using Thunar or change it, so I tried this solution below.

I patched Thunar 1.6.3 so it never actually tries to launch files with it's "thunar_launcher_execute_files", instead it always uses "thunar_launcher_open_files" so you can change the default open with application and Thunar will actually listen to you. The "Execute" menu item still shows up, but it runs the "Open With" default application. Selecting multiple executable files still seems to run them as before, but I have never done that & didn't even notice until now, but I think I see how it could be patched similarly to what I've done below. For this patch I just deleted 8 lines in thunar/thunar-launcher.c.

I modified the thunar_1.6.3.orig.tar.bz2, 1,936.6 kB, md5 4f10d5d5576ce5127308d6badbac3afa From http://packages.ubuntu.com/source/saucy/thunar
For my test build I did't touch (or use) the debian patches (thunar_1.6.3-1ubuntu1.debian.tar.gz, 16.9 kB, md5 bca51ef5b3c4656af8769b8f21be4996), but they don't appear to modify thunar/thunar-launcher.c.
Then I had to install a bunch of build-essential and dev packages before configure would complete and make install.
I'm on Linux Mint 16 XFCE x86_64 (it's default kernel 3.11.0-12-generic) FYI.

I've kept the patched/modified thunar executable & tested it by copying it to /usr/bin/thunar on a fresh (live) system and it seems to work excellent, at least as good as the original thunar (which would segfault every few hours when two windows are open & closing one causes them all to close/crash).

Also, there's a Thunar running in daemon mode (at least in mint 16 xfce) that you need to kill with "thunar -q" or kill before you can run the new patched thunar.

Then you can easily change the default action of "Execute" using "Open with Other Application" to make it always open scripts with "Text Editor" to edit, or "Terminal Emulator" to run in terminal, or even "bash -c " to run "invisibly" like it does before the patch if you want.

Here's the Patch (made with diff -Naur origfile newfile)
diff -Naur a/thunar/thunar-launcher.c b/thunar/thunar-launcher.c
--- a/thunar/thunar-launcher.c    2013-05-05 10:37:23.000000000 -0600
+++ b/thunar/thunar-launcher.c    2014-02-01 23:22:17.909126358 -0700
@@ -1184,16 +1184,8 @@
     }
   else
     {
-      if (thunar_file_is_executable (file))
-        {
-          /* try to execute the file */
-          thunar_launcher_execute_files (launcher, &files);
-        }
-      else
-        {
           /* try to open the file using its default application */
           thunar_launcher_open_files (launcher, &files);
-        }
     }
}

*** EDIT: The other patch I posted later is much better, it treats shellscript files like regular files and uses the "Open With" menu & settings. This patch here doesn't execute any files, not even binaries.
There's another bug report where some people want to never execute any files so this might yet be useful for them, though it's only half way there (multiple files selected will still execute) ***

Last edited by Xen2050 (2014-02-04 00:36:06)

Offline

#13 2014-02-02 19:52:43

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,931

Re: Disable "Execute" option on .sh files?

Nice. Post your patch to the bug report for the devs. It might help.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#14 2014-02-03 23:37:37

Xen2050
Member
Registered: 2014-02-02
Posts: 4

Re: Disable "Execute" option on .sh files?

I've got a better patch working, that last one was more if a "it hurts when I do this... so don't do that" hack that wouldn't execute *ANY* files, not even binaries, I'm sure the dev's wouldn't want to do that.

I found the function thunar_file_is_executable in thunar/thunar-file.c that decides which files are executable or not and changed that instead. It looks at the file's mimetype and if it was "application/x-executable" or "application/x-shellscript" then it would execute, causing the bad behaviour with scripts running "invisibly" in the background, and for whatever reason you can't add or change a default "open with" application for executables. Changing thunar_file_is_executable to only say "application/x-executable" files are executable didn't seem to work, for whatever other reasons "application/x-shellscripts" were still coming back as executable (maybe x-shellscript is a subset of x-executable?). But, changing it to first check if a file's "application/x-shellscript" and if yes then don't say it's executable does work! Now "application/x-shellscript" files get the "Open with" default application that you can change, use terminal emulator, text editor, or even sh or bash to have it run "invisibly" like before.

I'll get it posted asap, along with some instructions I kept for downloading the source, patching & compiling in case anyone else wants to patch & run it too. And I'll look into the bug reports, but I don't know if I just need to send an email, or sign up, or mail in a M.Sc. and dna sample first (I've read some developers can be a little rude to newcomers ;-)

Offline

#15 2014-02-04 00:30:04

Xen2050
Member
Registered: 2014-02-02
Posts: 4

Re: Disable "Execute" option on .sh files?

Patch to treat shellscript files like any regular file, use "Open With" menu and set default application.

To build on Linux Mint 16 XFCE
(Ubuntu based, hopefully works on any Ubuntu & Debian based sys)

First have sources in /etc/apt/sources.list ("deb-src" line(s), "Enable source code repositories" checkbox in Mint's "Software Sources" program)

$ mkdir sourcedir
$ cd sourcedir

# Now Add build-essential (30.5 MB of archives) and others. Total 47.2 MB of archives on Mint16XFCE, FYI
$ sudo apt-get build-dep thunar

# Next command downloads all the source files (the ones on the ubuntu webpage) and applies the ubuntu patches (uses the .dsc & archive files, I think apt-get runs "dpkg-source -x [name].dsc"?) automatically.
$ apt-get source thunar

# Then make changes to souce code, ex. apply patch
$ patch --verbose -p1  </some/dirs/the_patch_file.patch

# Now compile/build. Also builds some new .deb files I didn't need with the compiled binaries inside.
$ cd thunar-1.6.3/
$ dpkg-buildpackage -b -uc -us

Then install the new thunar binary file. It's in thunar-1.6.3/debian/thunar/usr/bin/thunar It looks like other binaries are in .lib folders scattered about, there's another thunar but it's 3.8 MB, while the debian folder one is 749 kB
For only thunar just copy the new file to /usr/bin (or wherever your old thunar is hiding (run "which thunar") )
$ sudo cp thunar-1.6.3/debian/thunar/usr/bin/thunar /usr/bin/thunar
( But first backup the original /usr/bin/thunar in case you want it later, otherwise have to use apt-get or synaptic to reinstall it )
Or should be able to "sudo make install" but I think that would install a bunch of other thunar-related files.
Also, there was a Thunar running in daemon mode (at least in mint 16 xfce) that you need to kill with "thunar -q" or "kill ..." before you can run the new patched thunar.


*** gpg key stuff - Maybe Mint 16 XFCE, or Ubuntu, specific? ***
"apt-get source [package]" buries a warning (from dpkg-source running gpgv) about "gpgv: can't check signature: pub key not found".
It's supposed to be fixed by adding the debian-keyring package, but it's about 50 MB, and didn't help for me.
The command "sudo apt-key adv --keyserver hkp://keys.gnupg.net --recv-keys 059DD5EB" adds only the missing key to apt's keyring, but the error remains.
Solution: gpgv is a "stripped-down gpg that only checks signatures" and apparently doesn't use the apt keyrings (I think it's supposed to but doesn't here). gpgv only looks in ~/.gnupg/trustedkeys.gpg and ignores the keyrings already in /etc/apt/trusted.gpg and /etc/apt/trusted.gpg.d/
This works to create the missing keyring & add the right key "gpg --no-default-keyring --keyring ~/.gnupg/trustedkeys.gpg --recv-keys 0x059DD5EB" so apt-get doesn't give any gpgv error messages.
Or if you've already got the key in your apt keyring (from apt-key adv...") ignore the error from apt-get and once it's done verify it yourself with "gpgv --keyring /etc/apt/trusted.gpg thunar_1.6.3-1ubuntu1.dsc" or  with "gpg --keyring /etc/apt/trusted.gpg --verify thunar_1.6.3-1ubuntu1.dsc"
Adding the key to your personal keyring would work too: "gpg --recv-keys 0x059DD5EB" and "gpg --verify thunar_1.6.3-1ubuntu1.dsc"

I noticed the .dsc file has info on the source files, and if there's a wrong size or checksum mismatch then dpkg-source will complain & stop (unless it's given --no-check). And the .dsc file is just a pgp/gpg signed text message.


/***** Here's the patch, copy&paste to a file (like the_patch_file.patch) *****/

diff -Naur a/thunar-1.6.3/thunar/thunar-file.c b/thunar-1.6.3/thunar/thunar-file.c
--- a/thunar-1.6.3/thunar/thunar-file.c    2013-05-05 10:37:23.000000000 -0600
+++ b/thunar-1.6.3/thunar/thunar-file.c    2014-02-03 16:00:44.731015673 -0700
@@ -2714,8 +2714,13 @@
           /* check if the content type is save to execute, we don't use
            * g_content_type_can_be_executable() for unix because it also returns
            * true for "text/plain" and we don't want that */
-          if (g_content_type_is_a (content_type, "application/x-executable")
-              || g_content_type_is_a (content_type, "application/x-shellscript"))
+          /* do not execute x-shellscripts, may want to edit or run in terminal etc
+           * without the x-shellscript check they get marked as executable */
+          if (g_content_type_is_a (content_type, "application/x-shellscript"))
+            {
+              ; /* leave can_execute = FALSE*/
+            }
+          else if (g_content_type_is_a (content_type, "application/x-executable"))
             {
               can_execute = TRUE;
             }

Offline

Board footer

Powered by FluxBB