Skip to content

Commit

Permalink
Add subst
Browse files Browse the repository at this point in the history
  • Loading branch information
Edd12321 committed Jun 15, 2023
1 parent 1615ffa commit 34805f8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Zrc is just 1.3mb in size because its implementation is to the point and simple.

## Features left to implement:

- [X] Standard library soon?
- [X] Standard library
- [X] Home directory config file (`~/.zrc`)
- [X] Aliases
- [X] **Rich return values** (not just 0-255, but any string)
Expand Down
9 changes: 9 additions & 0 deletions doc/man1/subst.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.TH SHIFT 1
.SH NAME
subst \- Substitute on a string
.SH SYNOPSIS
.BI "subst " <str>
.SH DESCRIPTION
The
.I subst
utility performs standard Zrc substitutions on its given arg and returns the resulting string.
12 changes: 11 additions & 1 deletion src/dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,15 @@ Command(exec) {
NoReturn;
}

/** Perform substitutions **/
Command(subst) {
if (argc != 2)
syntax_error("<str>");
std::string t{argv[1]};
str_subst(t);
return t;
}

Command(help);

const DispatchTable<std::string, std::function<std::string(int, char**)>> dispatch_table = {
Expand All @@ -688,7 +697,8 @@ const DispatchTable<std::string, std::function<std::string(int, char**)>> dispat
de(return) , de(set) , de(shift),
de(source) , de(string) , de(switch),
de(unalias) , de(unless) , de(unset),
de(until) , de(wait) , de(while)
de(until) , de(wait) , de(while),
de(subst)
};

/** Show a list of all BuiltIns **/
Expand Down

0 comments on commit 34805f8

Please sign in to comment.