blog :- https://my-hallo-project-blogs.hashnode.dev/wonderd-about-a-shell-in-rust
For details about the architecture and design decisions, check out the DESIGN.md.
A minimal shell implemented in Rust.
Right now this minimal shell has:
hallo
cd
echo
pwd
type
complete
jobs
history
declare
exit
- Navigation —
cd,pwd - Quoting / escaping —
echosupports single & double quotes and handles backslashes (escape sequences) hallo— display a simple bannertype— check whether a command is built-incomplete— register or inspect custom completionsexit— quit the shelljobs- helps to see all running and done jobs which are in the backgroundhistory- see all the command you typed till now from the start of the shelldeclare- helps to declare a shell variables
>/1>— stdout (truncate)>>/1>>— stdout (append)2>— stderr (truncate)2>>— stderr (append)
Tip: use
>to overwrite,>>to append
This shell provides flexible completion for commands and filenames, plus a way to register custom completion scripts.
-
Command completion
Tab— complete the current partial command when a single match existsTab+Tab— list matching commands for the current partial input- Matches include built-in commands and external commands
-
Filename completion
Tab— complete file or directory names for the current argument- Supports nested paths and multiple arguments
Tab+Tab— show matching filenames for the current argument- A completed directory may receive a trailing
/to indicate it's a directory
-
Custom completion (the
completebuilt-in)- Register:
complete -C <script-path> <command>— attach a completion script to<command> - Inspect:
complete -p <command>— show the registered completion for<command> - Unregister:
complete -r <command>— remove a registered completion - After registration, completions for the command will use the provided script
- Register:
-
Behavior & tips
- Completion follows the filesystem and command name casing (case-sensitive on case-sensitive systems)
- Use
Tabto save typing andTab+Tabto explore options - if there is common prefix in the command or for file/dirs completeion then the longest common prefix is used
- if you end a command with
&(e.g<command> &) then that is executed in the background it will generate a job number and a pid and we can still use the shell for other commands - if you want to see all the commands running in the background you can use the built-in command
jobsto see - to check the recent jobs
+for the recent command that gone to background-for the second recent commandspace for rest of the commands
- if it has a Status
Runningthen its still running in Background else thenDonemeans its completed - if the background job is completed it prints with
Donebefore running another command
- it will help to pass the stdout of one command to the stdin of the another command (e.g
<command1> | <command2>command1's stdout will be gone to the stdin for the command2) - it also support if one of the command is a BUILT_IN command's
- it also support multi command pipelines for external command's
- if you want to see all the commands you typed since the start of the shell you use the BUILT-IN command
historyfor viewing - you can also use flags with a path:
-rflag: reads the history from the path provided and add it to the history of the shell-wflag: writes all the history of the shell in to the path script provided-aflag: appends the new history to the path script provided
- there is also support for the arrow key:
- if pressed
<UPARROW>it gives the most recent command typed - if pressed
<DOWNARROW>it gives the back recent command typed
- if pressed
- also support for env variable
HISTFILEif there with the path then it reads the history and add it to the history of the shell on the start - after hitting exit in the shell the exit is also added to the history of the shell
- you can add your own shell variables with its value with the help of
declareBUILT_IN command - if you want to check if the shell variables exists or not you can do it with the help of
-pflag with the shell variable it will print if its there else it well give not present - it also support expansion so after declaring the variable you can use it other command as
$<Variable>if the<Variable>is declared then it will use the value the<Variable>was given - it also supports expansion as
${<Variable>}for checking for the more appropriate variable declared - if the
${<Variable>}and theVariableis not declared then it will treat it as empty variable
Note : the shell variable you want to declare must start with a letter or _ and it can contain letters,digits and underscore in the rest of the body
