Skip to content

Files, Directories with Overview

Gambas Shell GSH edited this page Aug 18, 2025 · 4 revisions

Overview of Search and inclusion process

GSH scripts, plugins and classes are linked dynamically, when a class/sub/struct is referenced by a sub/class then it is dynamically loaded and linked to the calling sub/class.

When a command is read/entered into gsh it first searches for a plugin by that name and then looks for a script of that name. As the sub or script is loaded, references to classes or structures or subs are linked to the loading object dynamically.

This approach allows the development of small apps that can be combined at compile time into a executable script.

Directories

~/vars

This is the root directory used by gsh to store retrieve data and programs. Most operations involve this directory path.

~/vars/subs /usr/share/gsh/subs

gsh searches these directories for integrated plugin functions. It searches in the order shown. the $subspath variable can be set to override these directories. /usr/share/gsh/subs contains the default versions, this should be last in the search path. Subs are plugin modules that are loaded dynamically as referenced by shell scripts and programs.

~/vars/class /usr/share/gsh/class

gsh searches these directories for integrated class definitions. It searches in the order shown. the $classpath variable can be set to override these directories. /usr/share/gsh/class contains the default versions, this should be last in the search path. Classes are plugin classes that are loaded dynamically as referenced by shell scripts and programs.

~/vars/struct /usr/share/gsh/struct

gsh searches these directories for integrated structure definitions. It searches in the order shown. the $structpath variable can be set to override these directories. /usr/share/gsh/struct contains the default versions, this should be last in the search path. Structures are included when referenced by shell scripts, programs, plugins and classes. This is particularly useful for structures or classes that are used by many apps.

~/vars/scripts /usr/share/gsh/scripts

gsh searches these directories for executable gsh scripts. It searches in the order shown. These are in fact games, tools etc. The $scriptpath variable can be set to override these directories. /usr/share/gsh/scripts contains the default versions, this should be last in the search path.

Some example paths

scriptpath="~/vars/scripts;~/vars/games;/usr/share/gsh/scripts"
structpath="~/vars/struct;/usr/share/gsh/struct"

Files

~/vars/profile.gsh

This file is updated by the latest install and is executes once after the install to update and changed environment configurations. You should be prompted to run update when ever this changes.

Example file

#!/usr/bin/gsh
'' Defaults to be loaded into an empty system
'' Script for Shell Version 1.5 and above
'' Functions in this file or the plugin directory are loaded as
'' plugins each time the gsh starts or as needed by the shell.
'' The comment lines starting with two single quote marks will be printed by the help
'' function. See the /usr/share/gsh/plugin directory. Or
'' your own plugins from ~/vars/plugin
'' so :
'' '' this is help
'' will be printed when detailed help is required
'' may contain as many lines as required after the Sub declaration
'' Extern, Include and Use may be declared in the body of any function
'' each is treated as a stand alone Program
'' see Sub clearhist for an example of extern
'' Dont use public that is assumed.
'' if you call a function from this file during loading then
'' it should be defined before you call it

$profile = true  ' sets this to true on the first load of the profile. only done upon first init

print "Gsh Profile Version";;$gshversion;;"Loaded"

alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
alias home='cd ~'
alias ??='lprint'
alias ps='ps -l'
alias hh='hist(-10)'
alias path='? env["PATH"]'
alias exit='Quit 0'
alias tcb='toclipboard'
alias fcb='fromclipboard'
alias done='loop until true'
alias clearsub='clearsubs'
alias clearvar='clearvars'
alias pwd='/bin/pwd'
alias foreach()='do:;for each value as variant in &1:;&2:;next:;done'
alias ifor()='for i as integer = &1 to &2:;&3:;next'

~/.gshrc

This file behaves in much the same way as the .bashrc. '~/.gshrc' contains gsh shell commands. This file is executed each time a copy of gsh is started.

Example file

#!/usr/bin/gsh
alias ifor()='for i as integer = &1 to &2:;&3:;next'
alias foreach()='do:;for each value as variant in &1:;&2:;next:;done'
alias less='less -c -N -R'
$textfont = "spacemono nerd"
$PATH=$PATH&":/usr/local/go/bin"
$editor="kwrite"

~/vars/subs/onstart

This plugin is called whenever an interactive terminal session is started.

Example file, Default one provided by system. This is a plugin and executed in the context of the gsh app.

Sub onstart() As Boolean ' executed when gsh starts an interactive session
''' Executed when gsh starts an interactive session
''onstart()  - Executed at startup of interactive session
''             Default version runs fortune if it is available

If system.exist("fortune") Then
        Dim stmnt As String
        Dim lines As String[]
        Exec ["fortune"] To stmnt
        lines = Split(stmnt, "\n", "\"", False, True)
        cls
        Print "\e[37;42m\e[" & Str(lines.count - 1) & ";" & file.out.term.width & "H\e[1J\e[1;1H";
        Print stmnt & "\e[0m"
Endif

Try env["EDITOR"] = system.find("kwrite")
If Error Then
    env["EDITOR"] = system.find("nano")
Endif
$editor = env["EDITOR"]

dim defaultNerd as string =  "\"\\e[36m\\e[37;46m\"&str(now)&\"\\e[36;101m\\e[37;101m\"&env[\"PWD\"]&\"\\e[0m\\e[91m\\e[0m\""

If sharedmem.exist("nerdmode") and if Not $nerdmode then
        If Not sharedmem.exist("textfont") Then $TextFont = "mono"
        If $textfont Like "*nerd*" Then
            $prompt = defaultNerd
            $nerdmode = True
        Else
            $nerdmode = False
        Endif
else if $prompt="\"$\"" then
    If Not sharedmem.exist("textfont") Then $TextFont = "mono"
    If $textfont Like "*nerd*" Then
        $prompt = defaultNerd
        $nerdmode = True
    Else
        $prompt = "\"str(now)&\":\"&env[\"PWD\"]&\" > \""
        $nerdmode = False
    Endif
endif

Return True

Catch
   Print error.text
   Return False
End

~/vars/subs/onexit

This plugin is called when ever an interactive session is terminated.

Example file, Default one provided by system. This is a plugin and executed in the context of the gsh app.

Sub onexit()
''' Executed when gsh  exits interactive sessions
''onexit()  This Function is executed at the end of an
''          interactive session. This is always available
''          Not deleted by clearsubs system Function
print "Exit"
end

Sample Scripts

Test the speed of memory access

#!/usr/bin/env gsh
Do
 With sharedmem
   Print "Test each of the methods for access/updating a gsh variable, this can take a while"
   Print "The test for each type is execute 1,000,000 times\n"
   Print "Test Speed to Access script Variables using $varname access method, locking"
   Dim starttime As Float = Timer
   Dim i As Integer = 0
   Dim a As Pointer
   Dim b As SharedMemSymbol

   $i = 59
   For i = 0 To 1000000
     If i % 100000 = 0 Then Print $i
     Inc $i
   Next
   Print "Total time "; Timer - starttime

   Print "Test Speed to Access script Variables using Symbol object access method, locking"
   starttime = Timer
   $i = 89
   b = .symboltable["i"]
   For i = 0 To 1000000
      If i % 100000 = 0 Then Print b.value
      Inc b.value
   Next
   Print "Total time "; Timer - starttime

   Print "Test Speed to Access script Variables using mem access interface, no locking"
   starttime = Timer
   $i = 98
   a = ._varptr("i")
   For i = 0 To 1000000
      If i % 100000 = 0 Then Print .usermem[a]
      Inc .usermem[a]
   Next
   Print "Total time "; Timer - starttime

   Print "Test Speed to Access script Variables using integer@ptr access method, no locking"
   starttime = Timer
   $i = 99
   b = .symboltable["i"]
   a = b.Dataptr()
   Print a, Integer@(a)
   For i = 0 To 1000000
      If i % 100000 = 0 Then Print Integer@(a)
      Integer@(a) = Integer@(a) + 1
   Next
   Print "Total time "; Timer - starttime
End With
done

Clone this wiki locally