Fix the assertion failure in expand_variables()

expand_variables() is slightly confused about how to handle last_idx. On
input, it expects it to be the index to start processing at, but when
called recursively it always passes the current index. This means that
it may sometimes pass an index 1 past the end of the input string.
Notably, that happens when typing something like

> echo "$foo

(where "foo" is any string that is not a prefix of some existing
variable name)

Fix this by explicitly defining last_idx as being the last processed
index, meaning the next index to process is actually last_idx-1. This
means we should call it with next.size() instead of next.size()-1.
Fix typo in German translation
Add Fossil command completions.
Fix $SHLVL

Due to being read-only, SHLVL wasn't being incremented properly for
recursive invocations of fish.
Fix `commandline` behavior in bind functions

When a key is bound to a fish function, if that function invokes
`commandline`, it gets a stale copy of the commandline. This is because
any keys passed to `self-insert` (the default) don't actually get added
to the commandline until a special character is processed, such as the
R_NULL that gets returned after running a binding for a fish command.

To fix this, don't allow fish commands to be run for bindings if we're
processing more than one key. When a key wants to invoke a fish command,
instead we push the invocation sequence back onto the input, followed by
an R_NULL, and return. This causes the input loop to break out and
update the commandline. When it starts up again, it will re-process the
keys and invoke the fish command.

This is primarily an issue with pasting text that includes bound keys in
it. Typed text is slow enough that fish will update the commandline
between each character.

---

I don't know of any way to write a test for this, but the issue can be
reproduced as follows:

    > bind _ 'commandline -i _'

This binds _ to a command that inserts _. Typing the following works:

    > echo wat_is_it

But if you copy that line and paste it instead of typing it, the end
result looks like

    > _echo wat_isit

With this fix in place, the pasted output correctly matches the typed
output.
Rework how screen size is tracked

The screen size is fetched after a SIGWINCH is delivered. The current
implementation has two issues:

* It calls ioctl() from the SIGWINCH signal handler, despite ioctl() not
  being a function that is known to be safe to call.
* It's not thread-safe.

Signals can be delivered on arbitrary threads, so we don't know if it's
actually safe to be modifying the cached winsize in response to a
signal. It's also plausible that the winsize may be requested from a
background thread.

To solve the first issue, we twiddle a volatile boolean flag in the
signal handler and defer the ioctl() call until we actually request the
screen size.

To solve the second issue, we introduce a pthread rwlock around the
cached winsize. A rwlock is used because it can be expected that there
are likely to be far more window size reads than window size writes. If
we were using C++11 we could probably get away with atomics, but since
we don't have that (or boost), a rwlock should suffice.

Fixes #1613.
Trim trailing newline on cmdsubst when IFS=''

When $IFS is empty, command substitution no longer splits on newlines.
However we still want to trim off a single trailing newline, as most
commands will emit a trailing newline and it makes it harder to work
with their output.
Fix fish_vi_mode.fish
Fix small typo in documentation
Merge pull request #1655 from xakon/master

Fix small typo in documentation
Fix F1 binding to work with multiple tokens.
Don't segfault when erasing short option completions

When using `complete -s x -e`, the long option is unspecified, which
makes it NULL. Comparing this to a `wcstring` segfaults.

Fixes #1182.
Don't erase all long opts with `complete -e`

When using `complete -c foo -l bar -e`, all long options for the command
were being erased because it was also comparing the short option, which
was 0.
Don't erase old-style options with `complete -l foo -e`

When erasing long option completions, distinguish between gnu-style and
old-style options, just like we do when adding and printing completions.
Erase all completions with `complete -c foo -e`

When passing `-e` to `complete -c foo` without any other options, all
options for the command should be erased.

Fixes #380.
Add tests for the various `complete -e` changes
Fix test output for `complete -e` tests

GNU sort behaves stupidly when LC_ALL is not C. This caused the test
output to be sorted wrong.
failiure/failure

Fix misspelling of failure in the fish shell design doc
New -n option for read builtin

Usage: read -n nchars
Reads maximum of nchars characters. If nchars <= 0, there's no limit.
Fix the fix for `commandline -i` in binds