├── .github └── workflows │ └── go.yml ├── .gitignore ├── LICENSE ├── README.md ├── Taskfile.yml ├── go.mod ├── go.sum ├── install.ps1 ├── install.sh ├── release ├── artifacts │ └── .gitkeep └── description.md ├── samples ├── bash.yml ├── interpreter.yaml ├── node.yml └── script.sh ├── src ├── bashy │ ├── interpreters.go │ ├── main.go │ ├── model.go │ └── repo.go ├── logger │ └── logger.go ├── logs │ └── bashy.log ├── main.go └── utils │ ├── templates │ └── bin.tmpl │ └── utils.go └── test └── yaml.go /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a golang project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go 3 | 4 | name: Go 5 | 6 | on: 7 | push: 8 | branches: [ "master" ] 9 | 10 | 11 | jobs: 12 | 13 | build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v3 17 | - name: Bump version and push tag 18 | id: tag_version 19 | uses: mathieudutour/github-tag-action@v6.1 20 | with: 21 | github_token: ${{ secrets.GITHUB_TOKEN }} 22 | - name: 'Output Step' 23 | env: 24 | NEW_TAG: ${{ steps.tag_version.outputs.new_tag }} 25 | run: echo "new tag $NEW_TAG" 26 | - uses: ClementTsang/delete-tag-and-release@v0.3.1 27 | with: 28 | delete_release: false 29 | tag_name: latets 30 | env: 31 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | 33 | - uses: rickstaa/action-create-tag@v1 34 | with: 35 | tag: "latest" 36 | message: "Latest release" 37 | no_verify_tag: true 38 | force_push_tag: true 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | - name: Set up Go 42 | uses: actions/setup-go@v3 43 | with: 44 | go-version: 1.18 45 | - name: install task 46 | run: sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d 47 | shell: bash 48 | 49 | - name: Build for linux 50 | run: bin/task build-linux 51 | shell: bash 52 | - name: Build for windows 53 | run: bin/task build-windows 54 | shell: bash 55 | 56 | - name: Publish 57 | env: 58 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 59 | NEW_TAG: ${{ steps.tag_version.outputs.new_tag }} 60 | NAME: Release ${{ steps.tag_version.outputs.new_tag }} 61 | CHANGELOG: ${{ steps.tag_version.outputs.changelog }} 62 | shell: bash 63 | run: | 64 | TITLE='Latest' 65 | BODY=$(cat ./release/description.md) 66 | go install github.com/tcnksm/ghr 67 | ghr -n="$NAME" -b="$CHANGELOG" -replace -delete $NEW_TAG ./out/ 68 | ghr -n="$TITLE" -b="$BODY" -replace -delete latest ./out/ 69 | 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Binaries for programs and plugins 3 | *.exe 4 | *.exe~ 5 | *.dll 6 | *.so 7 | *.dylib 8 | 9 | # Test binary, built with `go test -c` 10 | *.test 11 | 12 | # Output of the go coverage tool, specifically when used with LiteIDE 13 | *.out 14 | 15 | # Dependency directories (remove the comment below to include it) 16 | # vendor/ 17 | 18 | /node_modules 19 | 20 | /.task 21 | /internal/assets/bundle.go 22 | /tmp 23 | __debug_bin 24 | *.wixobj 25 | *.wixpdb 26 | *.msi 27 | 28 | .build.env 29 | bin 30 | samples/home 31 | out 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bashy 2 | Bashy is a script collector for bash system. It allows to download and collect scripts, and facilitates argument parsing. 3 | 4 | # Why I should use Bashy for my script 5 | Bashy provides a easy way for resolving arguments and generating an useful Help. 6 | You can simply have variable filled with values entered by the user by default, and the help infos build automatically from the script definition. This transofrms your bash script in a real console application with no pain 7 | 8 | # How to install 9 | The installation package is available for windows and linux. It was tested on Window 10&11, Ubuntu, Debian and Alpine. If the binay is not compatible with your OS or processor, you can compile it from source (see next section). 10 | 11 | ## Instal on Linux 12 | 13 | Copy the next piece of code and run in your terminal. 14 | 15 | ```bash 16 | curl -LO https://github.com/zeppaman/bashy/releases/download/latest/bashy.linux && install -m 0755 ./bashy.linux /usr/bin/bashy && rm ./bashy.linux && echo 'export PATH="$PATH:$HOME/.bashy/bin"'>>~/.bashrc && echo 'export PATH="$PATH:$HOME/.bashy/bin"'>>~/.profile && echo 'export PATH="$PATH:$HOME/.bashy/bin"'>>/etc/environment && export PATH="$PATH:$HOME/.bashy/bin" 17 | ``` 18 | *note*: basing on your os you may need to be root to run the command. Requires curl installed. 19 | 20 | ## Install on windows 21 | Open a powershell console with elevated privileges and run: 22 | 23 | ```ps 24 | $bashyHome=$([Environment]::GetFolderPath("UserProfile"))+"\.bashy"; New-Item -ItemType Directory -Force -Path $bashyHome\bin; (New-Object System.Net.WebClient).DownloadFile('https://github.com/zeppaman/bashy/releases/download/latest/bashy.windows', "$bashyHome\bin\bashy.exe"); $old = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User); $env:Path= "$old;$bashyHome\bin"; [Environment]::SetEnvironmentVariable("Path", "$old;$bashyHome\bin", [System.EnvironmentVariableTarget]::User); 25 | ``` 26 | 27 | 28 | # Compiling from source 29 | 30 | # Linux or WSL 31 | ```bash 32 | git clone bashy 33 | cd bashy 34 | bash ./install.sh 35 | ``` 36 | The script build executables in out folder. Copy them where you want and make sure to add the binary location on PATH and the /bin subfloder of BASHY_HOME folder (default is .bashy inside you home/profile folder) 37 | 38 | installation notes: 39 | - this compile bashy form source, so you can delete the folder at the end 40 | - the tool download and install go if not present. If present, nothing is touched but it have to be updated manually to the 1.19 version. 41 | 42 | # Windows 43 | ``` 44 | git clone bashy 45 | Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; ./install.ps1 46 | #rm -rf bashy optional 47 | ``` 48 | Despite that golang can produce multiplatform output and that this app could be improved to support multiple script engines (js,c#, etc..) and OS (windows, mac), at the moment the application is working only with linux and bash scripts. 49 | 50 | # How is it possible? 51 | The script hash a YAML file associated with it, so you can define all the infos. In the following example we are defining a command named `sample` with two parameters (`name, surname`). 52 | 53 | ```yaml 54 | name: Name 55 | description: the command description 56 | argsusage: help text 57 | params: 58 | - name: "name" 59 | desc: "enter your name" 60 | - name: "surname" 61 | desc: "enter your surname" 62 | ``` 63 | This will allow you to use directly the parameter names as named variables. So, your script will be able to do something similar to: 64 | 65 | ```bash 66 | echo "$name" 67 | echo "$surname" 68 | echo "$name $surname" 69 | ``` 70 | Moreover, you will be able to list all the commands available, and for each commands the help usage. 71 | 72 | # How can I share my script 73 | Each yaml file can contains one or more command definition. Commands can be: 74 | - embedded (the script is contained inside the yaml file definition) 75 | - linked to an external files (local or remote) 76 | 77 | You can work on-the-fly scripts on the current directory or move them to the internal report and make them available at OS level. Moreover you can publish scripts over HTTP and download it locally. 78 | 79 | ## Download a script and add it locally 80 | ```bash 81 | bashy repo add https://xxx.yy/path.yml 82 | ``` 83 | This will download all related scripts and save them locally. The home of bashy is `.bashy` on the user's home. 84 | 85 | 86 | ## Run a script on current folder 87 | You can run scripts on a foder witout installing them on bashy by specifing the `BASHY_EXTRA` (additional folder where the app looks for yaml) and `BASHY_FILES (a list of files path to add). 88 | ```bash 89 | BASHY_EXTRA=samples/home go run ./src/main.go 90 | BASHY_FILES=myfile.yml,/var/scripts/myscript2.yml bashy 91 | ``` 92 | 93 | ## Add a script to bashy 94 | ```bash 95 | bashy repo add filepath.yml 96 | ``` 97 | 98 | # How to use it 99 | Here some commands for usage. 100 | ```bash 101 | bashy --help #list all commands with description 102 | 103 | # NAME: 104 | # Bashy - A new cli application 105 | 106 | # USAGE: 107 | # main [global options] command [command options] [arguments...] 108 | 109 | # COMMANDS: 110 | # command1 111 | # command2 112 | 113 | # GLOBAL OPTIONS: 114 | # --help, -h show help (default: false) 115 | 116 | bashy command1 --help # show infos about the command 117 | 118 | # NAME: 119 | # command1 120 | 121 | # USAGE: 122 | # bashy command1 [command options] [arguments...] 123 | 124 | # DESCRIPTION: 125 | # the command description 126 | 127 | # OPTIONS: 128 | # --name value enter your name 129 | # --surname value enter your surname 130 | # --help, -h show help (default: false) 131 | 132 | bashy parameters args # execute the command 133 | 134 | # the command output 135 | ``` 136 | 137 | # How to embed a script 138 | Some samples about how to embed a script. 139 | ## Single command 140 | You can write a command using 141 | ```yaml 142 | name: Name 143 | description: the command description 144 | argsusage: help text 145 | params: 146 | - name: "name" 147 | desc: "enter your name" 148 | - name: "surname" 149 | desc: "enter your surname" 150 | cmd: | 151 | echo "commmand" 152 | env 153 | echo "$name $surname" 154 | 155 | ``` 156 | or you can concatenate all commands in a single line if you want to keep things more hard to understand: 157 | ```yaml 158 | name: Name 159 | description: the command description 160 | argsusage: help text 161 | params: 162 | - name: "name" 163 | desc: "enter your name" 164 | - name: "surname" 165 | desc: "enter your surname" 166 | cmd: echo "commmand" && env echo "$name $surname" 167 | ``` 168 | 169 | ## Multiline script 170 | In case you want to define multiple command you can define it by adding multiple `cmds` nodes. Each one can cantain multiple statement like in the Singleline script case. Cmd and Cmds can coexists: Cmd is executed AFTER the Cmds list. 171 | ```yaml 172 | name: Name 173 | description: the command description 174 | argsusage: help text 175 | cmd: echo "commmand" && env 176 | params: 177 | - name: "name" 178 | desc: "enter your name" 179 | - name: "surname" 180 | desc: "enter your surname" 181 | cmds: 182 | - echo "$name" 183 | - echo "$surname" 184 | - echo "$name $surname" 185 | ``` 186 | 187 | # How include an external script 188 | An external script can be included. The external script is not exclusive: you can use it in conjunction with `cmd, cmds` arguments, but loaded at the end. You can specify a local path (relative or absolute), or an URL. The remote script will be downloaded at the first usage then cached locally. Examples: 189 | **Remote script** 190 | ```yaml 191 | script: https://gist.githubusercontent.com/zeppaman/bbdfbac1304f88df1b905692e42f4d4e/raw/22ab3a2163f6ea481bca1b5d5570a964120a4f89/test-bashy.sh 192 | ``` 193 | 194 | **Local relative path** 195 | The path is relative to the same location 196 | ```yaml 197 | script: ./test-bashy.sh 198 | ``` 199 | 200 | **Local absolute path** 201 | ```yaml 202 | script: /test-bashy.sh 203 | ``` 204 | Note: absolute paths are not changed during the import/execution process 205 | 206 | # Extend Bashy 207 | The engine of bashy support any kind of script interpreter but it is shipped with sh for Linux and cmd for windows. 208 | To add a new one just create a file like the following (this piece of code add the nodejs interpreter): 209 | ```yaml 210 | name: node 211 | params: 212 | - node 213 | - $filename 214 | os: linux 215 | installscript: 216 | - #!/bin/bash 217 | - echo "installing dependencies (node)" 218 | - '[[ "$(command -v apt)" ]] || { apt install nodejs -y; }' 219 | - exit 0 220 | variabletemplate: var $name="$value"; 221 | ``` 222 | Important fields are: 223 | **name** the name of the interpreter. Into script YAML you will set the interpreter parameter to match this. 224 | - **params** a list of parameters to run the script. The placeholder `$filename` will be replaced with the temporary path of the script that will be generated during the script run. The list in the example will be transformed into `node /`path/to/file` 225 | - **os** the name of the os where the interpreter can be interpreted. If you have an interpreter that can be used in two different OS, you have to duplicate it 226 | - **installscript** list of script steps for installing the interpreter. In the example above, it checks if apt is available, then installs node 227 | - **variabletemplate** the template for adding variables on top of the script, `$name`` and `$value` are placeholders that will hold the param name and value as defined in the command YAML. 228 | 229 | The installation of the interpreter can be done by using the `interpreter` command, like in the following example: 230 | 231 | ```bash 232 | bash interpreter add samples/interpreter.yml 233 | ``` 234 | 235 | you can check the list of the loaded interpreters by typing: 236 | Once the interpreter is installed, you can use it by adding the field `interpreter: 237 | 238 | ```yaml 239 | name: Name 240 | description: the command description 241 | argsusage: help text 242 | cmd: ... 243 | interpreter: node 244 | ``` 245 | 246 | ## Default interpreters 247 | 248 | Bashy ships a set of default interpreters based on the OS. The list is the following. 249 | 250 | | OS | Name | Default | 251 | | ------------- | ------------- | ------------- | 252 | | LINUX | sh | YES | 253 | | WINDOWS | cmd | YES | 254 | 255 | # Change default home 256 | 257 | ```bash 258 | BASHY_HOME=samples bashy 259 | ``` 260 | 261 | # Debug 262 | ```bash 263 | BASHY_HOME=tmp/home go run ./src/main.go 264 | BASHY_HOME=tmp/home BASHY_EXTRA=samples/home go run ./src/main.go 265 | ``` 266 | -------------------------------------------------------------------------------- /Taskfile.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | 3 | dotenv: [".build.env"] 4 | 5 | tasks: 6 | build-debug: 7 | desc: Build with debug symbols for the current platform. 8 | summary: | 9 | Build with debug symbols for the current platform. 10 | cmds: 11 | - go build -gcflags "all=-N -l" -o ./out/debug/bashy ./src 12 | 13 | generates: 14 | - ./out/debug/bashy 15 | 16 | 17 | build-linux: 18 | desc: Build for Linux. 19 | summary: | 20 | Build for Linux. 21 | cmds: 22 | - env GOOS=linux go build --ldflags '-extldflags "-static"' -o ./out/bashy.linux ./src 23 | generates: 24 | - out/bashy.linux 25 | build-windows: 26 | desc: Build for Linux. 27 | summary: | 28 | Build for Linux. 29 | cmds: 30 | - env GOOS=windows go build -o ./out/bashy.windows ./src 31 | 32 | generates: 33 | - out/bashy.windows 34 | 35 | clean: 36 | desc: Clean temp artifacts. 37 | summary: | 38 | Clean temp artifacts. 39 | srcs: 40 | - rm -rf out 41 | 42 | run: 43 | desc: Run app on current platform. 44 | summary: | 45 | Run the application 46 | cmds: 47 | - go run ./src/main.go 48 | 49 | test: 50 | desc: Run all tests. 51 | summary: | 52 | Run all tests. 53 | srcs: 54 | - go test ./... 55 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module bashy 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/urfave/cli/v2 v2.3.0 7 | gopkg.in/yaml.v2 v2.4.0 8 | ) 9 | 10 | require ( 11 | github.com/Songmu/retry v0.1.0 // indirect 12 | github.com/golang/protobuf v1.5.2 // indirect 13 | github.com/google/go-github v17.0.0+incompatible // indirect 14 | github.com/google/go-github/v47 v47.1.0 // indirect 15 | github.com/google/go-querystring v1.1.0 // indirect 16 | github.com/hashicorp/go-version v1.6.0 // indirect 17 | github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect 18 | github.com/pkg/errors v0.9.1 // indirect 19 | github.com/tcnksm/ghr v0.16.0 // indirect 20 | github.com/tcnksm/go-gitconfig v0.1.2 // indirect 21 | github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e // indirect 22 | golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7 // indirect 23 | golang.org/x/net v0.0.0-20220923203811-8be639271d50 // indirect 24 | golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 // indirect 25 | golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 // indirect 26 | google.golang.org/appengine v1.6.7 // indirect 27 | google.golang.org/protobuf v1.28.1 // indirect 28 | ) 29 | 30 | require ( 31 | github.com/aripalo/go-delightful v0.2.15 // indirect 32 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect 33 | github.com/enescakir/emoji v1.0.0 // indirect 34 | github.com/fatih/color v1.15.0 // indirect 35 | github.com/google/logger v1.1.1 // indirect 36 | github.com/gookit/color v1.5.0 // indirect 37 | github.com/ku/go-change-case v0.0.1 // indirect 38 | github.com/mattn/go-colorable v0.1.13 // indirect 39 | github.com/mattn/go-isatty v0.0.19 // indirect 40 | github.com/mattn/go-runewidth v0.0.14 // indirect 41 | github.com/mattn/go-tty v0.0.4 // indirect 42 | github.com/rivo/uniseg v0.2.0 // indirect 43 | github.com/rs/zerolog v1.31.0 // indirect 44 | github.com/russross/blackfriday/v2 v2.0.1 // indirect 45 | github.com/schollz/progressbar/v3 v3.13.1 46 | github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect 47 | github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect 48 | golang.org/x/sys v0.12.0 // indirect 49 | golang.org/x/term v0.6.0 // indirect 50 | ) 51 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/Songmu/retry v0.1.0 h1:hPA5xybQsksLR/ry/+t/7cFajPW+dqjmjhzZhioBILA= 3 | github.com/Songmu/retry v0.1.0/go.mod h1:7sXIW7eseB9fq0FUvigRcQMVLR9tuHI0Scok+rkpAuA= 4 | github.com/aripalo/go-delightful v0.2.15 h1:EDKp24prEG3bnBQQY9T2CbBKCW4RluXdwEsJeLYjzSo= 5 | github.com/aripalo/go-delightful v0.2.15/go.mod h1:f8Sb7bC5R9CkaVVNBJ3klOzGwWTQXgDlkv1JJmov8Pc= 6 | github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= 7 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= 8 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 9 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 10 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 11 | github.com/enescakir/emoji v1.0.0 h1:W+HsNql8swfCQFtioDGDHCHri8nudlK1n5p2rHCJoog= 12 | github.com/enescakir/emoji v1.0.0/go.mod h1:Bt1EKuLnKDTYpLALApstIkAjdDrS/8IAgTkKp+WKFD0= 13 | github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= 14 | github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= 15 | github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= 16 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 17 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 18 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 19 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 20 | github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 21 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 22 | github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY= 23 | github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ= 24 | github.com/google/go-github/v47 v47.1.0 h1:Cacm/WxQBOa9lF0FT0EMjZ2BWMetQ1TQfyurn4yF1z8= 25 | github.com/google/go-github/v47 v47.1.0/go.mod h1:VPZBXNbFSJGjyjFRUKo9vZGawTajnWzC/YjGw/oFKi0= 26 | github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= 27 | github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= 28 | github.com/google/logger v1.1.1 h1:+6Z2geNxc9G+4D4oDO9njjjn2d0wN5d7uOo0vOIW1NQ= 29 | github.com/google/logger v1.1.1/go.mod h1:BkeJZ+1FhQ+/d087r4dzojEg1u2ZX+ZqG1jTUrLM+zQ= 30 | github.com/gookit/color v1.5.0 h1:1Opow3+BWDwqor78DcJkJCIwnkviFi+rrOANki9BUFw= 31 | github.com/gookit/color v1.5.0/go.mod h1:43aQb+Zerm/BWh2GnrgOQm7ffz7tvQXEKV6BFMl7wAo= 32 | github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= 33 | github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= 34 | github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw= 35 | github.com/ku/go-change-case v0.0.1 h1:Dym6yulm/ma+XRgH1SG2CIOLk2biWpSFf6mMPtg3ic8= 36 | github.com/ku/go-change-case v0.0.1/go.mod h1:7rNOPNKPrCdjm8+iDIKgs87tZuyPJkhnStQZIOT3Pss= 37 | github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 38 | github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= 39 | github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 40 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 41 | github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84= 42 | github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 43 | github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= 44 | github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= 45 | github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= 46 | github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 47 | github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= 48 | github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= 49 | github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 50 | github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= 51 | github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 52 | github.com/mattn/go-tty v0.0.4 h1:NVikla9X8MN0SQAqCYzpGyXv0jY7MNl3HOWD2dkle7E= 53 | github.com/mattn/go-tty v0.0.4/go.mod h1:u5GGXBtZU6RQoKV8gY5W6UhMudbR5vXnUe7j3pxse28= 54 | github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= 55 | github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= 56 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 57 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 58 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 59 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 60 | github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= 61 | github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 62 | github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= 63 | github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= 64 | github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= 65 | github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= 66 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 67 | github.com/schollz/progressbar/v3 v3.13.1 h1:o8rySDYiQ59Mwzy2FELeHY5ZARXZTVJC7iHD6PEFUiE= 68 | github.com/schollz/progressbar/v3 v3.13.1/go.mod h1:xvrbki8kfT1fzWzBT/UZd9L6GA+jdL7HAgq2RFnO6fQ= 69 | github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= 70 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 71 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 72 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 73 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 74 | github.com/tcnksm/ghr v0.16.0 h1:ie93I9DT1Uqnz7VJedNUwonAAKMhUi7+MjbpjiENfyM= 75 | github.com/tcnksm/ghr v0.16.0/go.mod h1:UfHvFJ5YmWBSd5ZVdbYLeb0J+eoYD9CF8SdrD8cWrO8= 76 | github.com/tcnksm/go-gitconfig v0.1.2 h1:iiDhRitByXAEyjgBqsKi9QU4o2TNtv9kPP3RgPgXBPw= 77 | github.com/tcnksm/go-gitconfig v0.1.2/go.mod h1:/8EhP4H7oJZdIPyT+/UIsG87kTzrzM4UsLGSItWYCpE= 78 | github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e h1:IWllFTiDjjLIf2oeKxpIUmtiDV5sn71VgeQgg6vcE7k= 79 | github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e/go.mod h1:d7u6HkTYKSv5m6MCKkOQlHwaShTMl3HjqSGW3XtVhXM= 80 | github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= 81 | github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= 82 | github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= 83 | github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= 84 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 85 | golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7 h1:WJywXQVIb56P2kAvXeMGTIgQ1ZHQxR60+F9dLsodECc= 86 | golang.org/x/crypto v0.0.0-20220924013350-4ba4fb4dd9e7/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= 87 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 88 | golang.org/x/net v0.0.0-20220923203811-8be639271d50 h1:vKyz8L3zkd+xrMeIaBsQ/MNVPVFSffdaU3ZyYlBGFnI= 89 | golang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= 90 | golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1 h1:lxqLZaMad/dJHMFZH0NiNpiEZI/nhgWhe4wgzpE+MuA= 91 | golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= 92 | golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7 h1:ZrnxWX62AgTKOSagEqxvb3ffipvEDX2pl7E1TdqLqIc= 93 | golang.org/x/sync v0.0.0-20220923202941-7f9b1623fab7/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 94 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 95 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 96 | golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 97 | golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 98 | golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 99 | golang.org/x/sys v0.0.0-20210426230700-d19ff857e887 h1:dXfMednGJh/SUUFjTLsWJz3P+TQt9qnR11GgeI3vWKs= 100 | golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 101 | golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 102 | golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= 103 | golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 104 | golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= 105 | golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 106 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= 107 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 108 | golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= 109 | golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= 110 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 111 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 112 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 113 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 114 | google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= 115 | google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 116 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 117 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 118 | google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= 119 | google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 120 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 121 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 122 | gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 123 | gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 124 | gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= 125 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 126 | -------------------------------------------------------------------------------- /install.ps1: -------------------------------------------------------------------------------- 1 | 2 | if (Get-Command choco -errorAction SilentlyContinue) 3 | { 4 | Write-Host "choco installed, step skipped" 5 | } 6 | else { 7 | Write-Host "download choco" 8 | 9 | iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) 10 | } 11 | 12 | if (Get-Command go -errorAction SilentlyContinue) 13 | { 14 | Write-Host "golang installed, step skipped" 15 | } 16 | else { 17 | Write-Host "golang choco" 18 | 19 | choco install golang -y 20 | } 21 | 22 | 23 | if (Get-Command go -errorAction SilentlyContinue) 24 | { 25 | Write-Host "task installed, step skipped" 26 | } 27 | else { 28 | Write-Host "task choco" 29 | 30 | choco install go-task -y 31 | } 32 | 33 | 34 | task build-debug 35 | 36 | #userprrofile 37 | $bashyHome=$([Environment]::GetFolderPath("UserProfile"))+"\.bashy" 38 | Write-Host $bashyHome 39 | New-Item -ItemType Directory -Force -Path $bashyHome\bin | Select-Object "bashy home created" 40 | Copy-Item ./out/debug/bashy -Destination $bashyHome\bin\bashy.exe -Recurse 41 | 42 | 43 | 44 | $old = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) 45 | if ($old -like "*$bashyHome\bin*") { 46 | Write-Host "bashy home already in PATH" 47 | } 48 | else{ 49 | Write-Host "bashy home added to PATH" 50 | $new = "$old;$bashyHome\bin" 51 | [Environment]::SetEnvironmentVariable("Path", $new, [System.EnvironmentVariableTarget]::User) 52 | } 53 | 54 | 55 | $old = [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) 56 | if ($old -like "*$bashyHome\bashy.exe*") { 57 | Write-Host "bashy home already in PATH" 58 | } 59 | else{ 60 | Write-Host "bashy home added to PATH" 61 | $new = "$old;$bashyHome\bashy.exe" 62 | [Environment]::SetEnvironmentVariable("Path", $new, [System.EnvironmentVariableTarget]::User) 63 | } 64 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if ! [ -x "$(command -v go)" ]; then 4 | echo "installing go" 5 | wget -q -O - https://git.io/vQhTU | bash 6 | else 7 | echo "go ok" 8 | fi 9 | 10 | OS="$(uname -s)" 11 | ARCH="$(uname -m)" 12 | 13 | case $OS in 14 | "Linux") 15 | case $ARCH in 16 | "x86_64") 17 | ARCH=amd64 18 | ;; 19 | "aarch64") 20 | ARCH=arm64 21 | ;; 22 | "armv6" | "armv7l") 23 | ARCH=armv6l 24 | ;; 25 | "armv8") 26 | ARCH=arm64 27 | ;; 28 | .*386.*) 29 | ARCH=386 30 | ;; 31 | esac 32 | PLATFORM="linux-$ARCH" 33 | ;; 34 | "Darwin") 35 | PLATFORM="darwin-amd64" 36 | ;; 37 | esac 38 | 39 | if [ -z "$PLATFORM" ]; then 40 | echo "Your operating system is not supported by the script." 41 | exit 1 42 | fi 43 | 44 | if [ -n "$($SHELL -c 'echo $ZSH_VERSION')" ]; then 45 | shell_profile="$HOME/.zshrc" 46 | elif [ -n "$($SHELL -c 'echo $BASH_VERSION')" ]; then 47 | shell_profile="$HOME/.bashrc" 48 | elif [ -n "$($SHELL -c 'echo $FISH_VERSION')" ]; then 49 | shell="fish" 50 | if [ -d "$XDG_CONFIG_HOME" ]; then 51 | shell_profile="$XDG_CONFIG_HOME/fish/config.fish" 52 | else 53 | shell_profile="$HOME/.config/fish/config.fish" 54 | fi 55 | fi 56 | 57 | #reload env variables 58 | source $shell_profile 59 | 60 | if [ -f ./bin/task ]; then 61 | echo "task exists. install skipped" 62 | else 63 | echo "task does not exist. installing" 64 | sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d 65 | fi 66 | 67 | #compile the tool 68 | 69 | bin/task build-debug 70 | # cp ./out/debug/bashy /usr/bin/bashy 71 | # export PATH="$PATH:/root/.bashy/bin" 72 | # echo 'export PATH="$PATH:/root/.bashy/bin"' >>~/.profile 73 | 74 | #wget https://github.com/zeppaman/bashy/releases/download/v1.0.1/bashy 75 | 76 | #curl -LO https://github.com/zeppaman/bashy/releases/download/v1.0.1/bashy && install -m 0755 ./bashy /usr/bin/bashy && rm ./bashy && echo 'export PATH="$PATH:$HOME/.bashy/bin"'>>~/.bashrc && echo 'export PATH="$PATH:$HOME/.bashy/bin"'>>~/.profile && echo 'export PATH="$PATH:$HOME/.bashy/bin"'>>/etc/environment && export PATH="$PATH:$HOME/.bashy/bin" 77 | #sudo sh -c 'curl -LO https://github.com/zeppaman/bashy/releases/download/v1.0.1/bashy && install -m 0755 bashy /usr/bin/bashy && rm -rf bashy' -------------------------------------------------------------------------------- /release/artifacts/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeppaman/bashy/65667e0d49d9b6b04e8c28d0188fb7a2c7ac8f9c/release/artifacts/.gitkeep -------------------------------------------------------------------------------- /release/description.md: -------------------------------------------------------------------------------- 1 | This is the **Bashy** release. The binaries are burnt using following conventions: 2 | - bashy.OSNAME are general purpose binaries valid for most distribution 3 | - bashy.ARCH.OSNAME are binaries compiled for the couple Archiecture/OS (Es. Linux x86) 4 | 5 | There isn't any plan to relese distribution specific installer. Anyway, GOLANG is quite compatible with most OS and distribution, so Bashy can run quite everywhere as it use only pure GO constructs. 6 | 7 | If there isn't any option for you OS you can: 8 | 1. compile it by yourself following istruction in the project README 9 | 2. Enanche the build process to include your OS in the pipeline. To do this, just fork the repo, change the Taskfile.yaml and make a pullrequest 10 | 11 | -------------------------------------------------------------------------------- /samples/bash.yml: -------------------------------------------------------------------------------- 1 | name: Name 2 | description: the command description 3 | argsusage: help text 4 | cmd: echo "commmand" && env 5 | cmds: 6 | - echo "$name" 7 | - echo "$surname" 8 | - echo "$name $surname" 9 | params: 10 | - name: "name" 11 | desc: "enter your name" 12 | - name: "surname" 13 | desc: "enter your surname" 14 | --- 15 | name: SecondCommand 16 | description: the command description 17 | argsusage: help text 18 | script: ./script.sh 19 | params: 20 | - name: "name" 21 | desc: "enter your name" 22 | - name: "surname" 23 | desc: "enter your surname" 24 | --- 25 | name: RemoteCommand 26 | description: the command description 27 | argsusage: help text 28 | script: https://gist.githubusercontent.com/zeppaman/bbdfbac1304f88df1b905692e42f4d4e/raw/22ab3a2163f6ea481bca1b5d5570a964120a4f89/test-bashy.sh 29 | params: 30 | - name: "name" 31 | desc: "enter your name" 32 | - name: "surname" 33 | desc: "enter your surname" -------------------------------------------------------------------------------- /samples/interpreter.yaml: -------------------------------------------------------------------------------- 1 | name: bash 2 | params: 3 | - sh 4 | - -c 5 | - $filename 6 | os: linux 7 | installscript: 8 | - #!/bin/bash 9 | - echo "nothing to do" 10 | - exit 0 11 | variabletemplate: $name='$value' 12 | --- 13 | name: node 14 | params: 15 | - node 16 | - $filename 17 | os: linux 18 | installscript: 19 | - #!/bin/bash 20 | - echo "installing dependencies (node)" 21 | - '[[ "$(command -v apt)" ]] || { apt install nodejs -y; }' 22 | - exit 0 23 | variabletemplate: var $name="$value"; 24 | --- 25 | name: node2 26 | params: 27 | - node 28 | - -c 29 | - $filename 30 | os: windows 31 | installscript: 32 | - 33 | - echo "installing node (with choco, run in elevated mode)" 34 | variabletemplate: xxx -------------------------------------------------------------------------------- /samples/node.yml: -------------------------------------------------------------------------------- 1 | name: js 2 | description: the command description using nodejs 3 | argsusage: help text 4 | cmd: console.log("single command") 5 | cmds: 6 | - console.log("Name " + name) 7 | - console.log("Surname "+ surname) 8 | - console.log(name+" -"+surname) 9 | params: 10 | - name: "name" 11 | desc: "enter your name" 12 | - name: "surname" 13 | desc: "enter your surname" 14 | interpreter: node 15 | --- -------------------------------------------------------------------------------- /samples/script.sh: -------------------------------------------------------------------------------- 1 | echo "external script" 2 | echo "$name" 3 | echo "$surname" 4 | echo "$name $surname" -------------------------------------------------------------------------------- /src/bashy/interpreters.go: -------------------------------------------------------------------------------- 1 | package bashy 2 | 3 | import ( 4 | "bashy/src/logger" 5 | "bashy/src/utils" 6 | "errors" 7 | "fmt" 8 | "io" 9 | "io/ioutil" 10 | "os" 11 | "path/filepath" 12 | "strconv" 13 | "strings" 14 | 15 | "gopkg.in/yaml.v2" 16 | ) 17 | 18 | func (re *Bashy) removeInterpreter(name string) { 19 | deletePattern := filepath.Join(re.InterpreterFolder, name+".*") 20 | utils.RemoveAll(deletePattern) 21 | deletePattern = filepath.Join(re.InterpreterFolder, name+".*") 22 | utils.RemoveAll(deletePattern) 23 | 24 | } 25 | func (re *Bashy) addInterpreter(path string) { 26 | logger.BgreenPrintln("Add Interpreter " + path + " to " + re.InterpreterFolder) 27 | 28 | if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") { 29 | cacheScript := filepath.Join(re.Tmp, utils.GetMD5Hash(path)+".yml") 30 | utils.DownloadFile(cacheScript, path) 31 | path = cacheScript 32 | } 33 | 34 | interpretersRead := re.loadInterpretersFromFile(path) 35 | interpretersToAdd := []*Interpreter{} 36 | 37 | for _, interpreter := range interpretersRead { 38 | if interpreter.Os == utils.CurrentOS() { 39 | interpretersToAdd = append(interpretersToAdd, interpreter) 40 | logger.GreenPrintln("info", interpreter.Name+" available for "+interpreter.Os) 41 | } else { 42 | logger.GreenPrintln("info", "Skipped "+interpreter.Os+" of "+interpreter.Name) 43 | } 44 | } 45 | 46 | if logger.IsDebug() { 47 | logger.BLogInfo("interpretersToAdd: " + fmt.Sprintf("%v", interpretersToAdd)) 48 | } 49 | //remove interpreters with the same name for replacing and append 50 | tmp := []*Interpreter{} 51 | for _, interpreter := range re.Interpreters { 52 | hasInterpreter := false 53 | for _, element := range interpretersToAdd { 54 | hasInterpreter = hasInterpreter || element.Name == interpreter.Name 55 | } 56 | if !hasInterpreter { 57 | tmp = append(tmp, interpreter) 58 | } 59 | } 60 | re.Interpreters = tmp 61 | re.Interpreters = append(re.Interpreters, interpretersToAdd...) 62 | 63 | //execute installation scripts 64 | for _, interpreter := range interpretersToAdd { 65 | re.installInterpreter(*interpreter) 66 | } 67 | 68 | re.saveInterpreters() 69 | re.LoadInternalCommands() 70 | 71 | } 72 | func (re *Bashy) saveInterpreters() { 73 | deletePattern := filepath.Join(re.ScriptFolder, "*.yml") 74 | utils.RemoveAll(deletePattern) 75 | 76 | for index, interpreter := range re.Interpreters { 77 | path := filepath.Join(re.InterpreterFolder, interpreter.Name+"_"+strconv.Itoa(index)+".yml") 78 | utils.SerializeToFile(path, interpreter) 79 | } 80 | } 81 | func (re *Bashy) listInterpreters(name string) { 82 | logger.GreenPrintln("Loaded Interpreters form: " + re.InterpreterFolder) 83 | for _, Interpreter := range re.Interpreters { 84 | logger.BLogInfo(Interpreter.Name) 85 | } 86 | 87 | } 88 | func (re *Bashy) loadInterpreters() { 89 | files := re.getInterpretersFileNames() 90 | for _, file := range files { 91 | //fmt.Println("loading from " + file) 92 | interpreters := re.loadInterpretersFromFile(file) 93 | re.Interpreters = append(re.Interpreters, interpreters...) 94 | } 95 | } 96 | 97 | func (re *Bashy) getInterpretersFileNames() []string { 98 | result := []string{} 99 | 100 | files, err := ioutil.ReadDir(re.InterpreterFolder) 101 | if err != nil { 102 | logger.BLogError(err) 103 | } 104 | 105 | for _, file := range files { 106 | filename := file.Name() 107 | 108 | logger.GreenPrintln(filename) 109 | if filepath.Ext(filename) == ".yaml" || filepath.Ext(filename) == ".yml" { 110 | result = append(result, filepath.Join(re.InterpreterFolder, filename)) 111 | } 112 | } 113 | 114 | return result 115 | } 116 | 117 | func (re *Bashy) loadInterpretersFromFile(filename string) []*Interpreter { 118 | 119 | interpretersList := []*Interpreter{} 120 | 121 | f, err := os.Open(filename) 122 | if err != nil { 123 | panic(err) 124 | } 125 | d := yaml.NewDecoder(f) 126 | for { 127 | // create new spec here 128 | config := new(Interpreter) 129 | // pass a reference to spec reference 130 | err := d.Decode(&config) 131 | // check it was parsed 132 | if config == nil { 133 | continue 134 | } 135 | // break the loop in case of EOF 136 | if errors.Is(err, io.EOF) { 137 | break 138 | } 139 | if err != nil { 140 | panic(err) 141 | } 142 | 143 | interpretersList = append(interpretersList, config) 144 | } 145 | return interpretersList 146 | } 147 | 148 | func (re *Bashy) installInterpreter(interpreter Interpreter) { 149 | 150 | installInterpreter := re.GetInterpreterForCurrentOS(interpreter.Interpreter) 151 | logger.BgreenPrintln("Installing " + interpreter.Name + " using " + installInterpreter.Name) 152 | 153 | re.ExecCommand(installInterpreter, make(map[string]string), interpreter.Installscript) 154 | } 155 | 156 | func (re *Bashy) GetInterpreterForCurrentOS(name string) *Interpreter { 157 | for _, interpreter := range re.Interpreters { 158 | if interpreter.Name == name && interpreter.Os == utils.CurrentOS() { 159 | return interpreter 160 | } 161 | } 162 | //if not found try to execute with the default one, first available for OS used 163 | for _, interpreter := range re.GetDefaultInterpreters() { 164 | if interpreter.Os == utils.CurrentOS() { 165 | return interpreter 166 | } 167 | } 168 | return nil 169 | } 170 | 171 | func (re *Bashy) GetDefaultInterpreters() []*Interpreter { 172 | interpreters := []*Interpreter{} 173 | //TODO add config file in assets, then add dinamically 174 | if "windows" == utils.CurrentOS() { 175 | interpreters = append(interpreters, &Interpreter{ 176 | Name: "bat", 177 | Os: "windows", 178 | Params: []string{"cmd", "/c", "$filename"}, 179 | }) 180 | } else if "linux" == utils.CurrentOS() { 181 | 182 | interpreters = append(interpreters, &Interpreter{ 183 | Name: "sh", 184 | Os: "linux", 185 | Params: []string{"sh", "-c", "$filename"}, 186 | }) 187 | 188 | } 189 | return interpreters 190 | 191 | } 192 | -------------------------------------------------------------------------------- /src/bashy/main.go: -------------------------------------------------------------------------------- 1 | package bashy 2 | 3 | import ( 4 | "bashy/src/logger" 5 | "bashy/src/utils" 6 | "errors" 7 | "os" 8 | "os/exec" 9 | "os/user" 10 | "path/filepath" 11 | 12 | //"bufio" 13 | "strings" 14 | //"net/http" 15 | "fmt" 16 | "io" 17 | "io/fs" 18 | "io/ioutil" 19 | 20 | "github.com/urfave/cli/v2" 21 | "gopkg.in/yaml.v2" 22 | ) 23 | 24 | type Bashy struct { 25 | Home string 26 | app cli.App 27 | scripts []*Script 28 | Interpreters []*Interpreter 29 | ScriptFolder string 30 | CacheFolder string 31 | BinFolder string 32 | BinScriptTemplate string 33 | Tmp string 34 | Instance string 35 | InterpreterFolder string 36 | LogsFolder string 37 | } 38 | 39 | func (re *Bashy) Init() error { 40 | 41 | currentUser, _ := user.Current() 42 | re.Home = os.Getenv("BASHY_HOME") 43 | if re.Home == "" { 44 | re.Home = filepath.Join(currentUser.HomeDir, ".bashy") 45 | } 46 | 47 | re.Home, _ = filepath.Abs(re.Home) 48 | 49 | if !utils.DirectoryExists(re.Home) { 50 | logger.BgreenPrintln("creating missing folder" + re.Home) 51 | err := os.MkdirAll(re.Home, os.ModePerm) 52 | if err != nil { 53 | logger.BLogFatal(err) 54 | } 55 | } 56 | logger.BLogInfo("Bashy started") 57 | re.Instance = utils.GenerateToken(5) 58 | re.ScriptFolder = filepath.Join(re.Home, "scripts") 59 | re.CacheFolder = filepath.Join(re.Home, "cache") 60 | re.BinFolder = filepath.Join(re.Home, "bin") 61 | re.Tmp = filepath.Join(re.Home, "tmp", re.Instance) 62 | re.InterpreterFolder = filepath.Join(re.Home, "interpreters") 63 | re.LogsFolder = filepath.Join(re.Home, "logs") 64 | err := os.MkdirAll(re.ScriptFolder, os.ModePerm) 65 | if err != nil { 66 | logger.BLogFatal(err) 67 | } 68 | err = os.MkdirAll(re.CacheFolder, os.ModePerm) 69 | if err != nil { 70 | logger.BLogFatal(err) 71 | } 72 | 73 | err = os.MkdirAll(re.BinFolder, os.ModePerm) 74 | if err != nil { 75 | logger.BLogFatal(err) 76 | } 77 | 78 | err = os.MkdirAll(re.Tmp, os.ModePerm) 79 | if err != nil { 80 | logger.BLogFatal(err) 81 | } 82 | 83 | err = os.MkdirAll(re.InterpreterFolder, os.ModePerm) 84 | if err != nil { 85 | logger.BLogFatal(err) 86 | } 87 | err = os.MkdirAll(re.LogsFolder, os.ModePerm) 88 | if err != nil { 89 | logger.BLogFatal(err) 90 | } 91 | 92 | cmds := re.loadCommands(re.ScriptFolder) 93 | cmds = append(cmds, re.LoadInternalCommands()...) 94 | if len(cmds) == 0 { 95 | return errors.New("no commands found") 96 | } 97 | 98 | re.loadInterpreters() 99 | re.app = cli.App{ 100 | Name: "Bashy", 101 | Commands: cmds, 102 | Description: "hello! script loaded from " + re.Home, 103 | } 104 | re.app.Commands = cmds 105 | return nil 106 | } 107 | 108 | func (re *Bashy) ExecCommand(interpreter *Interpreter, params map[string]string, lines []string) { 109 | filename := utils.TempFileName(re.Tmp, ".sh") 110 | linesToWrite := []string{} 111 | for name, value := range params { 112 | //fmt.Println("variable add" + interpreter.Variabletemplate) 113 | line := strings.ReplaceAll(interpreter.Variabletemplate, "$name", name) 114 | line = strings.ReplaceAll(line, "$value", value) 115 | linesToWrite = append(linesToWrite, line) 116 | } 117 | linesToWrite = append(linesToWrite, lines...) 118 | 119 | utils.WriteLinesToFile(filename, linesToWrite, 0777) 120 | //fmt.Printf("use " + interpreter.Name + " with file" + filename) 121 | 122 | commandArgs := []string{} 123 | for i, arg := range interpreter.Params { 124 | if i > 0 { 125 | arg = strings.ReplaceAll(arg, "$filename", filename) 126 | //fmt.Printf("arg:" + arg) 127 | if logger.IsDebug() { 128 | logger.BLogInfo("arg: " + arg) 129 | } 130 | commandArgs = append(commandArgs, arg) 131 | } 132 | } 133 | cmd := exec.Command(interpreter.Params[0], commandArgs...) 134 | cmd.Env = os.Environ() 135 | 136 | // for _, arg := range args { 137 | // cmd.Env = append(cmd.Env, arg) 138 | // } 139 | 140 | stdoutStderr, err := cmd.CombinedOutput() 141 | if err != nil { 142 | logger.BLogFatal(err) 143 | } 144 | fmt.Printf("%s\n", stdoutStderr) 145 | } 146 | 147 | func (re *Bashy) scriptFiles(scriptPath string) []fs.FileInfo { 148 | result := []fs.FileInfo{} 149 | 150 | files, err := ioutil.ReadDir(scriptPath) 151 | if err != nil { 152 | //fmt.Println(err) 153 | logger.BLogError(err) 154 | } 155 | manualfiles := os.Getenv("BASHY_FILES") 156 | if len(manualfiles) > 0 { 157 | for _, filestr := range strings.Split(manualfiles, ",") { 158 | file, _ := os.Stat(filestr) 159 | files = append(files, file) 160 | } 161 | } 162 | 163 | extrahome := os.Getenv("BASHY_EXTRA") 164 | if len(manualfiles) > 0 { 165 | files, err = ioutil.ReadDir(extrahome) 166 | //append script on main directory 167 | for _, file := range files { 168 | filename := file.Name() 169 | if filepath.Ext(filename) == ".yaml" || filepath.Ext(filename) == ".yml" { 170 | result = append(result, file) 171 | } 172 | } 173 | } 174 | 175 | for _, file := range files { 176 | filename := file.Name() 177 | if filepath.Ext(filename) == ".yaml" || filepath.Ext(filename) == ".yml" { 178 | result = append(result, file) 179 | } 180 | } 181 | 182 | //append script on main directory 183 | for _, file := range files { 184 | filename := file.Name() 185 | if filepath.Ext(filename) == ".yaml" || filepath.Ext(filename) == ".yml" { 186 | result = append(result, file) 187 | } 188 | } 189 | 190 | return result 191 | } 192 | 193 | func (re *Bashy) loadConfigs(scriptPath string) []*Script { 194 | files := re.scriptFiles(scriptPath) 195 | /* loop over command folder */ 196 | configList := []*Script{} 197 | for _, file := range files { 198 | filename, _ := filepath.Abs(filepath.Join(scriptPath, file.Name())) 199 | if filepath.Ext(filename) == ".yaml" || filepath.Ext(filename) == ".yml" { 200 | configList = append(configList, re.loadConfigFromFiles(filename)...) 201 | } 202 | } 203 | return configList 204 | } 205 | 206 | func (re *Bashy) loadConfigFromFiles(filename string) []*Script { 207 | 208 | //TODO: Works only with --- ending. Fix it 209 | configList := []*Script{} 210 | 211 | f, err := os.Open(filename) 212 | if err != nil { 213 | panic(err) 214 | } 215 | d := yaml.NewDecoder(f) 216 | for { 217 | // create new spec here 218 | config := new(Script) 219 | // pass a reference to spec reference 220 | err := d.Decode(&config) 221 | // check it was parsed 222 | if config == nil { 223 | continue 224 | } 225 | // break the loop in case of EOF 226 | if errors.Is(err, io.EOF) { 227 | break 228 | } 229 | if err != nil { 230 | logger.BLogFatal(err) 231 | panic(err) 232 | } 233 | 234 | configList = append(configList, config) 235 | } 236 | return configList 237 | } 238 | 239 | func (re *Bashy) convertToCommands(configs []*Script) []*cli.Command { 240 | result := []*cli.Command{} 241 | for _, config := range configs { 242 | /* convert config to commands*/ 243 | command := new(cli.Command) 244 | command.Name = config.Name 245 | command.ArgsUsage = config.ArgUsage 246 | command.Description = config.Description 247 | 248 | command.Action = func(c *cli.Context) error { 249 | 250 | lines := []string{} 251 | lines = append(lines, config.Cmds...) 252 | lines = append(lines, config.Cmd) 253 | if config.Script != "" { 254 | script := utils.ReadFileLines(config.Script) 255 | lines = append(lines, script...) 256 | } 257 | //fmt.Println("Prepare flags ") 258 | params := make(map[string]string) 259 | names := c.FlagNames() 260 | for _, flag := range config.Params { 261 | logger.BcyanPrintln(" - "+flag.Name, "bcyan") 262 | if utils.Contains(names, flag.Name) { 263 | params[flag.Name] = c.String(flag.Name) 264 | } else { 265 | params[flag.Name] = flag.Default 266 | } 267 | } 268 | installInterpreter := re.GetInterpreterForCurrentOS(config.Interpreter) 269 | 270 | re.ExecCommand(installInterpreter, params, lines) 271 | return nil 272 | } 273 | 274 | for _, element := range config.Params { 275 | param := new(cli.StringFlag) 276 | param.Name = element.Name 277 | param.Value = element.Default 278 | param.Usage = element.Desc 279 | param.Required = element.Required 280 | 281 | command.Flags = append(command.Flags, param) 282 | 283 | } 284 | result = append(result, command) 285 | } 286 | return result 287 | } 288 | 289 | func (re *Bashy) loadCommands(home string) []*cli.Command { 290 | configs := re.loadConfigs(home) 291 | commands := re.convertToCommands(configs) 292 | return commands 293 | } 294 | 295 | func (re *Bashy) Run(args []string) { 296 | err := re.app.Run(args) 297 | if err != nil { 298 | logger.BLogFatal(err) 299 | } 300 | } 301 | 302 | func (re *Bashy) Destroy() { 303 | os.RemoveAll(re.Tmp) 304 | os.Remove(re.Tmp) 305 | } 306 | 307 | func (re *Bashy) LoadInternalCommands() []*cli.Command { 308 | return []*cli.Command{ 309 | { 310 | Name: "dumpsettings", 311 | Aliases: []string{"d"}, 312 | Usage: "dump settings for debug", 313 | Action: func(c *cli.Context) error { 314 | re.dumpSettings() 315 | return nil 316 | }, 317 | }, 318 | { 319 | Name: "clearcache", 320 | Aliases: []string{"rmc"}, 321 | Usage: "Clear all cache", 322 | Action: func(c *cli.Context) error { 323 | re.clearcache() 324 | return nil 325 | }, 326 | }, 327 | { 328 | Name: "repo", 329 | Aliases: []string{"r"}, 330 | Usage: "manage local scripts", 331 | 332 | Subcommands: []*cli.Command{ 333 | { 334 | Name: "add", 335 | Usage: "add a new template", 336 | Action: func(c *cli.Context) error { 337 | re.addScript(c.Args().Get(0)) 338 | return nil 339 | }, 340 | }, 341 | { 342 | Name: "remove", 343 | Usage: "remove an existing template", 344 | Action: func(c *cli.Context) error { 345 | re.removeScript(c.Args().Get(0)) 346 | return nil 347 | }, 348 | }, 349 | { 350 | Name: "list", 351 | Usage: "list installed scripts", 352 | Action: func(c *cli.Context) error { 353 | re.listScript(c.Args().Get(0)) 354 | return nil 355 | }, 356 | }, 357 | }, 358 | }, 359 | { 360 | Name: "interpreter", 361 | Aliases: []string{"i"}, 362 | Usage: "manage local interpreters", 363 | 364 | Subcommands: []*cli.Command{ 365 | { 366 | Name: "add", 367 | Usage: "add a new interpreter", 368 | Action: func(c *cli.Context) error { 369 | re.addInterpreter(c.Args().Get(0)) 370 | return nil 371 | }, 372 | }, 373 | { 374 | Name: "remove", 375 | Usage: "remove an existing interpreter", 376 | Action: func(c *cli.Context) error { 377 | re.removeInterpreter(c.Args().Get(0)) 378 | return nil 379 | }, 380 | }, 381 | { 382 | Name: "list", 383 | Usage: "list installed interpreter", 384 | Action: func(c *cli.Context) error { 385 | re.listInterpreters(c.Args().Get(0)) 386 | return nil 387 | }, 388 | }, 389 | }, 390 | }, 391 | } 392 | } 393 | -------------------------------------------------------------------------------- /src/bashy/model.go: -------------------------------------------------------------------------------- 1 | package bashy 2 | 3 | type Parameter struct { 4 | Name string 5 | Desc string 6 | Type string 7 | Default string 8 | Required bool 9 | } 10 | 11 | type Script struct { 12 | Cmds []string // map[string][]string 13 | Cmd string 14 | Name string 15 | ArgUsage string 16 | Params []Parameter 17 | Description string 18 | Script string 19 | Interpreter string 20 | } 21 | 22 | type Interpreter struct { 23 | Name string 24 | Params []string 25 | Installscript []string 26 | Os string 27 | Interpreter string 28 | Variabletemplate string 29 | } 30 | -------------------------------------------------------------------------------- /src/bashy/repo.go: -------------------------------------------------------------------------------- 1 | package bashy 2 | 3 | import ( 4 | "bashy/src/logger" 5 | "bashy/src/utils" 6 | "io/ioutil" 7 | "path/filepath" 8 | "strings" 9 | ) 10 | 11 | func (re *Bashy) removeScript(name string) { 12 | deletePattern := filepath.Join(re.ScriptFolder, name+".*") 13 | utils.RemoveAll(deletePattern) 14 | deletePattern = filepath.Join(re.CacheFolder, name+".*") 15 | utils.RemoveAll(deletePattern) 16 | 17 | } 18 | func (re *Bashy) addScript(name string) { 19 | logger.BmagentaPrintln("Adding " + name) 20 | source := name 21 | cacheScript := filepath.Join(re.Tmp, utils.GetMD5Hash(name)+".yml") 22 | 23 | if strings.HasPrefix(name, "http://") || strings.HasPrefix(name, "https://") { 24 | utils.DownloadFile(cacheScript, name) 25 | source = cacheScript 26 | logger.BmagentaPrintln(source) 27 | } 28 | 29 | scripts := re.loadConfigFromFiles(source) 30 | for _, script := range scripts { 31 | logger.BmagentaPrintln(" - " + name) 32 | scriptName := filepath.Join(re.ScriptFolder, script.Name+".yml") 33 | binName := filepath.Join(re.BinFolder, script.Name) 34 | bin := utils.Transform("bin", script) 35 | ioutil.WriteFile(binName, []byte(bin), 0777) 36 | 37 | logger.ImagentaPrintln(scriptName, "imagenta") 38 | if !utils.Exists(scriptName) { 39 | if len(script.Script) == 0 { 40 | logger.GreenPrintln("Embedded script, nothing to include") 41 | } else if strings.HasPrefix(script.Script, "/") { 42 | //absolute local path, keep unchanged 43 | logger.GreenPrintln("Absoulte path used") 44 | } else if strings.HasPrefix(script.Script, "http://") || strings.HasPrefix(script.Script, "https://") { 45 | logger.GreenPrintln("Downloading and caching external script") 46 | //download it and chache 47 | cacheScript := filepath.Join(re.Home, "cache", script.Name+".sh") 48 | utils.Copy(script.Script, cacheScript) 49 | script.Script = cacheScript 50 | 51 | } else { 52 | logger.GreenPrintln("Moving relative path file to the cache") 53 | cacheScript := filepath.Join(re.Home, "cache", script.Name+".sh") 54 | utils.Copy(script.Script, cacheScript) 55 | script.Script = cacheScript 56 | } 57 | 58 | utils.SerializeToFile(scriptName, &script) 59 | 60 | } 61 | } 62 | 63 | } 64 | 65 | func (re *Bashy) listScript(name string) { 66 | logger.ImagentaPrintln("Loaded scripts form: " + re.ScriptFolder) 67 | for _, script := range re.scriptFiles(re.ScriptFolder) { 68 | logger.ImagentaPrintln(strings.Replace(script.Name(), filepath.Ext(script.Name()), "", 1) + " " + script.ModTime().Local().String()) 69 | } 70 | 71 | } 72 | 73 | func (re *Bashy) dumpSettings() { 74 | logger.BgreenPrintln("Dump Settings: ") 75 | logger.IcyanPrintln("BinFolder: " + re.BinFolder) 76 | logger.IcyanPrintln("BinScriptTemplate: " + re.BinScriptTemplate) 77 | logger.IcyanPrintln("CacheFolder: " + re.CacheFolder) 78 | logger.IcyanPrintln("Home: " + re.Home) 79 | logger.IcyanPrintln("Instance: " + re.Instance) 80 | logger.IcyanPrintln("ScriptFolder: " + re.ScriptFolder) 81 | logger.IcyanPrintln("Tmp: " + re.Tmp) 82 | } 83 | 84 | func (re *Bashy) clearcache() { 85 | utils.RemoveAll(re.CacheFolder) 86 | } 87 | -------------------------------------------------------------------------------- /src/logger/logger.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "os" 7 | "os/user" 8 | "strings" 9 | 10 | "github.com/fatih/color" 11 | "github.com/google/logger" 12 | ) 13 | 14 | var ColorFuncMap = map[string]*color.Color{ 15 | "red": color.New(color.FgRed), 16 | "green": color.New(color.FgGreen), 17 | "yellow": color.New(color.FgYellow), 18 | "blue": color.New(color.FgBlue), 19 | "magenta": color.New(color.FgMagenta), 20 | "cyan": color.New(color.FgCyan), 21 | "white": color.New(color.FgWhite), 22 | 23 | "bred": color.New(color.FgRed, color.Bold), 24 | "bgreen": color.New(color.FgGreen, color.Bold), 25 | "byellow": color.New(color.FgYellow, color.Bold), 26 | "bblue": color.New(color.FgBlue, color.Bold), 27 | "bmagenta": color.New(color.FgMagenta, color.Bold), 28 | "bcyan": color.New(color.FgCyan, color.Bold), 29 | "bwhite": color.New(color.FgWhite, color.Bold), 30 | 31 | "ured": color.New(color.FgRed, color.Underline), 32 | "ugreen": color.New(color.FgGreen, color.Underline), 33 | "uyellow": color.New(color.FgYellow, color.Underline), 34 | "ublue": color.New(color.FgBlue, color.Underline), 35 | "umagenta": color.New(color.FgMagenta, color.Underline), 36 | "ucyan": color.New(color.FgCyan, color.Underline), 37 | "uwhite": color.New(color.FgWhite, color.Underline), 38 | 39 | "bured": color.New(color.FgRed, color.Bold, color.Underline), 40 | "bugreen": color.New(color.FgGreen, color.Bold, color.Underline), 41 | "buyellow": color.New(color.FgYellow, color.Bold, color.Underline), 42 | "bublue": color.New(color.FgBlue, color.Bold, color.Underline), 43 | "bumagenta": color.New(color.FgMagenta, color.Bold, color.Underline), 44 | "bucyan": color.New(color.FgCyan, color.Bold, color.Underline), 45 | "buwhite": color.New(color.FgWhite, color.Bold, color.Underline), 46 | 47 | "ired": color.New(color.FgRed, color.Italic), 48 | "igreen": color.New(color.FgGreen, color.Italic), 49 | "iyellow": color.New(color.FgYellow, color.Italic), 50 | "iblue": color.New(color.FgBlue, color.Italic), 51 | "imagenta": color.New(color.FgMagenta, color.Italic), 52 | "icyan": color.New(color.FgCyan, color.Italic), 53 | "iwhite": color.New(color.FgWhite, color.Italic), 54 | 55 | "bired": color.New(color.FgRed, color.Bold, color.Italic), 56 | "bigreen": color.New(color.FgGreen, color.Bold, color.Italic), 57 | "biyellow": color.New(color.FgYellow, color.Bold, color.Italic), 58 | "biblue": color.New(color.FgBlue, color.Bold, color.Italic), 59 | "bimagenta": color.New(color.FgMagenta, color.Bold, color.Italic), 60 | "bicyan": color.New(color.FgCyan, color.Bold, color.Italic), 61 | "biwhite": color.New(color.FgWhite, color.Bold, color.Italic), 62 | 63 | "ibured": color.New(color.FgRed, color.Italic, color.Underline, color.Bold), 64 | "ibugreen": color.New(color.FgGreen, color.Italic, color.Underline, color.Bold), 65 | "ibuyellow": color.New(color.FgYellow, color.Italic, color.Underline, color.Bold), 66 | "ibublue": color.New(color.FgBlue, color.Italic, color.Underline, color.Bold), 67 | "ibumagenta": color.New(color.FgMagenta, color.Italic, color.Underline, color.Bold), 68 | "ibucyan": color.New(color.FgCyan, color.Italic, color.Underline, color.Bold), 69 | "ibuwhite": color.New(color.FgWhite, color.Italic, color.Underline, color.Bold), 70 | } 71 | 72 | var ( 73 | RedSprint = CreateColoredSprint("red") 74 | YellowSprint = CreateColoredSprint("yellow") 75 | GreenSprint = CreateColoredSprint("green") 76 | BlueSprint = CreateColoredSprint("blue") 77 | MagentaSprint = CreateColoredSprint("magenta") 78 | CyanSprint = CreateColoredSprint("cyan") 79 | WhiteSprint = CreateColoredSprint("white") 80 | 81 | RedPrintln = CreateColoredPrintln("red") 82 | YellowPrintln = CreateColoredPrintln("yellow") 83 | GreenPrintln = CreateColoredPrintln("green") 84 | BluePrintln = CreateColoredPrintln("blue") 85 | MagentaPrintln = CreateColoredPrintln("magenta") 86 | CyanPrintln = CreateColoredPrintln("cyan") 87 | WhitePrintln = CreateColoredPrintln("white") 88 | 89 | BredSprint = CreateColoredSprint("bred") 90 | ByellowSprint = CreateColoredSprint("byellow") 91 | BgreenSprint = CreateColoredSprint("bgreen") 92 | BblueSprint = CreateColoredSprint("bblue") 93 | BmagentaSprint = CreateColoredSprint("bmagenta") 94 | BcyanSprint = CreateColoredSprint("bcyan") 95 | BwhiteSprint = CreateColoredSprint("bwhite") 96 | 97 | BredPrintln = CreateColoredPrintln("bred") 98 | ByellowPrintln = CreateColoredPrintln("byellow") 99 | BgreenPrintln = CreateColoredPrintln("bgreen") 100 | BbluePrintln = CreateColoredPrintln("bblue") 101 | BmagentaPrintln = CreateColoredPrintln("bmagenta") 102 | BcyanPrintln = CreateColoredPrintln("bcyan") 103 | BwhitePrintln = CreateColoredPrintln("bwhite") 104 | 105 | UredSprint = CreateColoredSprint("ured") 106 | UyellowSprint = CreateColoredSprint("uyellow") 107 | UgreenSprint = CreateColoredSprint("ugreen") 108 | UblueSprint = CreateColoredSprint("ublue") 109 | UmagentaSprint = CreateColoredSprint("umagenta") 110 | UcyanSprint = CreateColoredSprint("ucyan") 111 | UwhiteSprint = CreateColoredSprint("uwhite") 112 | 113 | UredPrintln = CreateColoredPrintln("ured") 114 | UyellowPrintln = CreateColoredPrintln("uyellow") 115 | UgreenPrintln = CreateColoredPrintln("ugreen") 116 | UbluePrintln = CreateColoredPrintln("ublue") 117 | UmagentaPrintln = CreateColoredPrintln("umagenta") 118 | UcyanPrintln = CreateColoredPrintln("ucyan") 119 | UwhitePrintln = CreateColoredPrintln("uwhite") 120 | 121 | BuredSprint = CreateColoredSprint("bured") 122 | BuyellowSprint = CreateColoredSprint("buyellow") 123 | BugreenSprint = CreateColoredSprint("bugreen") 124 | BublueSprint = CreateColoredSprint("bublue") 125 | BumagentaSprint = CreateColoredSprint("bumagenta") 126 | BucyanSprint = CreateColoredSprint("bucyan") 127 | BuwhiteSprint = CreateColoredSprint("buwhite") 128 | 129 | BuredPrintln = CreateColoredPrintln("bured") 130 | BuyellowPrintln = CreateColoredPrintln("buyellow") 131 | BugreenPrintln = CreateColoredPrintln("bugreen") 132 | BubluePrintln = CreateColoredPrintln("bublue") 133 | BumagentaPrintln = CreateColoredPrintln("bumagenta") 134 | BucyanPrintln = CreateColoredPrintln("bucyan") 135 | BuwhitePrintln = CreateColoredPrintln("buwhite") 136 | 137 | IredSprint = CreateColoredSprint("ired") 138 | IyellowSprint = CreateColoredSprint("iyellow") 139 | IgreenSprint = CreateColoredSprint("igreen") 140 | IblueSprint = CreateColoredSprint("iblue") 141 | ImagentaSprint = CreateColoredSprint("imagenta") 142 | IcyanSprint = CreateColoredSprint("icyan") 143 | IwhiteSprint = CreateColoredSprint("iwhite") 144 | 145 | IredPrintln = CreateColoredPrintln("ired") 146 | IyellowPrintln = CreateColoredPrintln("iyellow") 147 | IgreenPrintln = CreateColoredPrintln("igreen") 148 | IbluePrintln = CreateColoredPrintln("iblue") 149 | ImagentaPrintln = CreateColoredPrintln("imagenta") 150 | IcyanPrintln = CreateColoredPrintln("icyan") 151 | IwhitePrintln = CreateColoredPrintln("iwhite") 152 | 153 | BiredSprint = CreateColoredSprint("bired") 154 | BiyellowSprint = CreateColoredSprint("biyellow") 155 | BigreenSprint = CreateColoredSprint("bigreen") 156 | BiblueSprint = CreateColoredSprint("biblue") 157 | BimagentaSprint = CreateColoredSprint("bimagenta") 158 | BicyanSprint = CreateColoredSprint("bicyan") 159 | BiwhiteSprint = CreateColoredSprint("biwhite") 160 | 161 | BiredPrintln = CreateColoredPrintln("bired") 162 | BiyellowPrintln = CreateColoredPrintln("biyellow") 163 | BigreenPrintln = CreateColoredPrintln("bigreen") 164 | BibluePrintln = CreateColoredPrintln("biblue") 165 | BimagentaPrintln = CreateColoredPrintln("bimagenta") 166 | BicyanPrintln = CreateColoredPrintln("bicyan") 167 | BiwhitePrintln = CreateColoredPrintln("biwhite") 168 | 169 | IburedSprint = CreateColoredSprint("ibured") 170 | IbuyellowSprint = CreateColoredSprint("ibuyellow") 171 | IbugreenSprint = CreateColoredSprint("ibugreen") 172 | IbublueSprint = CreateColoredSprint("ibublue") 173 | IbumagentaSprint = CreateColoredSprint("ibumagenta") 174 | IbucyanSprint = CreateColoredSprint("ibucyan") 175 | IbuwhiteSprint = CreateColoredSprint("ibuwhite") 176 | 177 | IburedPrintln = CreateColoredPrintln("ibured") 178 | IbuyellowPrintln = CreateColoredPrintln("ibuyellow") 179 | IbugreenPrintln = CreateColoredPrintln("ibugreen") 180 | IbubluePrintln = CreateColoredPrintln("ibublue") 181 | IbumagentaPrintln = CreateColoredPrintln("ibumagenta") 182 | IbucyanPrintln = CreateColoredPrintln("ibucyan") 183 | IbuwhitePrintln = CreateColoredPrintln("ibuwhite") 184 | flogs *os.File 185 | pathToBashy string 186 | ) 187 | 188 | func IsDebug() bool { 189 | return os.Getenv("BASHY_DEBUG") == "true" 190 | } 191 | 192 | func init() { 193 | logger.SetFlags(0) 194 | usr, err := user.Current() 195 | if err != nil { 196 | fmt.Println("Failed to get current user") 197 | os.Exit(1) 198 | } 199 | if os.Getenv("BASHY_HOME") == "" { 200 | pathToBashy = usr.HomeDir + "/.bashy" 201 | } else { 202 | pathToBashy = os.Getenv("BASHY_HOME") 203 | } 204 | flogs, err := os.OpenFile(pathToBashy+"/logs/bashy.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0660) 205 | if err != nil { 206 | fmt.Println("Failed to open log file") 207 | os.Exit(1) 208 | } 209 | if IsDebug() { 210 | logger.SetFlags(1) 211 | ByellowPrintln("Debug mode enabled") 212 | } 213 | 214 | logger.Init("Logger", IsDebug(), IsDebug(), flogs) 215 | } 216 | 217 | func CloseLogger() { 218 | flogs.Close() 219 | logger.Close() 220 | } 221 | 222 | func BLogInfo(msg interface{}) { 223 | BLog("info", msg) 224 | } 225 | 226 | // LogWarning logs a warning message 227 | func BLogWarning(msg interface{}) { 228 | BLog("warning", msg) 229 | } 230 | 231 | // LogError logs an error message 232 | func BLogError(msg interface{}) { 233 | BLog("error", msg) 234 | } 235 | 236 | // LogFatal logs a fatal error 237 | func BLogFatal(msg interface{}) { 238 | BLog("fatal", msg) 239 | } 240 | 241 | func BLog(level string, msg interface{}) { 242 | switch strings.ToLower(level) { 243 | case "info": 244 | logger.Info(msg) 245 | case "warning": 246 | logger.Warning(msg) 247 | case "error": 248 | logger.Error(msg) 249 | case "fatal": 250 | logger.Fatal(msg) 251 | } 252 | } 253 | 254 | func CreateColoredSprint(colorName string) func(string) string { 255 | colorFunc, exists := ColorFuncMap[colorName] 256 | if !exists { 257 | return func(s string) string { 258 | return s 259 | } 260 | } 261 | 262 | return func(msg string) string { 263 | return colorFunc.Sprint(msg) 264 | } 265 | } 266 | 267 | func CreateColoredPrintln(colorName string) func(...interface{}) { 268 | colorFunc, exists := ColorFuncMap[colorName] 269 | if !exists { 270 | return func(a ...interface{}) { 271 | fmt.Println(a...) 272 | } 273 | } 274 | 275 | return func(a ...interface{}) { 276 | colorFunc.Println(a...) 277 | } 278 | } 279 | 280 | func JsonEncode(v interface{}) string { 281 | j, err := json.MarshalIndent(v, "", "\t") 282 | 283 | if err != nil { 284 | BLogError("Error encoding json") 285 | return "" 286 | } 287 | 288 | return string(j) 289 | } 290 | 291 | func JsonDecode(v interface{}) interface{} { 292 | var result interface{} 293 | err := json.Unmarshal([]byte(v.(string)), &result) 294 | 295 | if err != nil { 296 | BLogError("Error decoding json") 297 | return nil 298 | } 299 | 300 | return result 301 | } 302 | -------------------------------------------------------------------------------- /src/logs/bashy.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zeppaman/bashy/65667e0d49d9b6b04e8c28d0188fb7a2c7ac8f9c/src/logs/bashy.log -------------------------------------------------------------------------------- /src/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bashy/src/bashy" 5 | "bashy/src/logger" 6 | "bashy/src/utils" 7 | "os" 8 | ) 9 | 10 | func main() { 11 | logger.GreenPrintln("OS: " + utils.CurrentOS()) 12 | logger.BLogInfo("Bashy is starting...") 13 | 14 | instance := bashy.Bashy{} 15 | err := instance.Init() 16 | if err == nil { 17 | instance.Run(os.Args) 18 | } else { 19 | logger.BLogError("not an happy ending.") 20 | logger.BLogError(err) 21 | } 22 | instance.Destroy() 23 | defer logger.CloseLogger() 24 | } 25 | -------------------------------------------------------------------------------- /src/utils/templates/bin.tmpl: -------------------------------------------------------------------------------- 1 | 2 | #!/bin/bash 3 | # Bashy template {{.Name}} 4 | # {{.Description}} 5 | bashy {{.Name}} "$@" 6 | 7 | -------------------------------------------------------------------------------- /src/utils/utils.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "bashy/src/logger" 5 | "bytes" 6 | "crypto/md5" 7 | "crypto/rand" 8 | "encoding/hex" 9 | "fmt" 10 | "html/template" 11 | "io/ioutil" 12 | "os" 13 | "path/filepath" 14 | "runtime" 15 | 16 | // "os/exec" 17 | // "path/filepath" 18 | // "strconv" 19 | // "github.com/urfave/cli/v2" 20 | // "gopkg.in/yaml.v2" 21 | "bufio" 22 | "embed" 23 | "errors" 24 | "io" 25 | "net/http" 26 | "strings" 27 | 28 | "github.com/schollz/progressbar/v3" 29 | "gopkg.in/yaml.v2" 30 | ) 31 | 32 | //go:embed templates 33 | var tpls embed.FS 34 | 35 | func Transform(templateName string, data interface{}) string { 36 | // Create bin entry 37 | 38 | t, err := template.ParseFS(tpls, "templates/*") 39 | if err != nil { 40 | logger.BLogFatal(err) 41 | panic(err) 42 | } 43 | 44 | var tpl bytes.Buffer 45 | if err := t.ExecuteTemplate(&tpl, templateName+".tmpl", data); err != nil { 46 | logger.BLogError(err) 47 | return "" 48 | } 49 | 50 | return tpl.String() 51 | } 52 | 53 | func DirectoryExists(name string) bool { 54 | return Exists(name) 55 | } 56 | 57 | func Exists(name string) bool { 58 | _, err := os.Stat(name) 59 | if err == nil { 60 | return true 61 | } 62 | if errors.Is(err, os.ErrNotExist) { 63 | return false 64 | } 65 | return false 66 | } 67 | 68 | func TempFileName(prefix, suffix string) string { 69 | randBytes := make([]byte, 16) 70 | rand.Read(randBytes) 71 | return filepath.Join(prefix, hex.EncodeToString(randBytes)+suffix) 72 | } 73 | 74 | func GenerateToken(len int) string { 75 | randBytes := make([]byte, len*2) 76 | rand.Read(randBytes) 77 | random := hex.EncodeToString(randBytes) 78 | return random[0:10] 79 | } 80 | 81 | func WriteTextToFile(filename string, content string, mode os.FileMode) string { 82 | file, err := os.Create(filename) 83 | if err != nil { 84 | logger.BLogFatal(err) 85 | } 86 | 87 | file.WriteString(content) 88 | file.Close() 89 | 90 | os.Chmod(file.Name(), mode) 91 | return file.Name() 92 | } 93 | 94 | func WriteLinesToFile(filename string, lines []string, mode os.FileMode) string { 95 | file, err := os.Create(filename) 96 | if err != nil { 97 | logger.BLogFatal(err) 98 | } 99 | 100 | for _, line := range lines { 101 | //fmt.Println(line) 102 | file.WriteString(line + "\n") 103 | } 104 | file.Close() 105 | 106 | os.Chmod(file.Name(), mode) 107 | return file.Name() 108 | } 109 | 110 | func DownloadFile(filepath string, url string) error { 111 | 112 | // Get the data 113 | resp, err := http.Get(url) 114 | if err != nil { 115 | logger.BLogError(err) 116 | return err 117 | } 118 | defer resp.Body.Close() 119 | 120 | // Create the file 121 | out, err := os.Create(filepath) 122 | if err != nil { 123 | logger.BLogError(err) 124 | return err 125 | } 126 | defer out.Close() 127 | 128 | // Create a progress bar 129 | fileSize := resp.ContentLength 130 | bar := progressbar.DefaultBytes( 131 | fileSize, 132 | logger.BiblueSprint("Downloading"), 133 | ) 134 | 135 | // Create a multi writer to write to both the file and the progress bar 136 | writer := io.MultiWriter(out, bar) 137 | 138 | // Write the body to file and update the progress bar 139 | _, err = io.Copy(writer, resp.Body) 140 | if err != nil { 141 | logger.BLogError(err) 142 | return err 143 | } 144 | 145 | bar.Finish() 146 | logger.BiblueSprint("Download completed") 147 | return nil 148 | } 149 | 150 | func ReadFileLines(filename string) []string { 151 | lines := []string{} 152 | f, err := os.OpenFile(filename, os.O_RDONLY, os.ModePerm) 153 | if err != nil { 154 | logger.BLogFatal(err) 155 | //log.Fatalf("open file error: %v", err) 156 | return lines 157 | } 158 | defer f.Close() 159 | 160 | rd := bufio.NewReader(f) 161 | for { 162 | line, err := rd.ReadString('\n') 163 | if err != nil { 164 | if err == io.EOF { 165 | break 166 | } 167 | logger.BLogFatal(err) 168 | //log.Fatalf("read file line error: %v", err) 169 | return lines 170 | } 171 | 172 | lines = append(lines, strings.Replace(line, "\r", "", -1)) 173 | } 174 | return lines 175 | } 176 | 177 | func Copy(src, dst string) (int64, error) { 178 | sourceFileStat, err := os.Stat(src) 179 | if err != nil { 180 | return 0, err 181 | } 182 | 183 | if !sourceFileStat.Mode().IsRegular() { 184 | logger.BLogError(err) 185 | return 0, fmt.Errorf("%s is not a regular file", src) 186 | } 187 | 188 | source, err := os.Open(src) 189 | if err != nil { 190 | logger.BLogError(err) 191 | return 0, err 192 | } 193 | defer source.Close() 194 | 195 | destination, err := os.Create(dst) 196 | if err != nil { 197 | logger.BLogError(err) 198 | return 0, err 199 | } 200 | defer destination.Close() 201 | nBytes, err := io.Copy(destination, source) 202 | if err != nil { 203 | logger.BLogError(err) 204 | } 205 | return nBytes, err 206 | } 207 | 208 | func GetMD5Hash(text string) string { 209 | hash := md5.Sum([]byte(text)) 210 | return hex.EncodeToString(hash[:]) 211 | } 212 | 213 | func RemoveAll(pattern string) { 214 | files, err := filepath.Glob(pattern) 215 | if err != nil { 216 | logger.BLogFatal(err) 217 | panic(err) 218 | } 219 | for _, f := range files { 220 | fmt.Println("removing " + f) 221 | if err := os.Remove(f); err != nil { 222 | logger.BLogFatal(err) 223 | panic(err) 224 | } 225 | } 226 | } 227 | 228 | func SerializeToFile(path string, object interface{}) error { 229 | data, err := yaml.Marshal(&object) 230 | if err != nil { 231 | //fmt.Println(err) 232 | logger.BLogError(err) 233 | return err 234 | } 235 | err = ioutil.WriteFile(path, data, 0) 236 | if err != nil { 237 | //fmt.Println(err) 238 | logger.BLogError(err) 239 | return err 240 | } 241 | return nil 242 | } 243 | 244 | func CurrentOS() string { 245 | os := runtime.GOOS 246 | switch os { 247 | case "windows": 248 | return "windows" 249 | case "darwin": 250 | return "mac" 251 | case "linux": 252 | return "linux" 253 | } 254 | return os 255 | } 256 | 257 | func Contains[T comparable](s []T, str T) bool { 258 | for _, v := range s { 259 | if v == str { 260 | return true 261 | } 262 | } 263 | 264 | return false 265 | } 266 | func RemoveFromSlice[T comparable](l []T, item T) []T { 267 | for i, other := range l { 268 | if other == item { 269 | return append(l[:i], l[i+1:]...) 270 | } 271 | } 272 | return l 273 | } 274 | -------------------------------------------------------------------------------- /test/yaml.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "io/ioutil" 7 | "path/filepath" 8 | 9 | "gopkg.in/yaml.v2" 10 | ) 11 | 12 | type Parameter struct { 13 | Name string 14 | Desc string 15 | Type string 16 | } 17 | 18 | type Script struct { 19 | Cmds []string // map[string][]string 20 | Cmd string 21 | Name string 22 | Params []Parameter 23 | } 24 | 25 | func main() { 26 | filename, _ := filepath.Abs("samples/bash.yml") 27 | yamlFile, err := ioutil.ReadFile(filename) 28 | 29 | if err != nil { 30 | panic(err) 31 | } 32 | 33 | var config Script 34 | 35 | err = yaml.Unmarshal(yamlFile, &config) 36 | if err != nil { 37 | panic(err) 38 | } 39 | 40 | fmt.Printf("Value: %#v\n", prettyPrint(config)) 41 | } 42 | 43 | func prettyPrint(i interface{}) string { 44 | s, _ := json.MarshalIndent(i, "", "\t") 45 | return string(s) 46 | } 47 | --------------------------------------------------------------------------------