Language Selection

English French German Italian Portuguese Spanish

Script KATE to Automagically Compile/Execute Programs

Filed under
Software
HowTos


Script KATE to Automagically Compile/Execute Programs

By Gary Frankenbery



I teach high school computer science and programming, and I'm trying to transition my computer lab from MS-Windows only to MS-Windows/Linux dual boot.

For Computer Programming, my students first learn to program with Ruby. I try to keep it simple for these fledgeling programmers, so we have been using the Crimson Text Editor under Microsoft Windows to enter/edit the Ruby source code. The Crimson Text Editor makes it easy to configure a macro to execute whatever Ruby script is being edited: that is, the Crimson macro saves the file, then calls up the Ruby interpreter, and Ruby executes the script. Students accomplish this by simply by pressing the F5 function key while in the Crimson Text Editor.

So, I started wondering if I could configure the KDE Advanced Text Editor (KATE) under Linux to do the same thing with Ruby scripts? Yes, I know that KATE has an embedded terminal where one can activate the terminal window, click in it, and then type, for example,"ruby factorial.rb" and press the enter key, to execute the current Ruby script being edited in KATE. But, I wanted to have the current ruby script in the KATE editor to be both automatically saved, and then executed in a separate Konsole window, all triggered with the simple press of a shortcut key--just like Crimson under MS-Windows.

Could I do this? I've got at least one thing going against me--I'm not a bash shell programmer--I don't really know much shell scripting at all. However, I've got some things working for me--I am a programming teacher so I can program, bash scripting is well documented, and I can be very tenacious. So, I believe that with effort, persistance, and and lot of trial and error, I can figure out how to do this with KATE and Linux. And, so, I did. Then, I wanted to do more.

Since my more advanced computer programming students program use Java (not my personal choice--it's the language mandated by the College Board in the U.S.), I figured out how to configure KATE to automatically save and compile a Java program, and then I finally worked out a script to have KATE call up the Java Run Time Environment to execute the Java program. Obviously, other programming languages (Python comes to mind) can be accommodated as well by customizing these scripts (this, as teachers so often (annoyingly) say, is left as an exercise for the reader Smile).

KATE does permit you to embed scripts, so I'll display some KATE screenshots along the way, and explain how it's done. We'll start by configuring three scripts: Ruby Execute, Java Compile, and Java Execute.Then we'll look at how to configure shortcut keys to activate the scripts under KATE.

  1. With KATE on your screen, select Settings -> Configure Kate... from the
    menu.







  2. In the Configure Dialog box shown below, click External Tools in the left panel, then then click the New... button at the bottom.









  3. The Edit External Tool Dialog comes up (below). Here, we're going to configure KATE for Ruby Program Execution. Type in a description Label for the script (I used Ruby Execute). Then type in the script itself, with all the single apostrophes, double quotes, spaces, and symbols. Because this is tricky, you can copy the text on the next line, and paste it into the script box:


    cd "%directory" && konsole -e sh -c 'ruby "%filename"; printf "%s"
    "Press any key to exit . . . "; read $dummy'







    Since the KATE External Tool scripts like an executable name, just type konsole into the Executable: text box. Next, click the drop down list arrow by the
    Save: button, and select Current Document. Click the OK button. This window will
    close. Click OK again. You should now be back at the KATE main window.


  4. Now, let's configure the Java Compile script. Starting at the KATE main window, do steps 1 and 2 again. This time, edit the External Tool Dialog to look like the screen clip below. Again, the script code needs to be exact. Here it is so you can copy and paste, if necessary:



    cd "%directory" && konsole -e sh -c 'javac "%filename"; printf "%s" "Press any key to exit . . . "; read $dummy'








    Click the OK button, and at the next window, click OK again. You should be back at the KATE main window.

  5. Time to configure the last script to execute the Java program. At the KATE main window, do steps 1 and 2 above one more time. You should edit the External Tool Dialog to look like the clip below. Again, here's the scipt command which you can copy and paste:


    cd "%directory" &&  CF="%filename" konsole -e  sh -c 'java ${CF%.*}; printf  "%s" "Press any key to exit . . . "; read $dummy'








    Finally, we are done with the scripting part. Next we'll setup shortcut keys to launch our scripts.

  6. To get started, at the main KATE window, click the Settings->Configure Shortcuts menu choices as shown.








  7. You will see the Configure Shorcuts dialog box window shown below.



    Click the Java Compile script, click the button next to Custom (at the bottom), and press the key(s) you want to launch this script. You can see that I chose the F12 key to compile the current Java program. Click OK



    For the Java Execute script, I chose Shift-F12.




    For executing a Ruby program, I chose I chose Alt+R.



    So, after you configure the three shortcuts, you're done! You can now edit your programming source code in KATE, and quickly save, compile, and execute your Ruby and Java source code with these scripts simply by
    pressing the shortcut key(s).







Script Kate Article

By default, Debian derived Linux distros execute sh scripts using dash rather than bash. Because dash won't work correctly for the above Kate scripts, just substitute bash in place of sh in the above scripts.

Gary Frankenbery
January 4, 2009

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

More in Tux Machines

OSS Leftovers

  • Pharmaceutical industry gets first open source platform for Level 4 serialization
    Pharmaceutical companies today for the first time have an open source alternative for level 4 serialization with the launch of QU4RTET, a platform that provides them with new flexibility, transparency and affordability as they comply with global drug anti-counterfeiting laws.
  • Kontron Uses Open Source to Move Beyond Bare Metal
    Kontron, a company known for its embedded computing technology, is leveraging virtualization and open source to become a direct supplier to large service providers, promising to integrate hardware and operating system software with best-of-breed virtual network functions. That new sales strategy has evolved to support containers, particularly as they fit at the edge of the network, which for Kontron AG is the cell tower. In May, Kontron announced that its integrated SYMKLOUD open source platform now supports the latest versions of OpenStack for virtual machines and bare metal, as well as Kubernetes v1.10 for Docker and containers, via its distribution partnership with Canonical.
  • Open Source Expands In Finance With The FINOS Platform
  • Global Open Source Services Market Forecast to 2025 Published by Marketresearchnest
  • Synopsys ARC HS4x Processors Now Supported By GCC
    The GCC 8 compiler brought the Synopsys ARC CPU target while for the GCC 9 release is going to be support for the company's HS4x processors. Merged today to mainline GCC is support for the HS4x CPUs within the ARC target. Adding this newer generation of ARC processors to the GNU Compiler Collection code-base was just a few hundred lines of code with building off the existing target code.
  • GPL Cooperation Commitment gets more support for open source licensing
    Red Hat has announced its open source license enforcement initiative is making new strides. As part of the GPL Cooperation Commitment, 14 new companies have joined the effort to promote greater predictability for GPLv2 and LGPLv2.x licenses. “Through this initiative, we hope ultimately to increase participation in the use and development of open source software by helping to ensure that enforcement, when it takes place, is fair and predictable,” according to the commitment’s website.
  • The Global IP Exchange: Human ingenuity and open source technology
    He said: “Customers do increasingly care about open source, and if you don’t comply you are at risk of upsetting authors, as well as litigation and injunctions.” “If you’re just distributing internally, then you’re fine, but as soon as it leaves your company, then you’ve triggered an obligation.” For those who don’t comply, he warned that either the licensor, or the Free Software Foundation will find out.
  • How to Setup Python Virtual Environment on Ubuntu 18.04
    Python is a versatile programming language that can be used for many different programming projects(Web - Mobile - Desktop). Easy to set up, and written in a relatively straightforward style with immediate feedback on errors, Python is a great choice for beginners and experienced developers alike. Python 3 is the most current version of the language and is considered to be the future of Python. This article will guide you through installing Python 3 on your local Linux machine and setting up a programming virtual environment via the command line. This article will explicitly cover the installation procedures for Ubuntu 18.04, but the general principles apply to any other distribution of Debian Linux.
  • How expensive is globbing for sources in large projects
    Since we have the measurement script, let's use it for something more interesting. Modules are an upcoming C++ feature to increase build times and a ton of other coolness depending on who you ask. The current specification works by having a kind of "module export declaration" at the beginning of source files. The idea is that you first compile those to generate a sort of a module declaration file and then you can start the actual compilation that uses said files. If you thought "waitaminute, that sounds exactly like how FORTRAN is compiled", you are correct. Because of this it has the same problem that you can't compile source files in an arbitrary order, but instead you must first somehow scan them to find out the interdependencies between source (not header) files. In practice what this means is that instead of single-phase compilation all files must be processed twice. All scan operations must be done before any compilation jobs can start because otherwise you might start to compile a file before its dependencies are fully processed. The scanning can be done in one of two ways. Either the build system scans the sources meaning it needs to understand the syntax of source files or the compiler can be invoked in a special preprocessing mode. Note that build systems such as Ninja do not do any such operations by themselves but instead always invoke external processes to do their work.
  • Security updates for Monday

Software: Newsboat, FreeFileSync, Corebird, FileZilla, nomacs, RAV1E

  • Newsboat: A Snazzy Text-Based RSS Feed Reader
    Newsboat is a sleek, open source RSS/Atom feed reader for the text console. It’s a fork of Newsbeuter. RSS and Atom are a number of widely-used XML formats to transmit, publish and syndicate articles, typically news or blog articles. Newsboat is designed to be used on text terminals on Unix or Unix-like systems. It’s entirely controlled by the keyboard. The software has an internal commandline to modify configuration variables and to run commands.
  • FreeFileSync – Data Backup and File Synchronization App
    FreeFileSync is a free data backup and file synchronization app which is available in Linux systems enables you to seamlessly sync your backup data with the source data. When you take a backup of your HD, or any other disk drive, you should keep it in sync for the file changes you do from time to time. It is often difficult to remember which file/directories you have changed/deleted/updated since the last backup. FreeFileSync solves that problem and it can determine and sync only those changed/deleted/updated files in your backup.
  • Corebird Twitter Client – to Stop Working
    Corebird, the best native GTK+ Twitter client available for Linux desktops including Ubuntu will stop working on August 2018. This has been recently reported by the Corebird developer in patreon as well as in GitHub. This is mainly due to the policy change from Twitter which will remove UserStream API which is used by Corebird and other third party Twitter clients. In the patreon post, the developer stated that, the new API by Twitter named Accounts Activity API is too difficult to implement and he may not have much time available for development.
  • FileZilla – Best FTP Client for Linux, Ubuntu Releases version 3.34.0
    FileZilla is a free and open source FTP client available for Ubuntu, Mint and other Linux systems. FileZilla is the go-to software when you need a FTP client for your need. FileZilla is loaded with supports for FTP, SFTP, FTPS protocols and it is cross platform. It comes with nice user friendly and easy to use GUI.
  • nomacs 3.10.2
    nomacs is licensed under the GNU General Public License v3 and available for Windows, Linux, FreeBSD, Mac, and OS/2.
  • RAV1E: The "Fastest & Safest" AV1 Encoder
    Following the news about VP9 and AV1 having more room to improve particularly for alternative architectures like POWER and ARM, a Phoronix reader pointed out an effort that Mozilla is behind on developing the "rav1e" encoder. AV1 up to this point for encoding on CPUs has been - unfortunately - extremely slow. But it turns out Mozilla and others are working on RAV1E as what they are billing as the fastest and safest AV1 encoder. RAV1E has been in development for a while now but has seemingly flown under our radar.

today's howtos

Red Hat Looks Beyond Docker for Container Technology

While Docker Inc and its eponymous container engine helped to create the modern container approach, Red Hat has multiple efforts of its own that it is now actively developing. The core component for containers is the runtime engine, which for Docker is the Docker Engine which is now based on the Docker-led containerd project that is hosted at the Cloud Native Computing Foundation (CNCF). Red Hat has built its own container engine called CRI-O, which hit its 1.0 release back in October 2017. For building images, Red Hat has a project called Buildah, which reached its 1.0 milestone on June 6. Read more