Using an external editor

Post

Posted
Rating:
#1 (In Topic #928)
Avatar
Trainee
When writing GUI scripts it makes sense to use the IDE, but for command line programs is there a way to run them directly from the Linux console, having created the script in an external editor? Thanks in advance for any help!
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Hi Median Joe and welcome to the forum.

You can use any text editor to create your code. You need to put #!/usr/bin/env gbs3 as the first line of the file and once you have saved it right-click and make the file 'Executable'.

There is a load of help here.
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Trainee
Hi cogier,

Many thanks! I've been using vim for some years and it makes conventional editing hard work by comparison.  :)
I found a basic syntax file for Gambas here here.

Hugely impressed by Gambas, Benoit is obviously some kind of God.  :shock:  I write a lot of number crunching code and was concerned that being an interpreted language, Gambas might not be up to the job, but I needn't have have worried. Even without using JIT it's fast enough for my needs.

Thanks again.
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Regular
stevedee is in the usergroup ‘Regular’

Median Joe said

…I've been using vim for some years and it makes conventional editing hard work by comparison…

Why not try Geany: Captain Bodgit: Geany Syntax Highlighter for Gambas Script
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
I wrote a script editor in gambas that has a few handy features like…

Uses the gambas gb.form.editor so has the same highlighting as the Gambas IDE and will format some text as the IDE does. (turns then into Then and stuff)
supports bash and gambas scripts
Click a button to toggle executable flag.
External tools (like pluma external tools) create scripts like plugins to do functions to the document/selected text.
A Run button to test the scripts.
Experimental key macro recorder. record keystrokes and repeat them at the press of a button. (works better with gtk than qt)
Lists the functions in a list , clicking a function in the list moves the cursor to it.
If you drop a .desktop file on it that points to a script it asks if you want to edit the ,desktop file or the file it points to.
Written in gambas, and you know gambas so you can modify the source at will.

Bruce Steers / scripted · GitLab

It's a bit WIP but i don't have many problems with it and use it all the time, it's especially handy for writing scripts as that's what it was made for.

The only real bug I've not been able to fix yet is sometimes when closing a tab they all close?  so i generally make sure i've saved edits before closing tabs.

Image

(Click to enlarge)

Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Trainee

stevedee said

Median Joe said

…I've been using vim for some years and it makes conventional editing hard work by comparison…

Why not try Geany: Captain Bodgit: Geany Syntax Highlighter for Gambas Script

Hi stevedee, Geany is a nice editor, in fact I used it before discovering vim. The thing which sets vim apart is the fact that you don't need to take your hands off the keyboard - ever!  With a little practice you'll find it much easier than having to keep moving from mouse to keyboard and back again. It takes a little while to build up the muscle memory but when you have it you won't want to use any other editor (which admittedly can be a disadvantage). Type vimtutor in the console for a quick interactive tutorial - you may get hooked!
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Trainee

BruceSteers said

I wrote a script editor in gambas that has a few handy features like…

Hi BruceSteers,

Very impressive! If you add vim bindings I would definitely use it.  :lol:  I continue to be amazed at Gambas and its capabilities. I tried FreePascal with Lazarus for a while but the Gambas IDE is easier to use and I prefer BASIC syntax to Pascal's.
Online now: No Back to the top

Post

Posted
Rating:
#8
Guru
BruceSteers is in the usergroup ‘Guru’

Median Joe said

BruceSteers said

I wrote a script editor in gambas that has a few handy features like…

Hi BruceSteers,

Very impressive! If you add vim bindings I would definitely use it.  :lol:  I continue to be amazed at Gambas and its capabilities. I tried FreePascal with Lazarus for a while but the Gambas IDE is easier to use and I prefer BASIC syntax to Pascal's.

ew, :lol: , i never got on with vim and use nano ;)
Like i say it's written in gambas and has the KeyPress event so you could probably add any vim bindings you like :)

And i agree about the other programming environments, i tried a few, all rather complicated, then i found gambas and was amazed at it's simplicity and nice syntax.

PS. to your original question.

There are 2 ways to launch a gambas script created from any editor.

Like Cogier said make the very first line, the "shebang" line, like this…
#!/usr/bin/env gbs3
then set the files executable flag
chmod +x /path/to/my/file.gbs
That file can now either be double clicked to launch or directly run from terminal. the shebang tells it to use gbs3 and it will run because it is executable (on most sytems).

Alternatively you can use gbs3 to run the file without a shebang or being executable.

gbs3 /path/to/my/file.gbs

You can also use various options with the gbs3 command.
gbs3 –help

Compile and execute a Gambas script.

Usage: gbs3 [options][–] [<script file> | <project directory> | - ]
       gbs3 –convert-project <input project directory> [<output directory where script is created>]
       gbs3 –convert-script <input script> [<output directory where project directory is created>]
       gbs3 –plugin <input script> [<output plugin cache directory>]

Options:
  -b –buildonly           process and compile the script without executing it
  -c –nocache             force the script compilation (do not check cache)
  -e                       execute the source code provided by the command line ( ':' separator )
  -g –debug               add debugging information to application
  -f –fast                use just-in-time compiler
  -h –help                display this help
  -L –license             display license
  -p –plugin              Compile the script, no main, define the class name as script base name entry point _Call(…)
  -S –strict              fail if 'Public' or 'Sub' are defined without a 'main' function
  -t –trace               turn on tracing option during execution
  -T –terse-listing       only print a very terse error report on compile errors
  -u –use <components>    force component loading ('comp1,comp2…')
  -U –unsafe              allows jit compiler to generate unsafe faster code
  -v –verbose             be verbose
  -V –version             display version
  -w –warnings            display warnings during compilation
  –convert-project        convert a simple project to a script
  –convert-script         convert a simple script to a project
  –                       stop any further option processing  
    •                        read the script from standard input
Online now: No Back to the top
1 guest and 0 members have just viewed this.