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

Linux Devices/Open Hardware

  • Site.js and Pi

    Chatting about Pi, on a Pi, with a chat server running on Site.js on the same Pi.

  • This MicroATX Motherboard is Based on Phytium FT2000/4 Arm Desktop SoC @ 3.0 GHz
  • Rikomagic R6 Review – Part 1: Android Mini Projector’s Unboxing and First Boot

    Rikomagic R6 is a mini Android projector that looks like a vintage radio, or depending on your point of view a mini vintage television.

  • Brief on Behalf of Amicus Curiae Open Source Hardware Association in Curver Luxembourg, SARL v. Home Expressions Inc., No. 18-2214 (Fed. Cir.)

    Curver Luxembourg, SARL v. Home Expressions Inc. is a case of first impression for the Court of Appeals for the Federal Circuit. The question on appeal is whether a design patent’s scope is tied to the article of manufacture disclosed in the patent. In this amicus brief, the Open Source Hardware Association (“OSHWA”) explains the potential effects on open source hardware development, and design practice generally, of untethering design patent protection from the article of manufacture disclosed in the patent. A large percentage of open-source hardware combines both ornamental and functional elements, and industrial design routinely involves applying design concepts from disparate fields in novel ways. To engage in this practice, open-source hardware designers need to know the universe of available source material and its limits. Further, understanding the licensing requirements of open-source hardware begins with understanding how the elements that make up that hardware may or may not be protected by existing law. Accordingly, while many creators of open-source hardware do not seek patent protection for their own creations, an understandable scope of design patent protection is nonetheless essential to their ability to collaborate with other innovators and innovate lawfully. The brief argues that the District Court in the case—and every district court that has considered the issue—correctly anchored the patented design to the article of manufacture when construing the patent. The brief explains that anchoring the patented design to the disclosed article of manufacture is the best approach, for several reasons. Connecting the patented design to the disclosed article of manufacture calibrates the scope of design patent protection to the patentee’s contribution over the prior art. It avoids encumbering the novel and nonobvious application of prior designs to new articles of manufacture, a fundamental and inventive practice of industrial design. It aligns the scope of design patent protection with its purpose: encouraging the inventive application of a design to an article of manufacture. This balances protection for innovative designs with later innovators’ interest in developing future designs. Finally, anchoring the patented design to the disclosed article of manufacture helps fulfill design patent law’s notice function by clarifying the scope of protection.

Graphics: Gallium3D and AMDGPU

  • Gallium3D's Mesa State Tracker Sees "Mega Cleanup" For NIR In Mesa 19.3

    AMD developer Marek Olšák has landed a "mega cleanup" to the Gallium3D Mesa state tracker code around its NIR intermediate representation handling. As part of getting the NIR support in good enough shape for default usage by the RadeonSI driver, Marek has been working on a number of clean-ups involving the common Gallium / Mesa state tracker code for NIR.

  • AMDGPU DC Looks To Have PSR Squared Away - Power-Savings For Newer AMD Laptops

    It looks like as soon as Linux 5.5 is where the AMDGPU kernel driver could be ready with Panel Self Refresh (PSR) support for enabling this power-savings feature on newer AMD laptops. While Intel's Linux driver stack has been supporting Panel Self Refresh for years, the AMD support in their open-source Linux driver code has been a long time coming. We've seen them working towards the support since Raven Ridge and now it appears the groundwork has been laid and they are ready to flip it on within the Display Core "DC" code.

today's howtos and programming bits

  • CentOS 8 Package Management with DNF on the Command Line
  • AdamW’s Debugging Adventures: “dnf is locked by another application”
  • Managing user accounts with Cockpit
  • Download Ubuntu 19.10 ISO image to install on VirtualBox VM
  • GNU poke: Dealing with alternatives - Unions in Poke

    Computing with data whose form is not the most convenient way to be manipulated, like is often the case in unstructured binary data, requires performing a preliminary step that transforms the data into a more convenient representation, usually featuring a higher level of abstraction. This step is known in computer jargon as unmarshalling, when the data is fetch from some storage or transmission media or, more generally, decoding. Once the computation has been performed, the result should be transformed back to the low-level representation to be stored or transmitted. This is performed in a closing step known as marshalling or, more generally, encoding. Consider the following C program whose purpose is to read a 32-bit signed integer from a byte-oriented storage media at a given offset, multiply it by two, and store the result at the same offset.

  • Android NDK r21 moves to beta

    Android announced that NDK r21 is now in beta. Android NDK is a toolset for implementing parts of an app in native code. The release — which is the first long term support release — includes improved defaults for better security and performance. One of the key features in the release is an update to GNU Make to version 4.2, which provides a number of bug fixes, and enables ‘–output-sync’ to avoid interleaving output with error messages, the team explained. This is enabled by default with ndk-build. Additionally, GDB, the GNU project debugger, has been updated to version 8.3, which includes fixes for debugging modern Intel CPUs.

  • What is the history behind C Programming and Unix?

    If you think C programming and Unix are unrelated, then you are making a big mistake. Back in the 1970s and 1980s, if the Unix engineers at Bell Labs had decided to use another programming language instead of C to develop a new version of Unix, then we would be talking about that language today. The relationship between the two is simple; Unix is the first operating system that is implemented with a high-level C programming language, got its fame and power from Unix. Of course, our statement about C being a high-level programming language is not true in today’s world. This article is an excerpt from the book Extreme C by Kamran Amini. Kamran teaches you to use C’s power. Apply object-oriented design principles to your procedural C code. You will gain new insight into algorithm design, functions, and structures. You’ll also understand how C works with UNIX, how to implement OO principles in C, and what multiprocessing is.

Server: Mirantis, Containers, GraalVM and Pensando

  • Mirantis Partners With OpenStack Foundation to Support Upgraded COA Exam

    “With the OpenStack market forecasted to grow to $7.7 billion by 2022 according to 451 research, the demand for Certified OpenStack Administrators is clearly strong and set to continue growing for many years to come,” said Mark Collier, COO of the OpenStack Foundation. “We are excited to collaborate with Mirantis, who has stepped up to provide the resources needed to manage the COA, including the administration of the vendor-neutral OpenStack certification exam.”

  • How to use containers with an eye on security

    Containers are all the rage. With good reason. With containers, your company’s apps and service deployments become considerably more agile, more reliable, and even more secure. This is true for software development companies (who develop apps and services for other businesses), as well as companies looking to roll out web-based and mobile applications with an unheard of speed and reliability. But with any new technology, comes hurdles. One of the biggest hurdles for any business is security. Data breaches have become rampant and it’s on the shoulders of every company to do everything in their power to make sure they are rolling out technology that is as secure as possible. This idea should certainly be applied to containers. But what can you do to use containers security? Fortunately, there are a few steps that you can take from the very beginning.

  • GraalVM: Clearing up confusion around the term and why Twitter uses it in production

    What does the “umbrella term” GraalVM stand for? We interviewed Chris Thalinger (Twitter) at JAX London 2019. Hear what he has to say about the meaning of Graal and how it can benefit Twitter as well as the environment.

  • Pensando Systems Exits Stealth Mode With Plans To Take On Amazon AWS

    While normally we don't cover hardware start-ups on Phoronix, Pensando Systems has just exited stealth and given their focus will be heavily involved with Linux and in fact already have their first kernel driver mainlined. After announcing a $145 million (USD) Series-C round, Pensando Systems exited "stealth" and revealed the first details of what they are trying to achieve with this company led by many ex-Cisco staff. [...] Pensando has been on our radar since as I wrote about last month when they were just a stealth networking startup they already upstreamed their first Linux kernel driver. In the Linux 5.4 kernel is a Pensando "Ionic" driver for a family of network adapters. In this week's press release, Pensando didn't specifically call out Ionic but presumably is the backbone to their hardware. Now that they are beginning to talk about their ambitions, hopefully we see more Linux kernel patches from them soon.