Background
Text editors support us to create and write codes in various programming languages. In several text editors (such as Visual Studio Code), they can also execute code written without executing or compiling the code in external terminal.
Many operating systems has their own standard text editor such as Linux with its own text editor gedit
. Unlike other standard text editors, gedit
has special features. It can highlight codes based on code written, and it can also execute codes using plugins!
I'm currently using Ubuntu 18.04 as primary operating system and get interested to try external tools plugin in gedit
which has been installed by default in Ubuntu 18.04.
Methodology
By opening Text Editor first
By clicking text editor menu on the Top Bar and accessing the preferences...
Accessing Plugins tab, we can enable "External Tools" by checking it and finally use it...
Finally, we can create some extra commands for executing code externally by access external tools menu (by clicking Text Editor menu -> Manage External Tools...).
By clicking the plus sign button in the bottom left corner, it will create the new empty tool). There are interesting stuffs that we can see with this external tools menu
-
Space for writing external tools command (usually using Linux
bash
code, but in my observation it can also usePython
). - Shortcut key for triggering keyboard shortcut to execute the commands.
- Input for specify the input source (if the program receives some input).
- Output for specify the output.
- Applicability for specify which document supports for this external tool command.
for example, I would like to execute some JavaScript code using external tools. We knew that we can use node appname.js
for executing JavaScript file using Node.js (assuming Node.js has already installed). By typing the command inside the space,
node $GEDIT_CURRENT_DOCUMENT_NAME
and applying shortcut using F5, we have successfully created our first external command. $GEDIT_CURRENT_DOCUMENT_NAME
is some gedit
variable that we can see in this link.
Simulation
Let's test our command in our simple JS file by pressing F5 and we found show the results based on Node.js command.
Let's try the another external code for opening files such as Python and JavaScript by typing this code and same shortcut.
#!/bin/sh
TYPE=$GEDIT_CURRENT_DOCUMENT_TYPE
APP_NAME=$GEDIT_CURRENT_DOCUMENT_NAME
# checking file mime-type
# $TYPE
# switch conditional
case $TYPE in
## nodejs
"application/javascript")
node $APP_NAME
echo "Nodejs file executed"
;;
## python
"text/x-python")
python3 $APP_NAME
echo "Python file executed"
;;
## else
*)
echo "Not supported programming file"
;;
esac
It executes successfully on JavaScript file (Node.js)
And it also executes successfully on Python file
Conclusion
In conclusion, gedit
can executes file externally using external tools. By using some bash
code, it can used for create command for execute codes for various functions.
Some reference(s)
- GNOME Gedit External Tools documentation (https://wiki.gnome.org/Apps/Gedit/Plugins/ExternalTools)
Top comments (1)
i try this for python3 but not succes.