Techno Blender
Digitally Yours.

Revolutionize the Bash scripting experience with Bashy

0 54


The story behind Bashy the script manager for Bash scripts

In this article, I will introduce the Opensource project Bashy, a tool that enhances the scripting experience by facilitating argument parsing and making it possible to share scripts as every package manager does. In another word, I made work Bash as any modern scripting framework should. This can be a boost for improving productivity and automating recurring tasks for programmers and data scientists.

I will explain why we need a tool like Bashy, and then show how it can be used with some practical examples. Finally, after we will have discovered how it can save hundreds of hours for developers, I will move into the internal components to explain how it works.

Let’s jump into the article!

Made with ❤️by the author.

The aim of Bashy is to reduce the friction in scripting. The most common issues are:

  • parsing input and providing a help page for the script that we created. This is usually messy and requires a lot of time, so this phase is often skipped and we have scripts that are hard to run. Often, developers need to open them and change the variable inside the script itself.
  • Sharing scripts. The most common way to share scripts is to copy/paste files from one PC or server to another. This practice is very old style and it’s hard to update scripts as one of the copy changes.

Bashy is willing to overcome all that problems by implementing:

  • a package manager for Bash
  • an easy way for parsing arguments.

Friction using bash scripts

Bash scripts solve a lot of problems but in most cases:

  1. resides on the PCs of their authors: sharing them is very hard
  2. are not parametric: parameters are inside the script and the author changes them directly instead of parsing the arguments

Why? Nowadays this behaviour seems very odd, but if you look at what are the options it’s clear that a developer has no option. In fact:

  1. there isn’t any repository where pushing your script for sharing
  2. make the script parametric and requires tons of code

That’s why I create Bashy:

THE PURPOSE OF BASHY IS TO OVERCOME THIS LIMITATIONS

Now that we understood why it was important to create a tool for managing bash scripts, let’s see how it works in practice!

Instead of talking a lot about Bashy, I prefer to explain it by an example. Let’s suppose to create a bash script that lists the file in a folder. The given parameters are the path of the folder and the extension to use for filtering files.

Well, for implementing it in bash parsing arguments you will have something like this in the following snippet.

Traditional bash script

Note that in the previous script only the last two lines of code are needed for implementing the script, all the 34 lines above are required only for parsing argument. Moreover, you do not have any help page and adding a new parameter will complicate things. How Bashy can make it better?

Using Bashy, you will have to write only the following code:

As you see, you have the parameters parsed for free and some variables yet populated that are ready to use. This translates into a huge simplification and, as you see it later, you have also a help page available without any additional effort.

That’s magic? Let’s see in the next section how it is possible.

As information is a science, there isn’t any incantation or magic wand behind the hood. The pillar of Bashy is to describe the script by adding a manifest in YAML format. The YAML and the script together make a package that can be portable and contains all that is required by Bashy to be required.

How Bashy packages are made. Made with ❤️by the author

An example of the previous script can be the following snippet:

script fore reading folder in bashy. Made with ❤️by the author.

The YAML manifest contains all the information to be displayed on the help pages and the script to be executed (can be embedded like in this case or a reference to an external resource). Moreover, you define the parameter list that is used by the argument parsing engine.

This information is used to create a help page like in the following example:

example of command help. Made with ❤️by the author.

As you see, the command is registered from Bashy as a global command and you can write it directly as it was a real binary installed on the OS.

The script made with this technology can be easily shared (you just need to publish on every HTTP server, git included) and helps to build more usable scripts.

But how it is implemented? The Bashy engine is built using Go and is available as an open-source application.

How bashy was made. Made with ❤️ by the author

The next figure shows the main flows of the application:

Main flows of the application,Made with ❤️ by the author

Basically, the Bashy engine adds the information contained in the YAML file into an internal database (red flow). Since you have the information, you can easily list all the commands available and provide help pages (blue flow). Finally, Bashy can execute commands by parsing arguments and passing values as variables to the script you aim to run. The output is then shown to the user.

To discover more about bashy you can:

By the way, I think that Bashy’s potential has not been fully realised. In the next section, I will explain what can be the next feature to add to make it smoother.

Like every product, also open-source applications must look at the market and at the user’s needs. Starting from this, you can get a list of features to add to the backlog. From my experience and from the feedback I got so far, there is a set of improvements that could be very useful. I summarize them in the next picture:

next steps of bashy. Made with ❤️by the autor

So, citing Eric Reis, author of Lean Startup:

WE MUST LEARN WHAT CUSTOMERS REALLY WANT, NOT WHAT THEY SAY THEY WANT OR WHAT WE THINK THEY SHOULD WANT.

This pushes me to hear the feedback of users for giving the right priority to these tasks.

Basically, the most wanted feature is to add a public repository where to add scripts allow users to search them by a web UI and install them locally. Moreover, a smother installation process is also welcome as better documentation on the website.

Anyway, any feedback is welcome and part of the improvement process! So, if you are a Bashy user or you are planning to test it, don’t forget to give me feedback 😃

Bash is a technology widely used but with some friction that makes it hard to implement reusable scripts. Bashy was born to overcome these issues and unleash the power of bash. As with every product, also open-source project needs to listen to the user’s need so it’s important to give feedback to the authors (this is true in general, not only for Bashy). I hope to have given you an opportunity for improving your script experience, don’t hesitate to write your feedback in the comments 😄

References:


The story behind Bashy the script manager for Bash scripts

In this article, I will introduce the Opensource project Bashy, a tool that enhances the scripting experience by facilitating argument parsing and making it possible to share scripts as every package manager does. In another word, I made work Bash as any modern scripting framework should. This can be a boost for improving productivity and automating recurring tasks for programmers and data scientists.

I will explain why we need a tool like Bashy, and then show how it can be used with some practical examples. Finally, after we will have discovered how it can save hundreds of hours for developers, I will move into the internal components to explain how it works.

Let’s jump into the article!

Made with ❤️by the author.

The aim of Bashy is to reduce the friction in scripting. The most common issues are:

  • parsing input and providing a help page for the script that we created. This is usually messy and requires a lot of time, so this phase is often skipped and we have scripts that are hard to run. Often, developers need to open them and change the variable inside the script itself.
  • Sharing scripts. The most common way to share scripts is to copy/paste files from one PC or server to another. This practice is very old style and it’s hard to update scripts as one of the copy changes.

Bashy is willing to overcome all that problems by implementing:

  • a package manager for Bash
  • an easy way for parsing arguments.

Friction using bash scripts

Bash scripts solve a lot of problems but in most cases:

  1. resides on the PCs of their authors: sharing them is very hard
  2. are not parametric: parameters are inside the script and the author changes them directly instead of parsing the arguments

Why? Nowadays this behaviour seems very odd, but if you look at what are the options it’s clear that a developer has no option. In fact:

  1. there isn’t any repository where pushing your script for sharing
  2. make the script parametric and requires tons of code

That’s why I create Bashy:

THE PURPOSE OF BASHY IS TO OVERCOME THIS LIMITATIONS

Now that we understood why it was important to create a tool for managing bash scripts, let’s see how it works in practice!

Instead of talking a lot about Bashy, I prefer to explain it by an example. Let’s suppose to create a bash script that lists the file in a folder. The given parameters are the path of the folder and the extension to use for filtering files.

Well, for implementing it in bash parsing arguments you will have something like this in the following snippet.

Traditional bash script

Note that in the previous script only the last two lines of code are needed for implementing the script, all the 34 lines above are required only for parsing argument. Moreover, you do not have any help page and adding a new parameter will complicate things. How Bashy can make it better?

Using Bashy, you will have to write only the following code:

As you see, you have the parameters parsed for free and some variables yet populated that are ready to use. This translates into a huge simplification and, as you see it later, you have also a help page available without any additional effort.

That’s magic? Let’s see in the next section how it is possible.

As information is a science, there isn’t any incantation or magic wand behind the hood. The pillar of Bashy is to describe the script by adding a manifest in YAML format. The YAML and the script together make a package that can be portable and contains all that is required by Bashy to be required.

How Bashy packages are made. Made with ❤️by the author

An example of the previous script can be the following snippet:

script fore reading folder in bashy. Made with ❤️by the author.

The YAML manifest contains all the information to be displayed on the help pages and the script to be executed (can be embedded like in this case or a reference to an external resource). Moreover, you define the parameter list that is used by the argument parsing engine.

This information is used to create a help page like in the following example:

example of command help. Made with ❤️by the author.

As you see, the command is registered from Bashy as a global command and you can write it directly as it was a real binary installed on the OS.

The script made with this technology can be easily shared (you just need to publish on every HTTP server, git included) and helps to build more usable scripts.

But how it is implemented? The Bashy engine is built using Go and is available as an open-source application.

How bashy was made. Made with ❤️ by the author

The next figure shows the main flows of the application:

Main flows of the application,Made with ❤️ by the author

Basically, the Bashy engine adds the information contained in the YAML file into an internal database (red flow). Since you have the information, you can easily list all the commands available and provide help pages (blue flow). Finally, Bashy can execute commands by parsing arguments and passing values as variables to the script you aim to run. The output is then shown to the user.

To discover more about bashy you can:

By the way, I think that Bashy’s potential has not been fully realised. In the next section, I will explain what can be the next feature to add to make it smoother.

Like every product, also open-source applications must look at the market and at the user’s needs. Starting from this, you can get a list of features to add to the backlog. From my experience and from the feedback I got so far, there is a set of improvements that could be very useful. I summarize them in the next picture:

next steps of bashy. Made with ❤️by the autor

So, citing Eric Reis, author of Lean Startup:

WE MUST LEARN WHAT CUSTOMERS REALLY WANT, NOT WHAT THEY SAY THEY WANT OR WHAT WE THINK THEY SHOULD WANT.

This pushes me to hear the feedback of users for giving the right priority to these tasks.

Basically, the most wanted feature is to add a public repository where to add scripts allow users to search them by a web UI and install them locally. Moreover, a smother installation process is also welcome as better documentation on the website.

Anyway, any feedback is welcome and part of the improvement process! So, if you are a Bashy user or you are planning to test it, don’t forget to give me feedback 😃

Bash is a technology widely used but with some friction that makes it hard to implement reusable scripts. Bashy was born to overcome these issues and unleash the power of bash. As with every product, also open-source project needs to listen to the user’s need so it’s important to give feedback to the authors (this is true in general, not only for Bashy). I hope to have given you an opportunity for improving your script experience, don’t hesitate to write your feedback in the comments 😄

References:

FOLLOW US ON GOOGLE NEWS

Read original article here

Denial of responsibility! Techno Blender is an automatic aggregator of the all world’s media. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials, please contact us by email – [email protected]. The content will be deleted within 24 hours.
Leave a comment