Commit Graph

4108 Commits

Author SHA1 Message Date
Kevin Ballard
cc52a59e1a 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.
2014-08-29 12:46:03 -07:00
Kevin Ballard
24ac7d2698 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.
2014-08-29 12:29:48 -07:00
Kevin Ballard
130619d6b0 Fix $SHLVL
Due to being read-only, SHLVL wasn't being incremented properly for
recursive invocations of fish.
2014-08-29 12:22:35 -07:00
Konrad Borowski
71ab40e536 Add Fossil command completions. 2014-08-29 14:19:55 +02:00
Philipp Klose
7638a7d531 Fix typo in German translation 2014-08-29 11:23:08 +02:00
Kevin Ballard
b92a09d5e7 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.
2014-08-28 13:29:43 -07:00
Kevin Ballard
02a07164f3 Make commandline -P actually work
`commandline --paging-mode` worked but the short flags list accidentally
omitted the documented `-P`.
2014-08-24 14:47:05 -07:00
ridiculousfish
9419191aa6 Clean up variable expansion, and properly handle embedded NULs 2014-08-24 14:39:56 -07:00
ridiculousfish
f71b10df8c Don't suggest after | & or in comments
Fixes #1631
2014-08-24 14:39:41 -07:00
ridiculousfish
0b7735d279 Merge pull request #1630 from kballard/expand_variables_in_quoted_strings
Fix various expansions issues with variables
2014-08-23 16:13:25 -07:00
Konrad Borowski
1f3a93a3af
Fix the compilation under gcc 4.9.0.
gcc interpretes C99's compound literals more strictly by invalid the
compound literal on implicit to pointer cast (because of automatic
storage duration, 6.5.2.5.6 in C99 standard draft).

This fixes the issue by not using compound literals at all.
2014-08-22 21:52:41 +02:00
ridiculousfish
f9f773cc28 Comment on why we run 'false' in web_config.py 2014-08-22 12:04:23 -07:00
Kevin Ballard
d9bf53c6e5 Show a non-zero status in the fish_config prompt
When selecting a prompt with fish_config, render the prompt with a
non-zero status so the user knows what it looks like.
2014-08-22 12:00:16 -07:00
Kevin Ballard
f549ada16c Set up fish_{function,complete}_path properly
In the base config.fish, fish_function_path and fish_complete_path have
$__fish_datadir/{functions,completions} added to them if not already
present. For some reason they were replacing the final path component
instead of being added on to the end.
2014-08-22 11:54:58 -07:00
ridiculousfish
d8b955294a Add a test for syntax highlighting pipes 2014-08-22 11:53:20 -07:00
Kevin Ballard
8aad53556d Highlight pipe characters correctly
According to `fish_config`'s colors page, the pipe operator `|` is
supposed to be colored the same as a statement terminator.
2014-08-22 11:45:05 -07:00
Kevin Ballard
61ce9db4ba Make the alias built-in function work better
The new --wraps functionality was breaking aliases of the form
`alias foo='bar baz'`. That is, aliases where the body is multiple
words. Extract the first word of the body and use that instead.

Use better errors for aliases with no name or no body.
2014-08-22 11:40:59 -07:00
ridiculousfish
2da435712a Merge branch 'master' of github.com:fish-shell/fish-shell 2014-08-22 11:39:41 -07:00
Andy Lutomirski
9079ec459c webconfig: fixes for token security
* Use 16-byte tokens
 * Use os.urandom (random.getrandbits shouldn't be used for security)
 * Convert to hex correctly
2014-08-22 15:44:43 +08:00
Andy Lutomirski
aaddccfdb1 webconfig: Use a constant-time token comparison
This prevents a linear-time attack to recover the auth token.
2014-08-22 15:39:13 +08:00
ridiculousfish
033373f078 Merge branch 'make_type_better' of github.com:kballard/fish-shell into kballard-make_type_better 2014-08-21 21:36:39 -07:00
Kevin Ballard
d63db59ade Clean up the IFS handling in command substitution
Remove the useless ASCII test of the first byte of IFS. We don't split
on the first character, we only use a non-empty IFS as a signal to split
on newlines.
2014-08-21 20:57:23 -07:00
Kevin Ballard
20899f2df9 doc: Document how IFS affects command substitution
IFS is used for more than just the read builtin. Setting it to the empty
string also disables line-splitting in command substitution, and it's
done this for the past 7 years. Some day we may have a better way to do
this, but for now, document the current solution.
2014-08-21 20:57:23 -07:00
Kevin Ballard
b9948ca297 doc: Fix docs on $HOME/$USER
The docs claimed that the $HOME and $USER variables could only be
changed by the root user. This is untrue. They can be changed by
non-root users as well.
2014-08-21 20:57:23 -07:00
Kevin Ballard
f33e6a053e doc: Fix links in "Further help and development"
Hyperlink the mailing list to the proper info page.

Tweak the GitHub link to use https.
2014-08-21 19:15:58 -07:00
Kevin Ballard
9f725bee1f set: Print an error when setting umask to a bad value
Repurpose the ENV_INVALID return value for env_set(), which wasn't
currently used by anything. When a bad value is passed for the 'umask'
key, return ENV_INVALID to signal this and print a good error message
from the `set` builtin.

This makes `set umask foo` properly produce an error.
2014-08-21 19:06:21 -07:00
Kevin Ballard
2974025010 Fix error span for invalid slice indexes
The span now properly points at the token that was invalid, rather than
the start of the slice.

Also fix the span for `()[1]` and `()[d]`, which were previously
reporting no source location at all.
2014-08-21 01:10:07 -07:00
Kevin Ballard
9a90e041f3 Color "$foo[1" as an error
We can't color the whole argument as an error, since the tokenizer is
responsible for that and doesn't care abou this case, but we can color
the `$foo[` bit as an error.
2014-08-20 22:55:24 -07:00
Kevin Ballard
b0be15d4f7 Fix highlighting of "foo\"bar"
The backslash-escape wasn't being properly caught by the highlighter.

Also remove the highlighting of `"\'"`, as `\'` is not a valid escape in
double-quotes, and add highlighting for a backslash-escaped newline.
2014-08-20 22:34:18 -07:00
Kevin Ballard
a24998abac Highlight "$foo[1]" properly
Preserve the highlighting applied to the slice brackets when coloring
variables inside of double-quoted strings.
2014-08-20 22:28:42 -07:00
Kevin Ballard
cc49042294 Parse slices even for empty variables
When a variable is parsed as being empty, parse out the slice and
validate the indexes anyway, behaving for slicing purposes as if the
variable had a single empty value.

Besides providing errors when expected, this also fixes the following:

    set -l foo
    echo "$foo[1]"

This used to print "[1]", now it properly prints nothing.
2014-08-20 22:09:32 -07:00
Kevin Ballard
3981b644d6 Fix double expansions ($$foo)
Double expansions of variables had the following issues:

* `"$$foo"` threw an error no matter what the value of `$foo` was.
* `set -l foo ''; echo $$foo` threw an error because of the expansion of
  `$foo` to `''`.

With this change, double expansion always works properly. When
double-expanding a multi-valued variable, in a double-quoted string the
first word of the inner expansion is used for the outer expansion, and
outside of a quoted string every word is used for the double-expansion
in each of the arguments.

    > set -l foo bar baz
    > set -l bar one two
    > set -l baz three four
    > echo "$$foo"
    one two baz
    > echo $$foo
    one two three four
2014-08-20 21:45:07 -07:00
ridiculousfish
d0c85471b4 Make escape_string transform wildcard characters
The characters ANY_CHAR, ANY_STRING, and ANY_STRING_RECURSIVE are
currently transformed by unescape, but not by escape. Let's try escaping
them. Fixes #1614.
2014-08-16 19:25:36 -07:00
ridiculousfish
06400b83b1 Support for command wrapping ("aliases")
Add the --wraps option to 'complete' and 'function'. This allows a
command to (recursively) inherit the completions of a wrapped command.
Fixes #393.

When evaluating a completion, we inspect the entire "wrap chain" for a
command, i.e. we follow the sequence of wrapping until we either hit a
loop (which we silently ignore) or the end of the chain. We then
evaluate completions as if the wrapping command were substituted with
the wrapped command. Currently this only works for commands, i.e.
'complete --command gco --wraps git\ checkout' won't work (that would
seem to encroaching on abbreviations anyways). It might be useful to
show an error message for that case.

The commandline builtin reflects the commandline with the wrapped
command substituted in, so e.g. git completions (which inspect the
command line) will just work. This sort of command line munging is
also performed by 'complete -C' so it's not totally without precedent.

'alias will also now mark its generated function as wrapping the
'target.
2014-08-15 18:14:36 -07:00
ridiculousfish
fe68d30be9 Use sgrep instead of grep in ssh completion 2014-08-13 01:06:15 -07:00
ridiculousfish
a3a11c2e0c Strip users with leading underscores from ssh completions 2014-08-12 14:46:59 -07:00
ridiculousfish
3f526698ab Make __fish_print_users work on OS X via dscl 2014-08-12 14:42:49 -07:00
ridiculousfish
6ce74febc7 Accepting an autosuggestion should clear the pager 2014-08-11 10:17:41 -07:00
ridiculousfish
ede3d422a0 Don't show "and 1 more rows" in pager if that requires a row 2014-08-11 09:55:07 -07:00
ridiculousfish
cb480dddf6 Don't try to colorize errors when running in Xcode 2014-08-04 13:55:53 -07:00
ridiculousfish
33c714ca03 Add fish_tests target to Xcode build
Allows running the tests in Xcode
2014-08-04 13:32:23 -07:00
Gio d'Amelio
bcda3f1baa Set $CMD_DURATION to milliseconds. Fixes #1585 2014-08-04 13:36:39 +08:00
David Adam
4ae2753025 Authenticate connections to web_config service
- Require all requests to use a session path.
 - Use a redirect file to avoid exposing the '/start' URL on the
   command line, as it contains the cookie value.

Fix for CVE-2014-2914.
Closes #1438.
2014-08-04 13:34:26 +08:00
David Adam
8844f0c142 Clarify I/O redirection documentation
Fix the examples and try and improve the clarity of the section.

Closes #1409.
2014-08-03 18:54:10 +08:00
David Adam
6cabd42ed2 Remove getpeerid/getpeerucred and fallbacks 2014-08-03 15:40:44 +08:00
ridiculousfish
0daee33ad6 Document new fish_title behavior per #334 2014-08-03 00:00:26 -07:00
ridiculousfish
b97a94ccc8 Clean up reader_write_title to work with wcstring 2014-08-02 21:01:40 -07:00
jianjun
87abcecca6 add command line string as $argv[1] for fish_title 2014-08-02 12:57:38 -07:00
Kevin Stone
556680cf5e Update grunt.fish
Fixed command error when no local Gruntfile results in a command error.

Fixes #1592.
2014-08-02 00:04:26 -07:00
ridiculousfish
35ba97cbdf Fix up OSC / iTerm2 escape code parsing as part of #1565 2014-07-30 11:35:39 -07:00