Posts Tagged ‘shell’

So the documentation for Powerline kind of sucks. I followed this pretty good article on getting started with it. First thing I noticed however is that the if statement on the article doesn’t work if you don’t have powerline installed (which kind of defeats the purpose of having the if statement there at all).

Next up is the configuration. I primarily use my bash prompt as a way to indicate which branch I’m working in within a Git repository. You need to point at the default_leftonly theme which is pretty easy to find when you web search for it. The issue is everything seems to just point you at the powerline docs, which aren’t the most clear.

First, start by creating a local configuration directory that will override the configuration for powerline for your user.

$ mkdir -p ~/.config/powerline

Then the next thing is to copy over the config.json from the main powerline configuration directory where you can find the available color schemes and other shell, i3, vim, etc themes.

(Again, the documentation kind of sucks on where the root of these configurations live…)

On my Fedora 22 system they live in /etc/xdg/powerline/. I then copy the config.json from that directory to ~/.config/powerline

To get the Git branch stuff going, I modified the configuration file in the following way:

To make it active you can run powerline-config --reload. If you have any errors in your configuration (I actually ran into this when playing with the colorscheme setting and used “solorized” instead of “solarized”), you can check it with powerline-lint.

Preamble

Today on the VoIP Users Conference we discussed my request for recipe ideas in order to start developing some additional documentation. Specifically, I’m looking for problems that are simple, common problems that can be solved in the dialplan, and which are good examples of the dialplan language (markup, script, yadda yadda).

One of the suggestions was something posted to the Asterisk mailing list which was pretty straight forward: to read in the contents of a file, where the file contained a number which was the current temperature. This file was created by an external script, and the poster was looking for how to read in the contents of that file, and play back something that would say the number, followed by “degrees”.

The discussion delved into some possible solutions, and delved into the problem with writing Asterisk recipes in general; that there are always several ways to skin the same cat. Below I will mention some of the examples that had come up on the conference call in the Discussion section, and will then show a dialplan (that works on Asterisk 1.4) that will solve the problem proposed in the Solution section.

Problem

To read the contents of a file, where the contents will contain a number, that needs to be read back to the caller, followed by the word “degrees”.

Discussion

The solution above is really the “right” way to do it in Asterisk. But with Asterisk, there always seems to be many “right” ways to solve the same solution. Because the problem was to read in the contents of a file and to say the contents back, then the solution I provided certainly solves that problem directly in dialplan without any external scripts, or dropping to the console.

There were several other solutions that could have been provided for this solution since there was an external PHP script that was generating the file and its contents. That script could have done any of the following:

Execute a shell command, and write the contents to the Asterisk database:asterisk -rx "database put temperature current 60"

Write the contents to a relational database such as MySQL and use func_odbc: Set(TEMPERATURE=${ODBC_TEMP()})

On Asterisk 1.6, there is the SHELL() function:Set(TEMPERATURE=${SHELL(cat /tmp/current_temperature.txt)})

I particularly like the curl solution since it allows the script to lookup the temperature when the CURL() function calls it, which means it can be real time and not delayed like writing to a text file can be.

So like with all things Asterisk, there are always many inventive ways to solve the same solution.