Jun 192014
 

… or a red ✗. Incidentally, if your browser doesn’t show ticks (✓), crosses (✗), and a right pointing double arrow (») properly, this posting may look a bit odd.

As in :-

2014-06-19_1934

The aim here is to make the zsh prompt (a Unix shell) start with a green ✓ (tick) if the previous command’s exit status was zero, and a red ✗ (cross) if the previous command’s exit status was non-zero. A tiny thing, but both useful and fun.

The first thing I need is a set of variables containing terminal sequences for setting colours. Fortunately zsh comes with a set of suitable functions; even if they’re poorly named :-

autoload -U colors && colors

The next thing is to perform a test to see if the current terminal type is worth setting a fancy prompt for. In some cases – such as when using the plain Linux console, or when things are broken enough that the terminal type isn’t set properly – it is worth avoiding setting a prompt. I do this by setting up an array containing a list of terminal types that I think it is worth setting a fancy prompt for :-

fancyterms=()
fancyterms=(xterm xterms dtterm iris-ansi xterm-256color)

(Some of that list is very historical!)

The test for whether to set a fancy prompt is somewhat tricky … it uses a ‘reverse subscripting’ flag in the array lookup to search the array for the string :-

if [[ ${fancyterms[(r)$TERM]} == "$TERM" ]] 
then
  echo Fancy prompt
else
  echo Plain prompt
fi

And lastly, I actually set the prompt :-

export PROMPT="%(?.%{$fg[green]%}✓ %{$reset_color%}.%{$fg[red]%}✗ %{$reset_color%})%B%n@%m»%b "

Which is not exactly the easiest string to understand, but breaking it up :-

  1. The %{$fg[green]%} sequence sets the colour to green, the ✓ is fairly self-explanatory, and the %{$reset_color%} sets the colours back to normal.
  2. Similarly the %{$fg[red]%} sets the colour to red, the ✗ should also be self-explanatory, and the %{reset_color%} does as before.
  3. The sequence %{ … %} is very important as any output that does not advance the cursor should be contained within these. This allows zsh to count the number of visible characters within the prompt so that various screen operations happen in the right location. Judging by how often this is emphasised (and the fact that I made a mistake with it myself), it looks to be a very common problem.
  4. The sequence %{?.True.False%} tests the exit status of the previous command and if true outputs the first string and if false outputs the second string.
  5. The sequence at the end – %B%n@%m»%b – turns bold on (%B), outputs the username (%n), outputs an “@”, outputs the short machine name (%m), outputs a literal “»”, turns off cold (%b), and finally adds a space to the prompt.

Putting it all together, I get :-

# Now the prompt
autoload -U colors && colors
#       Enable colour variables (used in prompt)
fancyterms=()
fancyterms=(xterm xterms dtterm iris-ansi xterm-256color)
#       An array of 'fancy' terminal types that we do more for … as in a funky PROMPT.

if [[ ${fancyterms[(r)$TERM]} == "$TERM" ]] 
then
        precmd () { print -Pn '\e]2;%n@%m - %~^G' }
        # Put the hostname in the Window title/Tab title
        export PROMPT="%(?.%{$fg[green]%}✓ %{$reset_color%}.%{$fg[red]%}✗ %{$reset_color%})%B%n@%m»%b "
        # And set a really fancy prompt.
else
        # If we don't recognise the terminal type, don't attempt to be quite so ambitious
        # with the prompt.
        export PROMPT=$'%B%n@%m - %~\n%#%b '
fi

This is still a little bit plain compared with what some people do with their prompts, but it is right for me (at least for now).
 

Jun 162014
 

There is a fair bit of news around at present with respect to the current sectarian conflict in Iraq, including the news of mass killings by ISIS. And of course we have a number of talking heads appearing on TV talking about the causes of the sectarian conflict. And often blaming the US intervention in Iraq.

Which is of course a complete red herring.

The previous regime in Iraq kept the lid on sectarian conflicts between Shias and Sunnis with extreme repression. Even a very superficial look at the history of the conflict shows that sectarian conflict was almost inevitable after the removal of Saddam Hussain.

And the blame for that conflict lies with the extremists within both Shia and Sunni communities – not with the Americans or British who fought to remove Saddam Hussain. Whilst the western forces may well be guilty of many things – including human rights abuses – this sectarian conflict is not something they brought about.

Ultimately sectarian conflicts in Iraq can only be solved by the Iraqis themselves.

 

Jun 092014
 

The issue of certain faith-based schools is in the media today. Specifically whether certain schools in Birmingham were targeted for take-over by islamic extremists. Lots of allegations floating around with lots of denials.

Determining the truth of the matter is not likely to be easy – do I believe Tory ministers or religious nutters? By nature, I’m inclined to ignore both.

But there is a simple answer to this problem. Take any sort of faith out of all schools; schools are supposed to be about education and not about fairy stories. Any kind of faith activity should be classified as an extra-curricular activity that takes place outside school and has no interference with the normal school curriculum.

It is probable that most faith based schools are relatively harmless, although even the best will lead to a sense of exclusion for those in attendance whose faith does not match that of the school. And of course teenagers are probably the most likely group to change religion or reject religion altogether.

But whenever faith-based schools are permitted, there is always the chance that some form of extremism may creep into the curriculum. And that includes all religions – there are extremist christians who want to block the teaching of evolution as well as extremist muslims, hindus, etc.

Ban ’em all.

Jun 052014
 

Apostasy can be loosely defined as renouncing a religion either to become an atheist or to convert to another religion. It has been in the news recently because of a Sudanese woman sentenced to death for apostasy.

Of course in her case it’s not apostasy, but following her childhood religion – her mother was a christian and her absent father was a muslim. But Sudan does not recognise the mother’s religion in such cases.

However you slice it, the concept of apostasy is ridiculous – it basically forces people who have “lost their way” to pretend to follow a religion. Forcing someone to go to a mosque (or a church, etc.) will just annoy and bore the victim. And yes listening to some holly roller prattle on about his imaginary friend is very boring.

It is noticeable that only islamic countries have a criminal sanction for apostasy, and probably only for deserting islam. In fact that is not quite true – other countries have had laws against apostasy … or herest which to an unbeliever is pretty much the same thing. After all apostasy is along the lines of “you don’t believe in what we believe” and heresy is merely a slightly different flavour of “you don’t believe what we believe”. The “best” example of a christian country executing someone for apostasy is probably Poland,

Although there are plenty of other examples.

But countries with a history of christianity have progressed on from a primitive medieval society that executes people for “crimes” as ridiculous as apostasy. Ignoring the rights and wrongs of it, apostasy is another group’s convert. And executing someone for being a protestant, a jew, a muslim or an atheist is nothing more than persecution of a minority group and will sooner or later (hopefully very much sooner) lead to all sorts of problems with such a society.

After all, a persecuted minority does not have much interest in protecting the status quo – they might well want to start a revolution and kick out the leaders.

Islamic law-makers need to look at implementing apostasy laws even handedly and prosecute christians, jews, and atheists who convert to islam – because they are apostates too. And of course babies are not born with a knowledge of islam, so they can be considered apostates as well. If you threaten to execute islamic apostates, then you need to threaten to execute all the other apostates too.

And then you might realise just how foolish laws against apostasy are.