3 releases
0.1.2 | May 28, 2023 |
---|---|
0.1.1 | May 28, 2023 |
0.1.0 | May 30, 2021 |
#667 in Unix APIs
31 downloads per month
515KB
1.5K
SLoC
vrsh
A small shell written in rust as a way for me to learn rust
Long term goal/dream (not gonna happen), achieve POSIX compliance (https://pubs.opengroup.org/onlinepubs/009604499/utilities/xcu_chap02.html).
Customizable prompt
To customize the prompt, one can set the PROMPT
variable.
This can be done using the set var=val
syntax where val
is a string, please note that if single quotes ('
) are used for the string the content of the string is preserved and prompt expansions will be performed on the prompt, see prompt expansions.
If double quotes ("
) are used for the string, the standard expansions will be performed on the string (note that these are evaluated immediately whereas the single quote syntax is evaluated on each prompt display).
To make the prompt configuration permanent one can set the PROMPT
variable in the ~/.vrshrc
file (generated on application launch if it does not exist).
Prompt expansion
The following prompt expansions are currently supported:
%%
for the%
char.%n
username of the current user.%F{var}
to set the foreground color of the coming text, var must either be one of the supported colors (see prompt expansion colors); or a number in the range 0-255, see ansi 8-bit coloring.%f
resets the foreground color.%K{var}
Works the same as%F
but for background color.%k
resets the background-color.%g
prints git information according to the built-in git module (used in the example below).%d
or%/
print the current working directory in full.%~
prints the current working directory but replaces/home/current_user
to~/
.%~>
prints only the current directory with a leading/
(e.g. if the current path is/var/log
, this will print/log
). If the current working directory is/home/current_user
it will instead print~/
.%-<
prints only the parent directories of the current directory (e.g. if in/var/log
this will print/var
). If the current directory is root (/
) nothing will be printed.
Prompt expansion colors
To test colors in the current terminal, one can use the vrsh-colors
command which will print all 256 supported foreground and background colors.
The named colors and their numeric value are as follows:
red
= 1green
= 2orange
= 3blue
= 4purple
= 5bluegreen
= 6white
= 7gray
= 8darkred
= 9brightgreen
= 34brightblue
= 123pink
= 200yellow
= 220
Examples
An example of the prompt that I myself currently use is the one below, it is somewhat verbose though.
set PROMPT='%F{blue} %~%f %F{orange} as %f %F{purple}%n%f %g %F{brightgreen} ❯ %f'
PROMPT
Gives the following prompt:
One can utilize the %~<
and %~>
options to print the full path but only highlight the current directory, for example:
set PROMPT='%F{31} %~<%f %F{51}%~>%f %F{214} as %f %F{170}%n%f %g %F{46} ❯ %f'
Gives the following prompt:
Example output from the vrsh-colors
command:
Current & planned features
Currently only a small amount of features have been implemented but more are planned, feel free to suggest features to be added to the planned features list!
Current & planned features list:
- Execution of programs with given arguments.
- Support single quotes
'
- Arguments without spaces should be one argument e.g.
"asd""bsd"
should be one argument. - Support environment variables e.g.
$HOME
- Support comments
#
- Command history:
- Persistant (stored in history file in users home directory).
- Can reuse commands by using
arrow-up
to go back in history andarrow-down
to go forward in history.
- Some basic highlighting:
- Suggest previously used commands.
- Highlight (valid) commands.
- Highlight strings.
- Matching expansions
- Expansions (Look through https://www.gnu.org/software/bash/manual/html_node/Shell-Expansions.html for more):
- Command expansions using
$()
. - - -> any file matching.
- More... see above url
- Command expansions using
- Piping between programs
|
. - Redirects:
- From command output to file (
>
). - To program from file (
<
).
- From command output to file (
- Built in commands:
-
cd
-
exit
-
alias
-
~
-> the home directory of the current user.
-
-
source
- variables i.e.
A="some value"
- Program specific variables i.e.
SOME_VARIABLE="some_value" firefox
- Program specific variables i.e.
-
- Autocompletion
- For history, see above.
- File completion using
tab
. - Expanded file completion by tabbing through them when several options are available.
- Tab completion for commands in history.
- Prompt
- Shows current path.
- Git integration.
- Show current user.
- Show result of last command.
- Prompt on right side as well.
- Support starship integration: https://starship.rs/.
- Configuration using a file.
- Be able to add aliases.
- Configure color scheme.
- Customize prompt
- Background processes
&
- Sequentially executed commands
&&
Dependencies
~21MB
~419K SLoC