{"id":22189838,"url":"https://github.com/harshsikhwal/sshell","last_synced_at":"2026-04-20T05:31:52.940Z","repository":{"id":143215475,"uuid":"232312089","full_name":"harshsikhwal/sshell","owner":"harshsikhwal","description":"A simple shell written in C","archived":false,"fork":false,"pushed_at":"2022-02-22T04:42:34.000Z","size":146,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-06T10:58:00.169Z","etag":null,"topics":["bash","c","shell","terminal"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/harshsikhwal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-01-07T11:40:30.000Z","updated_at":"2022-02-22T04:42:37.000Z","dependencies_parsed_at":"2023-04-27T13:02:19.425Z","dependency_job_id":null,"html_url":"https://github.com/harshsikhwal/sshell","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/harshsikhwal/sshell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harshsikhwal%2Fsshell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harshsikhwal%2Fsshell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harshsikhwal%2Fsshell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harshsikhwal%2Fsshell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/harshsikhwal","download_url":"https://codeload.github.com/harshsikhwal/sshell/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/harshsikhwal%2Fsshell/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32034593,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","c","shell","terminal"],"created_at":"2024-12-02T11:38:47.590Z","updated_at":"2026-04-20T05:31:52.919Z","avatar_url":"https://github.com/harshsikhwal.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sshell\n\nA simple shell written in C where you can hook your commands easily and play with it.\n\nFolder structure:\n* sshell\n\t* src\n\t\t* commands\n\t \n\nThis code is divided into following files:\n* src/simple_shell.c\n* src/command_handler.h\n* src/prompt.h\n* src/statement_handler.h\n* src/util.h\n* src/commands/standard_commands.h\n\nLibraries used:\nstdio.h\nstring.h\nstdlib.h\nunistd.h\nlimits.h\ntermios.h\nstdarg.h\n\nsshell contains the main executable. The code initializes terminal (termios), initializes asl (archived statement list) required for history and initializes commands and spawns the shell (prompt with the current path)\n\nThe user can enter \"statement\" and execute commands as described in command_handler.h\n\nA \"statement\" is comprised of \"command\", \"flags\" and \"values\". The first word being the command.\n\nOnce a statement is entered by the user, it is tokenized to command, flags and values in statement_handler.h. Each of this command is stored in asl or archived statement list which is required by \"history\" command.\n\nAfter preprocessing and tokenization, the command is checked against the entries as specified by the programmer.\n\nHow can we hook commands?\n\nThis code uses a common data structure which can be used by any subroutine specific to a command. The data structure:\n\n```C\nstruct command_data_struct\n{\n    char _command[256];\n    char _flags[128][128];\n    char _values[128][256];\n    unsigned int _flags_count;\n    unsigned int _values_count;\n};\n```\n\nThis contains the command, flags and values in sequence in which they were written by the user. This can be passed to other command handling routines.\n\nThe commands can be hooked into the code in command_handler.h:\n\n```C\nvoid command_register_init()\n```\n\nIn the abve function, you can add the command in list:\n\n```C\n// Command exit\nnew_entry = create_command_entry(1, \"exit\", 0);\ncommand_register_add(new_entry);\n```\nYou need to assign a unique \"id\" as specified in the first argument. The second argument is the command itself. The third is the number of flags and the corresponding flags can be sent as parameters (using stdarg.h for variable argument)\n\nExample of variable argument:\n\n```C\n// Command history\nnew_entry = create_command_entry(2, \"history\", 1, \"c\");\ncommand_register_add(new_entry);\n```\n\nThe unique id must be unique to each command. Using this id, we will call the specific subroutine and pass the data.\n\n```C\nint master_command_handler(int command_id, command_data* c_data, char* statement)\n```\n\nThe above function has a switch block that has various cases and it switches based on the command_id. The unique id will be used here to call specific subroutine:\n\n```C\ncase 1: // exit\n        return command_exit(c_data, statement);\n```\n\nHere the routine ```command_exit(c_data, statement); ``` is present in commands/standard_commands.h file. Therefore the programmer can define his command.h file, give a jump to the routine using the unique id.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharshsikhwal%2Fsshell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharshsikhwal%2Fsshell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharshsikhwal%2Fsshell/lists"}