Tips and Tricks - justlostintime/GambasShell GitHub Wiki

Tips And Tricks

Using :; as a separator in a command line

Since : is used for name space definition, we now use the :; to seperate multiple statements on a single line.

Correcting Block after entering and error or Just changing block

Example:
begin
  dim a as string = "test string"
  for i as integer = 0 to a.leg
    print a[i];;
    next
  end
or
for i as integer = 0 to 20
  print j
next

Now there is an obvious error above - a.leg or the j , You don't have to retype it
just enter:
edit
by it's self. From here you can edit/change this block. The block will be executed
as soon as you save and quit the editor. If you want to save this block permanently
just change the name during the save phase.

When you installed gsh, both a nanorc and vim/vi rc where installed
so the code should be highlighted.
to choose your editor set the $editor global variable
$$editor="/usr/bin/vi" 
or
$$editor="/bin/nano"
The default editor is nano, to make your choice permanent you need to add it to the
~/.gshrc file
By the way you can edit any, sub/class/struct/variable in gsh

It is Possible to run the last block of code executed again by simply entering Run Without any parameters ...

Inserting Gambas variable values into a Linux CLI command

$[gambasVariablename]  Inserts a Gambas variable into the cli command line
$ShellGlobalVariable   Inserts a Gsh global variable into the cli command line

Example:
for i as integer = 0 to 10
  $a = i
  dim a as integer = i
  echo This is the Gambas Variable {a} and this is the gsh variable $a
next

What to do when things go south/gsh does unexplained things

If the shell acts strange, delete the ~/var/gsh.image and any /dev/shm/'username'gsh 
and /dev/shm/'username'col you find. then restart gsh, for a clean restart. 
Use savesubs and saveclass commands often to save your work. Theses are only in the image
until you save them to disk.
The system puts them into your local ~/vars/subs and ~vars/class ~/var/struct directories. 
They will be loaded from here if not found in the image upon demand.
gsh operates on an in memory image, which is auto saved when you create a global variable, 
this includes vars/subs/class/structs.
This image is synced to the disk upon exit and reloaded upon start restoring your last session state.
So... It can get messed up.... the above deletes the image and in memory db used to store global variables.
example:
rm /dev/shm/mynamcol /dev/shm/mynamegsh ~/vars/gsh.image
abort
The abort prevents the image from being dumped to disk.
then restart gsh.

What to do if gsh gets slow to start

Since gsh is image based, when you have a large number of global variables, 
or of a large size the load time can get a little long to solve this, you can as 
above reset the image. Or you can use the load and save functions for 
variable data that must be kept.
example:
varwrite xx
The variable is written to the ~/vars/xx a file of the same name as the variable.
Your can write a number of variables using
varwr xx yy xx ....
you can restore the variable using
varread xx
or many using
varrd
Then you can remove each from memory using vardel
vardel xx
or
clearvars  ' this will delete all user created variables
Variables are not loaded by reference you need to explicitly load them from storage.