Thunar: do not execute shell script files

Every time I need to open a shell script file that is executable (typically a SlackBuild), I right click on it in Thunar and select my editor from the Open with sub-menu. I miss the functionality of Nautilus, where I could tell the file browser to directly open such shell script files in a text editor when double clicked.

I searched a little and found several discussions about it. The one that offered a solution was in the XFCE forum. There, a user provided a patch for Thunar to treat shellscript files like any regular file, using Open with menu and setting a default application.

I decided to give it a try. My system is Slackware64 14.1, with XFCE 4.10 and Thunar 1.6.3. I downloaded the Thunar source, SlackBuild script and slack-desc file from a convenient mirror. I saved the patch (see below) to the same folder.

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;
             }

I modified the Thunar.SlackBuild, inserting the following lines just after the line that untars the source:

cd $TMP
rm -rf $PKGNAM-$VERSION
tar xvf $CWD/$PKGNAM-$VERSION.tar.?z* || exit 1

# Patch to treat shellscript files like any regular file, use "Open With" menu and set default application.
# http://forum.xfce.org/viewtopic.php?pid=31992#p31992
patch --verbose -p1  <$CWD/thunar-no-run.patch

cd $PKGNAM-$VERSION || exit 1

find . -exec touch {} \;

I recompiled Thunar and replaced the default package with the new one:

upgradepkg --reinstall /tmp/Thunar-1.6.3-x86_64-2.txz

Then I logged out and in. Now, double clicking on a shell script opens it in my preferred text editor, while right clicking brings the following menu:

thunar-no-shThis behaviour, however, does not apply for files placed on the Desktop. I suppose it reflects on how XFCE handles the Desktop folder.

Anyway, it is convenient enough.

Leave a comment

Filed under desktop, SlackBuilds, system

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s