Commit Graph

43 Commits

Author SHA1 Message Date
Soumya
8dd2d4f15d Change builtins to return maybe_t<int> instead of int 2020-08-05 12:23:49 -07:00
Rosen Penev
fee08a87e9 [cppcheck] add const in several places
Found with constParameter, functionConst, constVariable, constArgument

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-03-14 15:07:54 -07:00
ridiculousfish
8d8bcb7d8a Stop acquiring the terminal before running builtins
fish has some unprincipled code that attempts to tcsetpgrp() to own the
terminal before running a builtin; this was added because 'read' might
want to read from the terminal. I added this code before fully
understanding how process groups and terminals work. A better fix would
be to ensure that fish is marked as the pgroup leader in the job when
the builtin is the first process in the job, and we do that now.

Courageously back out the changes to grab the terminal; see #5147 and
also #5133.
2020-01-31 10:42:21 -08:00
ridiculousfish
4bb18eaf42 Use completion_list_t naming everywhere
std::vector<completion_t> -> completion_list_t
2020-01-16 15:18:49 -08:00
Johannes Altmanninger
75fa3b6bae unbreak missing argument error on long option 2020-01-08 17:33:36 +01:00
Rosen Penev
5ca80a61e3 [clang-tidy] Fix inconsistent declarations
Found with readability-inconsistent-declaration-parameter-name

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2019-11-25 14:13:33 -08:00
Johannes Altmanninger
61486954bc Use a pager to view long outputs of builtin --help
Every builtin or function shipped with fish supports flag -h or --help to
print a slightly condensed version of its manpage.
Some of those help messages are longer than a typical screen;
this commit pipes the help to a pager to make it easier to read.

As in other places in fish we assume that either $PAGER or "less" is a
valid pager and use that.

In three places (error messages for bg, break and continue) the help is
printed to stderr instead of stdout.  To make sure the error message is
visible in the pager, we pass it to builtin_print_help, every call of which
needs to be updated.

Fixes #6227
2019-10-28 18:36:07 +01:00
LawAbidingCactus
305a657694 fix typos 2019-10-23 19:38:44 +02:00
Aaron Gyes
61f0756fe6 builtins: Use standard builtin.h error macros more 2019-09-17 22:04:33 -07:00
ridiculousfish
1baa479bbf Eliminate the global list of scoped transient commandlines
Store this in a parser's libdata instead.
2019-06-09 14:11:25 -07:00
Fabian Homborg
88d2d54276 Stop printing help summary on error
This now displays

- the error message

- a (significantly shorter) backtrace

- A call to open `help $cmd` if necessary

See #5434.
Fixes #3404.
2019-03-26 19:24:48 +01:00
Aaron Gyes
d837eee09d remove some wcstring -> wchar_t* -> wcstring conversions
Mostly related to usage _(L"foo"), keeping in mind the _
macro does a wcstring().c_str() already.

And a smattering of other trivial micro-optimizations certain
to not help tangibly.
2019-03-14 15:21:08 -07:00
ridiculousfish
bb36274e6b Introduce proc_status_t
In fish we play fast and loose with status codes as set directly (e.g. on
failed redirections), vs status codes returned from waitpid(), versus the
value $status. Introduce a new value type proc_status_t to encapsulate
this logic.
2019-02-25 10:14:45 -08:00
ridiculousfish
96da62ea87 Revert "Convert list of builtins from sorted array to unordered_set"
This reverts commit d8a1928c24.

It is better to have builtins as static const data to avoid unnecessary
initialization and allocation during startup.
2018-09-29 00:22:24 -04:00
ridiculousfish
d9f34147c3 builtins to only acquire terminal if owned by their pgroup
Fix #5133 changed builtins to acquire the terminal, but this regressed
caused fish to be stopped when running in background via `sudo fish`.
Fix this by only acquiring the terminal if the terminal was owned by the
builtin's pgroup.

Fixes #5147
2018-08-18 16:56:01 -07:00
ridiculousfish
acff2516d4 Straighten out some wchar_t** casts
Embrace the fact that builtins expect to modify their argv array and get rid
of a bunch of const.
2018-08-04 16:25:51 -07:00
Mahmoud Al-Qudsi
d8a1928c24 Convert list of builtins from sorted array to unordered_set
The order of this list does not need to be strictly maintained any
longer.

Benchmarked with `hyperfine` as follows, where `bench1` is the existing
approach of binary search and `bench2` is the new unordered_set code,
(executed under bash because fish would always return non-zero). The
benchmark code checks each argv to see if it is a builtin keyword (both
return the same result):

```
hyperfine './bench1 $(shuf /usr/share/dict/words)' './bench2 $(shuf /usr/share/dict/words)'
Benchmark #1: ./bench1 $(shuf /usr/share/dict/words)

  Time (mean ± σ):      68.4 ms ±   3.0 ms    [User: 28.8 ms, System: 38.9 ms]

  Range (min … max):    60.4 ms …  75.4 ms

Benchmark #2: ./bench2 $(shuf /usr/share/dict/words)

  Time (mean ± σ):      61.4 ms ±   2.3 ms    [User: 23.1 ms, System: 39.8 ms]

  Range (min … max):    58.1 ms …  67.1 ms

Summary

'./bench2 $(shuf /usr/share/dict/words)' ran
    1.11x faster than './bench1 $(shuf /usr/share/dict/words)'
```
2018-04-03 15:47:21 -05:00
ridiculousfish
ba7b8a9584 Remove various empty or useless functions
In particular remove init()/destroy() functions that do nothing, or
destroy functions that only free memory.
2018-02-10 17:21:55 -08:00
Kurtis Rader
4a7aa98e93 modify read to require at least one var
Fixes #4220
2017-07-20 13:07:30 -07:00
Kurtis Rader
9adf500cf3 implement argparse --max-args N --min-args N
Fixes #4190
2017-07-12 22:38:32 -07:00
Kurtis Rader
c6093ad782 make read honor FISH_HISTORY
The `read` command `-m` and `--mode-name` vars are now deprecated and do
nothing other than result in a warning message. The `read` command now
honors the `FISH_HISTORY` var that is used to control where commands are
read from and written to. You can set that var to the empty string to
suppress the use of both history files. Or you can set it to a history
session ID in which case that will limit the `read` history that is
available.

Fixes #1504
2017-06-30 21:03:05 -07:00
Kurtis Rader
bd299e96b2 implement status is-breakpoint
This implements `status is-breakpoint` that returns true if the current
shell prompt is displayed in the context of a `breakpoint` command.

This also fixes several bugs. Most notably making `breakpoint` a no-op if
the shell isn't interactive. Also, typing `breakpoint` at an interactive
prompt should be an error rather than creating a new nested debugging
context.

Partial fix for #1310
2017-06-20 17:18:59 -07:00
Kurtis Rader
d22743dad0 change help only cmd opts interface 2017-06-16 21:01:57 -07:00
Kurtis Rader
37b8cfaeba avoid struct name clashes
Running the tests on travis revealed that some compilers (or at least
with some options) call the wrong struct constructor if there is more
than one struct with the same name but differing definitions.
2017-06-16 21:01:57 -07:00
Kurtis Rader
422b1bd066 split builtin bg into its own module 2017-06-16 21:01:56 -07:00
Kurtis Rader
f1d40a3c7c limit bind mode names to the rules for var names
The bind mode names can be, and are, used in the construction of fish
variable names. So don't allow users to use names that are not legal as
a variable name. This should not break anything since, AFAICT, no
existing fish scripts, including those provided by Oh-My-Fish and
Fisherman define bind modes that would not be legal with this change.

Fixes #3965
2017-04-22 20:33:56 -07:00
Kurtis Rader
275d658616 simplify and clarify valid identifiers
This is the first step in addressing issue #3965. It renames some of the
functions involved in validating variable and function names to clarify
their purpose. It also augments the documentation to make the rules for
such identifiers clearly documented.
2017-04-21 21:55:06 -07:00
Kurtis Rader
509ee64fc9 implement our own assert() function
I recently upgraded the software on my macOS server and was dismayed to
see that cppcheck reported a huge number of format string errors due to
mismatches between the format string and its arguments from calls to
`assert()`. It turns out they are due to the macOS header using `%lu`
for the line number which is obviously wrong since it is using the C
preprocessor `__LINE__` symbol which evaluates to a signed int.

I also noticed that the macOS implementation writes to stdout, rather
than stderr. It also uses `printf()` which can be a problem on some
platforms if the stream is already in wide mode which is the normal case
for fish.

So implement our own `assert()` implementation. This also eliminates
double-negative warnings that we get from some of our calls to
`assert()` on some platforms by oclint.

Also reimplement the `DIE()` macro in terms of our internal
implementation.

Rewrite `assert(0 && msg)` statements to `DIE(msg)` for clarity and to
eliminate oclint warnings about constant expressions.

Fixes #3276, albeit not in the fashion I originally envisioned.
2017-02-14 18:48:27 -08:00
Kurtis Rader
aad2848e80 use consistent mechanism to validate var names
Builtin commands that validate var names should use a consistent
mechanism. I noticed that builtin_read() had it's own custom code that
differed slightly from wcsvarname().

Fixes #3569
2016-11-22 16:18:20 -08:00
Kurtis Rader
c07c98ac05 eliminate many "unused parameter" warnings
Partially addresses issue #3430.
2016-10-09 14:38:26 -07:00
Aaron Gyes
9daffc7080 HeaderDoc code documentation improvements
Some cleanup too, move things to builtin.h from builtin.cpp that seem
to belong there.
2016-08-16 18:00:07 -07:00
Kurtis Rader
b53f42970c correct handling of history args
This fixes several problems with how the builtin `history` command handles
arguments. It now complains and refuses to do anything if the user specifies
incompatible actions (e.g., `--search` and `--clear`). It also fixes a
regression introduced by previous changes with regard to invocations that
don't explicitly specify `--search` or a search term.

Enhances the history man page to clarify the behavior of various options.

This change is already far larger than I like so unit tests will be added
in a separate commit.

Fixes #3224.

Note: This fixes only a couple problems with the interactive `history
--delete` command in the `history` function. The main problem will be
dealt with via issue #31.
2016-07-20 21:18:48 -07:00
Kurtis Rader
51468b7646 add function --shadow-builtin flag
It's currently too easy for someone to bork their shell by doing something
like `function test; return 0; end`. That's obviously a silly, contrived,
example but the point is that novice users who learn about functions are
prone to do something like that without realizing it will bork the shell. Even
expert users who know about the `test` builtin might forget that, say, `pwd`
is a builtin.

This change adds a `--shadow-builtin` flag that must be specified to
indicate you know what you're doing.

Fixes #3000
2016-05-14 20:38:32 -07:00
Kurtis Rader
1f06e5f0b9 add better support for IWYU and fix things
Remove the "make iwyu" build target. Move the functionality into the
recently introduced lint.fish script. Fix a lot, but not all, of the
include-what-you-use errors. Specifically, it fixes all of the IWYU errors
on my OS X server but only removes some of them on my Ubuntu 14.04 server.

Fixes #2957
2016-04-26 15:02:22 -07:00
Kurtis Rader
a10a79c6d0 restyle builtin module to match project style
Reduces lint errors from 271 to 215 (-21%). Line count from 4304 to 3242 (-25%).

Another step in resolving issue #2902.
2016-04-18 21:06:10 -07:00
ridiculousfish
10f3ea0008 Mark a bunch of constructors as explicit
This prevents undesired implicit conversions
2016-02-27 19:38:15 -08:00
ridiculousfish
c1bd3b5824 Eliminate global variables associated with builtin IO
This change eliminates global variables like stdout_buffer. Instead we wrap up
the IO information into a new struct io_streams_t, and thread that through
every builtin. This makes the intent clearer, gives us a place to hang new IO
data, and eliminates the ugly global state management like builtin_push_io.
2015-09-22 18:08:00 -07:00
ridiculousfish
025b45b91e Don't crash on complete -C in non-interactive mode
Fixes #2361
2015-09-10 18:08:42 -07:00
ridiculousfish
871a822379 Remove some dead #defines 2015-08-11 01:00:05 -07:00
David Adam
a6a16808e3 Merge branch 'iwyu'
http://include-what-you-use.org/
2015-07-29 09:30:19 +08:00
ridiculousfish
6e3231a9d7 Stop passing mutable references to completions around
Replace uses of vector<completion_t>& with vector<completion_t>*
This makes it clear at the call site that the object may be mutated.
2015-07-27 18:45:47 -07:00
David Adam
3929e9de0e Merge branch 'master' into iwyu 2015-07-26 10:20:13 +08:00
ridiculousfish
b4f53143b0 Migrate source files into src/ directory
This change moves source files into a src/ directory,
and puts object files into an obj/ directory. The Makefile
and xcode project are updated accordingly.

Fixes #1866
2015-07-24 00:59:27 -07:00