Prepare:

Install ffmpeg, to shorten encoding duration. Please considering compiling ffmpeg yourself(instead of using binary file from package).
Install ImageMagick (or GraphicsMagick).

Go capture your screen:

$ sleep 10; ffmpeg -y -video_size 1366x680 -framerate 25 -f x11grab -i :0.0+0,80 output.mp4
## sleep {X}: prepare for X seconds before start recording
## -y: overwrite output.mp4 if exists
## -video_size {width}x{height}: make frame size to width x height
## -framerate: frame per second
## -f x11grab: the encoder used, you shouldn't modify this =/
## -i {a}.{b}+{left},{top}: record screen {a}.{b}(FYI: X server $DISPLAY) with offset from left top corner of screen to {left} {top}

Review and trim your clip(output.mp4 -> myclip.mp4)

$ ffmpeg -y -i output.mp4 -ss 3 -t 11 myclip.mp4; ffplay myclip.mp4
## -i: specify which input file
## --ss {n}: trim {n} seconds from begining
## -t {d}: secify the duration of myclip.mp4
## ffplay: play myclip.mp4 once the encoding ends

Output as series of pictures(myclip.mp4 -> PNGs)

$ rm -rf frames
$ mkdir frames
$ ffmpeg -i myclip.mp4 -vf scale=320:-1:flags=lanczos,fps=10 frames/ffout%03d.png
## frames/: make a new directory to store output pictures
## scale={width}:-1: make pictures at scale of {width} with calculated height
## flags={whatever}: some MAGIC
## fps={x}: make pictures with playback at {x}fps
## ffout%03d.png: file name with 001, 002, ..., 999

Combine series of pictures(PNGs -> GIF)

$ convert -delay 3 -loop 0 -dither None -colors 80 "frames/ffout*.png" -fuzz "10%" -layers OptimizeFrame "output.gif"
## -delay {f}: skip {f} frames between each frame in GIF, making GIF playing fast
## -loop 0: make GIF loop forever
## -color {c}: Make about {c} colors in available in GIF
## -fuzz "10%": fuzz each frame, would make GIF not recognizable
## -layers: some MAGIC

Here’s the demo GIF[54s(mp4) -> ~20s(GIF), 900k]:

demo of converting

with:

$ sleep 2; ffmpeg -y -video_size 683x384 -framerate 15 -f x11grab -i :0.0+0,0 output.mp4
$ ffmpeg -i output.mp4 -ss 10 -t 54 myclip.mp4; ffplay myclip.mp4
$ ffmpeg -i myclip.mp4 -vf fps=6 frames/ffout%03d.png
$ convert -delay 7 -loop 0 -dither None -colors 3 "frames/ffout*.png" -fuzz "10%" -layers OptimizeFrame "output.gif"

Reference:

More demo GIFs!!1
Compiling ffmpeg
Capture screen in Linux
How to trim first seconds with ffmpeg
How to convert with reasonable quality