{"id":13529432,"url":"https://github.com/alexst07/shell-plus-plus","last_synced_at":"2025-04-13T21:35:23.241Z","repository":{"id":46990755,"uuid":"67890747","full_name":"alexst07/shell-plus-plus","owner":"alexst07","description":"A friendly and modern functional object oriented language for shell script.","archived":false,"fork":false,"pushed_at":"2023-03-26T18:41:49.000Z","size":1844,"stargazers_count":160,"open_issues_count":5,"forks_count":10,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-27T11:51:18.430Z","etag":null,"topics":["command-line","glob","glob-pattern","language","programming-language","scripting-language","shell","shell-script","shellscript","terminal"],"latest_commit_sha":null,"homepage":"https://alexst07.github.io/shell-plus-plus/","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexst07.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}},"created_at":"2016-09-10T19:40:08.000Z","updated_at":"2025-03-16T15:07:00.000Z","dependencies_parsed_at":"2023-01-29T18:00:56.095Z","dependency_job_id":null,"html_url":"https://github.com/alexst07/shell-plus-plus","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexst07%2Fshell-plus-plus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexst07%2Fshell-plus-plus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexst07%2Fshell-plus-plus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexst07%2Fshell-plus-plus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexst07","download_url":"https://codeload.github.com/alexst07/shell-plus-plus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788302,"owners_count":21161721,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["command-line","glob","glob-pattern","language","programming-language","scripting-language","shell","shell-script","shellscript","terminal"],"created_at":"2024-08-01T07:00:36.242Z","updated_at":"2025-04-13T21:35:23.220Z","avatar_url":"https://github.com/alexst07.png","language":"C++","funding_links":[],"categories":["Shells","terminal","Packages","C++"],"sub_categories":["Shells"],"readme":"# Introduction\n\nShell++ is a programming language that aims bring features from modern languages,\nas facility to manipulate data structures, object oriented programming,\nfunctional programming and others, to shell script.\nhttps://alexst07.github.io/shell-plus-plus/\n\n# Features\n * easy to manipulate data structure, as in Python\n * lambda functions\n * classes\n * executes commands like in Bash\n * pipe, redirection to or from files, sub shell\n * dynamic typing\n * glob and recursive glob\n * closures\n * reference counter\n * operator overriding\n\n# Why another programming language?\nI wanted a language that runs shell commands like Bash, and manipulate data structure with the ease of Python, I searched, but I did not find any that met my requirements, so I decided to use my free time to create one.\n\nThis is still in development, but it has already made life easier for me in many day-to-day tasks, maybe this might be useful for someone else, so I shared it on github.\n\nHowever everything here can change without warning, because to date, the only purpose of it is MAKE MY LIFE EASIER AND ONLY THAT.\n\n# Examples\nFollows some examples just to get an idea of how the language works.\n\n## A powerful glob\nShell++ has a powerful glob, that allows you to perform laborious tasks in a few lines. For example, suppose you want to modify the extension of all `txt` files to `csv` recursively.\n\n```python\nfor p, [n] in G\"**/*.txt\" {\n  mv ${p} ${p.parent_path()/\"{n}.csv\"}\n}\n```\n\n## List comprehension\n```shell\nfiles = [f for f in $(ls) if path(f).size(\"M\") \u003e 50]\n```\nIn this example files will be an array with all files listed by ls command with size bigger than 50Mb.\n\n## Try-Catch\ntry catch helps you handle situations in an elegant way, for example, instead of giving a raw message to the user's face, you can treat the message that a command does not exist.\n\n```php\ntry {\n  git clone git@github.com:alexst07/shell-plus-plus.git\n} catch InvalidCmdException as ex {\n  print(\"git not installed [msg: {ex}]\")\n}\n```\n## Reading user input\n```python\nline = read()\nprint(line)\n```\n\nFunction `read` is used to read user input, until the enter key is pressed, and the next line print the user input.\n\n## Reading file line by line\n```python\nfor line in file(\"example.txt\") {\n  print(\"line: {line}\")\n}\n```\n\n## Reading file line by line in shell style\n```shell\nshell {\n  while let line = read() {\n    print(\"line: {line}\")\n  }\n} \u003c example.txt\n```\n\n## Hello World\n```shell\necho Hello World\nprint(\"Hello World\")\n```\nIn Shell++ you can use an other program as echo, or a native function print.\n\n## String operations\n### Length\n```python\nstr = \"example\"\nprint(\"length: {len(str)}\") # length: 7\n```\n\n\n### Upper case and lower case\n```php\nx = \"HELLO\"\necho ${x} # HELLO\necho ${x.lower()} # hello\necho ${x.upper()} # HELLO\n```\n\n### Substring\n```python\nstr = \"string test\"\nstr1 = str[2:] # ring test\"\nstr2 = str[:-2] # string te\nstr3 = str[2:4] # ri\n```\n\n### Replace\n```python\nfilename = \"Path of the bash is /bin/bash\"\nprint(\"After Replacement: {filename.replace('bash', 'sh')}\")\n# After Replacement: Path of the sh is /bin/sh\nprint(\"length: {len(str)}\")\n```\n\n### Pass variables to command\n```php\necho ${t} # Hello\necho ${t + \" World\"} # Concatenate string\n# ${} solve an expression and return the value to echo\n```\n\n## Command examples\n### Pipeline\n```shell\necho \"Test\" | cat # simple pipeline\nls src* | grep -e \"test\" # using glob\n\n# using variables content as command\ncip = \"ipconfig\"\ncgrep = [\"grep\", \"-e\", \"10\\..*\"]\n${cip} | ${cgrep} # pass an array to command\n```\n\n### Redirecting to and from file\n```shell\ncat \u003c filename.txt\ncat \u003c filename.txt | grep test\ncat \u003c filename.txt | grep test \u003e result.txt\n\n# using variables\nfilename = \"filename.txt\"\nresult = \"result.txt\"\ncat \u003c ${filename} | grep test \u003e ${result}\n```\n### Concatenate file\n\n```shell\necho line1 \u003e test.txt\necho lene2 \u003e\u003e test.txt\n```\ntest.txt has this content:\nline1\nlene2\n\n### Redirecting error output\n```shell\nprog_test 2\u003e /dev/null\n```\nAny output on stderr go to /dev/null.\n\n### Assign command to variable\n```php\np = $(prog_test -opt 1)\n\n# check result\nif p {\n  print(p)\n} else {\n  print(\"error: {p.err()}\")\n}\n```\nCheck the status result of the command prog_test, if prog_test\nexited normally with status 0, the result is true and the line\nprint(p) is executed, if not, the else is executed.\n\n### Iterating command result\n```php\nfor f in $(ls -a mypath) {\n  print(\"file: {f}\")\n}\n```\nPrint all lines generated by ls command.\n\n### Execute command from simple variabel\n```shell\nex = \"ls\"\n${ex} # execute ls commad\n```\n\n### Execute command from array variabel\n```shell\nscp = [\"sch\", \"-i\", \"path/file.pem\", \"user@addr:path\"]\n${scp} # execute command from iterator\n```\nIt is possible execute a command from an array, using this feature\nyou have much more flexibility to mount the command with its arguments\nusing arrays.\n\n### Glob and recursive glob\n```shell\nfile *.txt\n```\nGlob in this case works like in bash.\n\n```shell\nfor f in g\"**/*.txt\" {\n  file ${f}\n}\n```\niterate over all txt files recursively\n\n```shell\nfile **/*.txt\n```\nThis peace of code has the same output from above\n\n## Path\n### Check if a path or file exists\n```php\nif path(\"/home/me/file.txt\").exists() {\n  print (\"file exists\")\n}\n```\n\n### Smart path comparison\n```php\np1 = path(\"/home/../home/me/file.txt\")\np2 = path(\"/home/me/file.txt\")\n\nprint(p1 == p2) # true\n\np1 = p\"/home/me/file.txt\"\np2 = p\"/home/me/file2.txt\"\n\nprint(p1 == p2) # false\n```\nIn Shell++ you can compare relatives path, it means,\nusing path object you compare path not string.\n\n## Array\nIn Shell++ is easy create and access array, it works like in Python\n\n```python\narray1 = ['physics', 'chemistry', 1997, 2000];\narray2 = [1, 2, 3, 4, 5, 6, 7 ];\n\nprint(\"array1[0]: {array1[0]}\")\nprint(\"array2[1:5]: {array2[1:5]}\")\n```\nOutput:\n```\narray1[0]:  physics\narray2[1:5]:  [2, 3, 4, 5]\n```\n\n## Map\nMap is a hash map object, it works like dictionary in Python.\n\n```python\nm = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}\n\nprint(\"m['Name']: {m['Name']}\")\nprint(\"m['Age']: {m['Age']}\")\n```\nOutput:\n```\nm['Name']:  Zara\nm['Age']:  7\n```\n\n## Functions\nIn Shell++ function is not a command as in Bash, functions in Shell++ are similar with Python.\n```go\nfunc test(a, b = 5) {\n  m = {\"sum\": a+b, \"sub\":a-b}\n  return m\n}\n\nprint(test(6)[\"sum\"])\n```\nOutput:\n```\n11\n```\n\n### Lambda\nReturn a closure function\n```go\nfunc ftest(a) {\n  v = [\"echo\", \"ls\", a]\n\n  # closures\n  return func(x) {\n    return v.append(x)\n  }\n}\n```\n\nThe keyword lambda is valid too. This example convert all array elements to\nupper case string.\n```python\nvec = [\"apple\", \"orange\", \"grape\"]\nvec.map(lambda x: x.to_upper())\n```\n\n## Classes\n```php\n# Complex number\nclass Complex {\n  func __init__(r, i) {\n    this.r = r\n    this.i = i\n  }\n\n  func __add__(n) {\n    return Complex(n.r + this.r, n.i + this.i)\n  }\n\n  func __sub__(n) {\n    return Complex(n.r - this.r, n.i - this.i)\n  }\n\n  func __print__() {\n    return \"{string(this.r)} {string(this.i)}i\"\n  }\n}\n\nc1 = Complex(2, 3)\nc2 = Complex(1, 2)\nc = c1 + c2\n\nprint(c)\n```\nOutput:\n```\n3 + 5i\n```\n\n## Quick-sort\n\n```go\nfunc quicksort(A, lo, hi) {\n  if lo \u003c hi {\n    p = partition(A, lo, hi)\n    A = quicksort(A, lo, p - 1)\n    A = quicksort(A, p + 1, hi)\n  }\n\n  return A\n}\n\nfunc partition(A, lo, hi) {\n  pivot = A[hi]\n  i = lo\n  j = lo\n\n  for j in range(lo, hi) {\n    if A[j] \u003c= pivot {\n      A[i], A[j] = A[j], A[i]\n      i = i + 1\n    }\n  }\n\n  A[i], A[hi] = A[hi], A[i]\n  return i\n}\n\na = [1,4,6,4,10,11,22,100,3,3,9]\nprint(quicksort(a, 0, len(a) - 1))\n```\nOutput:\n```\n[1, 3, 3, 4, 4, 6, 9, 10, 11, 22, 100]\n```\n\n## Check if a command exists\nIf you need execute a no standard application, sometimes you need to check if the application is installed, with Shell it is a way.\n\n```php\nfunc exist_cmd(name) {\n  c = $(which ${name})\n\n  if string(c) == \"\" {\n    return false\n  }\n\n  return true\n}\n\nprint(\"Does cmd exist?\")\nprint(\"ls: {exist_cmd('ls')}\")\nprint(\"non-exist-cmd { exist_cmd('non-exist-cmd')}\")\n```\nthe command which inside $() have as result an cmd object, you can convert its result to string and handle it.\n# Building\n\n## Requirements:\n  * A compiler that supports C++ 14 (gcc or clang)\n  * Boost\n  * Readline\n  * CMake\n  * Linux\n\n## Compiling\n\n### Ubuntu\nFirst you need intall the requirements to build Shell++\n```\n# apt-get install -y build-essential\n# apt-get install -y libboost-all-dev libreadline6 libreadline6-dev git cmake\n```\n\nWith the requirements installed, make a clone of the repository\n```\n$ git clone git@github.com:alexst07/shell-plus-plus.git\n```\nAfter the clone, change to directory of the project\n```\n$ cd shell-plus-plus\n```\nTo compile the project, you need create a directory when the cmake files will\nbe generated, and so, build the project\n\n```\n$ mkdir build\n$ cd build\n$ cmake ..\n$ make\n```\nNow you can already use the Shell++, the binary is generated at shell/ directory.\nTo use Shell++ to execute a script, first, create an example script called my.shpp.\n\n```\necho my first script in shell++\n```\nIn the build path, call the binary to execute your script\n\n```\n$ ./shell/shpp my.shpp\n```\nYou should see the output:\n```\nmy first script in shell++\n```\nIf you saw this output your build is working, if you want install Shell++.\n\n```\n$ sudo make install\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexst07%2Fshell-plus-plus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexst07%2Fshell-plus-plus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexst07%2Fshell-plus-plus/lists"}