2
3
Fork 0
Browse Source

Adds a .sloshrc file that is separate from the login file .slosh. Updates man page.

master
sloum 12 months ago
parent
commit
35641a2a43
  1. 14
      builtins.go
  2. 2
      commandRunner.go
  3. 4
      main.go
  4. 14
      slosh.1

14
builtins.go

@ -81,10 +81,18 @@ func SetLocal(items []string) error {
return nil
}
func LoadSloshFile() error {
func LoadSloshFiles() error {
alias = map[string]CommandLine{}
homeSloshFile := filepath.Join(HomeDir(), ".slosh")
lines, err := getRcLines(homeSloshFile)
if IsLoginShell {
loginSloshFile := filepath.Join(HomeDir(), ".slosh")
lines, err := getRcLines(loginSloshFile)
if err != nil {
return err
}
parseRcLines(lines)
}
interactiveSloshFile := filepath.Join(HomeDir(), ".sloshrc")
lines, err := getRcLines(interactiveSloshFile)
if err != nil {
return err
}

2
commandRunner.go

@ -153,7 +153,7 @@ func (cg CommandGroup) Execute() error {
err = RemoveAlias(cg.commands[0].Args[2])
}
case "lsf":
err = LoadSloshFile()
err = LoadSloshFiles()
default:
err = fmt.Errorf("Unknown builtin call\n")
}

4
main.go

@ -158,9 +158,7 @@ func getSloshPrompt() string {
func initShell() *ln.State {
Hostname, _ = os.Hostname()
setCompletionNames()
if IsLoginShell {
LoadSloshFile()
}
LoadSloshFiles() // Loads login and rc
return setUpLineInput()
}

14
slosh.1

@ -1,6 +1,6 @@
.TH "slosh" 1 "09 JUL 2021" "" "General Operation Manual"
.SH NAME
\fBslosh\fP- sloum's shell, a simple command shell
\fBslosh\fP - SLOum's SHell, a simple command shell
.SH SYNOPSIS
.nf
.fam C
@ -14,7 +14,7 @@
slosh works like most shells: commands are issued as a series of whitespace separated words/symbols. When the enter key is pressed the command sequence is parsed and acted upon.
.SS Paths
Contrary to many shells, changing paths can occur just by typing an absolute or relative path. All paths must begin with \fI..\fP, \fI./\fP, \fI~\fP, or \fI/\fP for slosh to recognize them for this purpose. The \fIcd\fP and \fIdir\fP command words are also available for compatibility reasons and they are aliased to the comandless behavior (the \fIcd\fP is dropped and it is treated as a bare path).
.PP
Filepath globbing via \fI*\fP and \fI**\fP, as wildcards, within a path will be expanded to all valid paths that can be represented by the wildcards. Each of these paths will be treated as a separate argument.
.SS Strings
Using quotes around a group of words will tell the shell to treat them as a single argument being passed to the given program. A string created with double quotes will have any variables within it expanded. A string created with single quotes will not have variables expanded and will be treated literally.
@ -25,12 +25,15 @@ slosh supports very basic output redirection via the \fI>\fP (to write to a file
.SS Command Continuation
Running multiple subsequent commands is achieved via the \fI&&\fP command. If any command in a series of commands joined by \fI&&\fP exits with a non-zero exit code, execution of further commands will stop. The \fI&&\fP is also very useful for setting local execution environment variables (see: local variables).
.SS Variables
slosh has two types of variables. A \fIglobal\fP variable is created via the \fIset\fP keyword. The first argument to \fIset\fP is the name of the variable that is being set, and any subsequent arguments are concatenated into a space separated string (unless they are already a string, which is passed as is). Global variables can be accessed at the command line by prefixing their name with a \fI$\fP. Thus, \fI$SHELL\fP would get expande, but \fISHELL\fP would not. Expansion happens when the command is issued from the shell and will not occur within single quoted strings. Any variable that does not exist, but is referenced, will be treated as an empty string for expansion purposes. A global variable can be removed from the system via the \fIunset\fP command, which takes a single argument: the name of the variable to unset.
A local variable is created via the \fIlet\fP keyword. The first argument to \fIlet\fP is the name of the variable, any subsequent arguments are treated as the value and concatenated together as a space separated string (unless they are already a string, which is passed as is). Local variables cannot be accessed via the command line and are only in the environment of any other commands being run from the same command line entry (joined via the \fI&&\fP command). They cease to exist when all commands from the command line entry are finished executing (or execution has halted due to error).
slosh has two types of variables:
.PP
A \fIglobal\fP variable is created via the \fIset\fP keyword. The first argument to \fIset\fP is the name of the variable that is being set, and any subsequent arguments are concatenated into a space separated string (unless they are already a string, which is passed as is). Global variables can be accessed at the command line by prefixing their name with a \fI$\fP. Thus, \fI$SHELL\fP would get expande, but \fISHELL\fP would not. Expansion happens when the command is issued from the shell and will not occur within single quoted strings. Any variable that does not exist, but is referenced, will be treated as an empty string for expansion purposes. A global variable can be removed from the system via the \fIunset\fP command, which takes a single argument: the name of the variable to unset.
.PP
A \fIlocal\fP variable is created via the \fIlet\fP keyword. The first argument to \fIlet\fP is the name of the variable, any subsequent arguments are treated as the value and concatenated together as a space separated string (unless they are already a string, which is passed as is). Local variables cannot be accessed via the command line and are only in the environment of any other commands being run from the same command line entry (joined via the \fI&&\fP command). They cease to exist when all commands from the command line entry are finished executing (or execution has halted due to error).
.SS Aliasing
The \fIalias\fP command takes as its first argument the new command name that you are creating. All subsequent values are treated as the command that will be run when the new alias name is called. Aliases are not recursive (they will not expand values from other aliases when run).
.SH FILES
The shell will attempt to access the file \fI~/.slosh\fP when it starts up. Any commands inside of it will be run. This is a good place to set aliases, global variables, run any initialization commands, etc. Commands are run as if they were typed in line by line at the shell and are not treated differently for being in this file. One exception exists: any line beginning with \fI#\fP is treated as a comment and is ignored when processing the slosh file.
The shell will attempt to access two files, \fI~/.slosh\fP and \fI~/.sloshrc\fP, when it starts up - depending on the run environment. If the shell is a login shell the both will be run, with \fI~/.slosh\fP being run first. If it is not a login shell, but is still an interactive shell, then only \fI~/.sloshrc\fP will be run. Any commands inside of these files will be executed. These are good places to set aliases, global variables, run any initialization commands, etc. Commands are run as if they were typed in line by line at the shell and are not treated differently for being in these files. One exception exists: any line beginning with \fI#\fP is treated as a comment and is ignored when processing the slosh file.
.SH VARIABLES
The \fB$SLOSH_PROMPT\fP variable can be set to create a prompt that differs from the initial one provided by the shell. It does not allow escape characters/codes/ansi-sequences/etc; these will have any non-printing characters removed and the remaining characters will be printed verbatim. There are some recognized replacement patterns that can be used to create a slightly more dynamic prompt:
.TP
@ -55,6 +58,7 @@ The current host
The current user
.SH LIMITATIONS
slosh is not a programming language the way bash and many other shell/command languages are. There are no if statements, no loops, etc. The general ethos behind slosh has been: if you want to program you can either write a bash script and execute it with bash or you can use a programming language. slosh is meant to be a very minimal shell that provides a basic feature set to allow you to navigate a system successfully, but not much more.
.PP
There is no support for job control (moving processes to the background, foreground, etc). A terminal multiplexer (tmux, dvtm, mtm, screen) can easily solve the problem of working on multiple things from a single terminal window and as such there is no need, in post cases, for the shell to handle this.
.SH BUGS
There are very likely bugs. This software was largely made for personal use and is being made available so that others can modify it to their needs if they would like. Feel free to fork and patch as you see fit (within the terms of the license).

Loading…
Cancel
Save