Why is the shape of lightning or an electric spark a zig-zag line? Why is the shape of the lightning (or an electric spark) always of a zig-zag nature? Why is it never just a straight line? 

Image source.
 A: The lightning is just electricity, a huge burst of electrons that try to find the path of least resistance through the molecules of the atmosphere to the ground.
The electrons come from many different places in the clouds 
and the atmosphere is not homogeneous: there are differences in humidity, temperature, density, particle count, velocity, etc., and this is particularly true in thunderstorms. Charges build up all over the place and electric fields exist all over as well, sooner or later one or more of these electric fields reach critical strength, or perhaps a cosmic ray ionizes a path through the middle of it where things start to conduct and there it goes: lightning and thunder. 
While moving electrons are subject to change of direction from magnetic fields. The energy is coming from differences in statics voltage levels or electric fields
The electric arc forms where the air is most easily ionized (which is what makes it conduct electricity) and generally in the direction of shortest distance between the electrical charge and the ground (the electrically lower potential).
A: The lighting shape and path is a non-linear phenomenon. Why? Because it involves a multitude of interactions with the medium (air molecules, atmosphere) and these depending on range of interecations are also non-linear. However there are compatibility conditions (or conserved quantities), as such this is a good example of the fractal geometry of nature.

A: 
Why is it never just a straight line?

I think it can be interesting to answer both questions and add a few interesting details to the answer already given. 


*

*Electrons move in a straight line only in vacuum, where they meet no obstacles. What happens here is the same that happens with a river: the water of a waterfall goes in a straight line because it meets no obstacles, but the water of a river on a slope follows a zig-zag line meandering. In lighining that phenomenon is called: 'tortuosity' picture 10.3 (below) looks exactly like the meandering of a river) trying to 'find' the path of least resistance. But water and electrons do not make a choice, of course, they just move as soon as it is possible when there is no obstacle, then we call it 'finding the path...' and can ask: How does lightning "know" where to go?.





*

*The zig-zag line is a sort of optical illusion, if you watch the slow motion of a ligtning on YT here at 3:04  or here from 0.45 to 0.51, you will see that the real path looks like the course of a river.
Each discharge is a series of steps in which the current travels a short distance and then pauses: each pause is where we see a change in direction. Meanwhile the local potential to ground is changing, so the final target is constantly changing. 

*As the discharge approaches the earth, many potential targets might be seen, but only one or a few will ionize the local air enough to provide the final path to ground, a small discharge can be seen coming from objects that were failed targets, and there is upward lightning. That explains also why the zig-zag line is not perpendicular to the ground. 

*You can compare the actual course of the lightning in the above picture 10.3 with the picture you get with an ordinary camera or with the eye:

The secondary branches are only temporary and in different directions, but they remain impressed on the retina at the real flow of time.
