Repository navigation
2. Creating Commands
To create commands in AHSh, you first need to download the source code. You could download the source code from the release (stable) or clone the repository for the latest changes (unstable)
git clone https://github.com/vrified-stupd/AHSh.git
Open the folder of the source code. You can see a directory called "term", open it and you can see the external commands.
Create a command by creating a file like "(changethiscommandname).h". Open that file. Inside, paste the code snippet below. It is just the "ver" command.
#include "../include/libs.h"
int sh_changethiscommandname(char **args);
int sh_changethiscommandname(char **args)
{
int i;
printf("AHSh a1.0.0:\n");
printf("Name: kappy wappy \n");
return 1;
}You can edit the command to your liking now as long as you know C.
As of version a2.0.0, Registering the command has been updated!
When you are finished with the command, save and close the file. You want to go back to the main directory and open "ahsh.c". Inside you will see this code:
int (*builtin_func[]) (char **) = {
&sh_echo,
&sh_help,
&sh_exit,
&sh_ver,
&sh_crdir,
&sh_crfile
};You can register your command by doing:
int (*builtin_func[]) (char **) = {
&sh_echo,
&sh_help,
&sh_exit,
&sh_ver,
&sh_crdir,
&sh_crfile,
&sh_changethiscommandname
};Save the file and close it.
When you are finished with the command, save and close the file. You want to go back to the "include" directory and open "func.c". Inside you will see this code:
int (*builtin_func[]) (char **) = {
&sh_echo,
&sh_help,
&sh_exit,
&sh_ver,
&sh_crdir,
&sh_crfile
};You can register your command by doing:
int (*builtin_func[]) (char **) = {
&sh_echo,
&sh_help,
&sh_exit,
&sh_ver,
&sh_crdir,
&sh_crfile,
&sh_changethiscommandname
};
Save the file and close it.
Next, open "str.h", which is located in the "commands" directory (I know, it's confusing that the commands directory doesn't hold the commands)
You should find this code:
```c
#ifndef STR_H
#define STR_H
/*
List of builtin commands, followed by their corresponding functions.
*/
char *builtin_str[] = {
"echo",
"help",
"exit",
"ver",
"crdir",
"crfile"
};
#endifJust like in "main.c", add your command, but this time, it's the name. e.g. "echo". Make sure it lines up with the functions in "main.c" like this:
char *builtin_str[] = {
"echo", //1
"help", //2
"exit", //3
"ver", //4
"crdir", //5
"crfile", // 6
"commandname" //7, if your command is the 7th command in the functions in main.c, it should be the 7th string here
};Build the commands and compile the code, you can find how to do that here.
Run AHSh and if everything goes well, if you type your command name, it will work!