Commit Graph

67 Commits

Author SHA1 Message Date
ridiculousfish
8a96f283ba Allow setting feature flags on the command line
This introduces a new command line option --features which can be used for
enabling or disabling features for a particular fish session.

Examples:
  fish --features stderr-nocaret
  fish --features 3.0,no-stderr-nocaret
  fish --features all

Note that the feature set cannot be changed in an existing session.
2018-05-06 11:20:14 -07:00
Mahmoud Al-Qudsi
5a561bcfce Source : function without any C++ hacks
Thanks, @faho
2018-03-15 18:19:08 -05:00
Mahmoud Al-Qudsi
3996e437b6 Autoload : function on startup.
The newly added `:` command is implemented as a function (to avoid
increasing complexity by making it a builtin), but it is saved to a path
that does not match its filename (since its name is somewhat of a
special character that might cause problems during installation).
Directly probing the `colon` function for autoload causes `:` to be
correctly loaded, so doing just that after function paths are loaded
upon startup.

This is a hack since the CPP code shouldn't really be aware of
individual functions, perhaps there is a better way of doing this.
2018-03-14 18:22:10 -05:00
Fabian Homborg
b67a614d86 Replace the process-exit event with generic "fish_exit" event
Turns out the process-exit is only ever used in conjunction with
`%self`. Make that explicit by just adding a new "fish_exit" event,
and deprecate the general process-exit machinery.

Fixes #4700.
2018-02-19 20:21:02 +01: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
Mahmoud Al-Qudsi
e76c1fd139 Remove custom lock types in favor of native C++11 mutexes
No longer using RAII wrappers around pthread_mutex_t and pthread_cond_t
in favor of the C++11 std::mutex, std::recursive_mutex, and
std::condition_variable data types.
2017-08-18 23:09:31 -05:00
Kurtis Rader
f872f25f5b change env_var_t to a vector of strings
Internally fish should store vars as a vector of elements. The current
flat string representation is a holdover from when the code was written
in C.

Fixes #4200
2017-08-18 16:24:30 -07:00
Kurtis Rader
58b604c5ba change order of env_set() args
It's bugged me forever that the scope is the second arg to `env_get()`
but not `env_set()`. And since I'll be introducing some helper functions
that wrap `env_set()` now is a good time to change the order of its
arguments.
2017-08-14 18:18:09 -07:00
Kurtis Rader
82b5ba1af4 fix bug in env_get() involving empty vars
My previous change to eliminate `class var_entry_t` caused me to notice
that `env_get()` turned a set but empty var into a missing var. Which
is wrong. Fixing that brought to light several other pieces of code that
were wrong as a consequence of the aforementioned bug.

Another step to fixing issue #4200.
2017-08-14 18:18:09 -07:00
Kurtis Rader
52d739c746 Revert "Revert "finish cleanup of signal blocking code""
This reverts commit 35ee28ff24.

Reapply the signal blocking cleanup change on top of the job control
changes made by @mqudsi.
2017-08-06 14:46:12 -07:00
Kurtis Rader
35ee28ff24 Revert "finish cleanup of signal blocking code"
This reverts commit fb08fe5f47.

Needed to cleanly apply PR#4268. Will reapply after applying that
change.
2017-08-06 14:38:25 -07:00
Kurtis Rader
fb08fe5f47 finish cleanup of signal blocking code
PR #3691 made most calls to `signal_block()` and `signal_unblock()`
no-ops unless a magic env var is set when fish starts running. It's
been seven months since that change was made and no problems have been
reported. This finishes that work by removing those no-op function calls
and support for the magic env var in our next major release (which won't
happen till at least six months from now).
2017-07-26 13:51:00 -07:00
Kurtis Rader
0dc92fbb2d a make style-all cleanup 2017-07-18 22:40:25 -07:00
Kurtis Rader
a9aa234a64 implement helper functions for fish script vars
This is the first step in implementing a better abstraction for handling
fish script vars in the C++ code. It implements a new function (with two
signatures) to provide a standard method for construct the flag string
representation of a fish script array.

Partial fix for #4200
2017-07-08 13:14:30 -07:00
Kurtis Rader
f3d025bd75 always define argv for scripts
Found when testing what breaks when dereferencing undefined vars is an
errors (#4163).

Fixes #4181
2017-07-03 16:58:14 -07:00
Charles Ferguson
053d940d0a Add '--init-command', '-C' to the command line switches.
In order to allow the execution of commands before dropping to an
interactive prompt, a new switch, '-C' or '--init-command' has been
added to those switches that we accept.

The documentation has been updated correspondingly.

The original code only supported a single command list to be executed,
and this command list terminates the shell when it completes. To allow
the new command list to preceed the original one, both have been
wrapped in a new container class 'command_line_switches_t'. This is
then passed around in place of the list of strings we used previously.

I had considered moving the interactive, login and other command line
switch states into this container, but doing so would change far more
of the code, moving the structure to be available globally, and I
wasn't confident of the impact. However, this might be a useful thing
to do in the future.

A new function, run_command_list, was lifted from the prior execution
code, and re-used for both the initial command and the regular command
execution.
2017-06-29 20:59:58 -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
5e94650645 more wgetopt cleanup 2017-06-10 12:30:36 -07:00
Kurtis Rader
4c38867768 another step in fixing issue #3985
This primarily replaces "STATUS_BUILTIN_OK" with "STATUS_CMD_OK" and
"STATUS_BUILTIN_ERROR" with "STATUS_CMD_ERROR". That is because we want
to make it clear these status codes are applicable to fish functions as
well as builtins. Future changes will make it easier to use these
symbols and values in functions.
2017-05-04 00:18:02 -07:00
Kurtis Rader
107127afb7 ensure no signals are blocked when started
Fixes #3964
2017-05-02 21:02:42 -07:00
Kurtis Rader
e0f62c178f make not blocking signals the default
This is the next step in determining whether we can disable blocking
signals without a good reason to do so. This makes not blocking signals
the default behavior. If someone finds a problem they can add this to
their ~/config/fish/config.fish file:

set FISH_NO_SIGNAL_BLOCK 0

Alternatively set that env var before starting fish. I won't be surprised
if people report problems. Till now we have relied on people opting in
to this behavior to tell us whether it causes problems. This makes the
experimental behavior the default that has to be opted out of. This will
give us a lot more confidence this change doesn't cause problems before
the next minor release.

Note that there are still a few places where we force blocking of
signals. Primarily to keep SIGTSTP from interfering with the shell in
response to manipulating the controlling tty. Bash is more selective
in the signals it blocks around the problematic syscalls (c.f., its
`git_terminal_to()` function). However, I don't see any value in that
refinement.
2017-03-10 21:34:24 -08:00
Kurtis Rader
6d02bec4c7 fix setting up and using the terminfo data
There should be just one place that calls `setupterm()`. While refactoring
the code I also decided to not make initializing the curses subsystem a
fatal error. We now try two fallback terminal names ("ansi" and "dumb")
and if those can't be used we still end up with a usable shell.

Fixes #3850
2017-03-08 20:54:37 -08:00
Kurtis Rader
ea9e05568e Revert "make not blocking signals the default"
This reverts commit e30f3fee88.

Not sure why I didn't notice this before merging it but the change I'm
reverting makes it impossible to start a login shell.
2017-02-25 21:06:30 -08:00
Kurtis Rader
e30f3fee88 make not blocking signals the default
This is the next step in determining whether we can disable blocking
signals without a good reason to do so. This makes not blocking signals
the default behavior. If someone finds a problem they can add this to
their ~/config/fish/config.fish file:

set FISH_NO_SIGNAL_BLOCK 0

Alternatively set that env var before starting fish. I won't be surprised
if people report problems. Till now we have relied on people opting in
to this behavior to tell us whether it causes problems. This makes the
experimental behavior the default that has to be opted out of. This will
give is a lot more confidence this change doesn't cause major problems
prior to the next minor release.
2017-02-22 21:53:49 -08: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
69731f6642 more IWYU fixes
I'm starting to wonder if IWYU is worth the effort. Nonetheless, this
makes it lint clean on macOS and reduces the number of warnings on
FreeBSD and Linux.
2017-02-12 20:36:37 -08:00
Kurtis Rader
af7f5f42b6 put upper bound on data read will consume
This puts a hard upper bound of 10 MiB on the amount of data that read
will consume. This is to avoid having the shell consume an unreasonable
amount of memory, possibly causing the system to enter a OOM condition,
if the user does something non-sensical.

Fixes #3712
2017-02-09 21:04:46 -08:00
Kurtis Rader
616d301083 set stdout to unbuffered if attached to a tty
Fixes #3748
2017-02-07 21:01:22 -08:00
Kurtis Rader
fd6d814ea4 remove unnecessary signal management
The shell was doing a log of signal blocking/unblocking that hurts
performance and can be avoided. This reduced the elapsed time for a
simple benchmark by 25%.

Partial fix for #2007
2017-01-14 20:51:54 -08:00
David Adam
5eaccf91e2 drop check for old running fishd instances
Closes #3669.

Reverts commit d1a56139e1.
2017-01-11 19:34:32 +08:00
Kurtis Rader
521546a986 fix some lint warnings
This fixes some of the IWYU and cppcheck lint warnings. And only on
macOS (formerly OS X). Fixing these types of warnings on a broader set
of platforms should be done but this is a baby step to making `make
lint-all` have few, if any, warnings. This reduces the number of lines
in the `make lint-all` output on macOS by over 500 lines.
2016-11-15 21:15:22 -08:00
Kurtis Rader
4f4d34e664 lint: missing break in switch statement 2016-11-02 14:07:12 -07:00
Kurtis Rader
f6047f02d6 lint: constant conditional operator 2016-11-01 21:19:34 -07:00
Kurtis Rader
d389b22afc make style-all C++ style cleanup
It's time once again to run `make style-all` to fix some style bogosities
that have crept in.
2016-10-04 20:06:14 -07:00
Aaron Gyes
c2a8de4873 Make fish find config directories in source tree
If one does a make fish; ./fish - don't use the make-installed paths.

Also, remove huge chunk of nearly duplicated code #ifdef'd __APPLE__
for relocatable dirs in fish.app: the directories under Resources
in the bundle followed by the changes I made around here a few months
ago now are not different enough that they require a special case.
This works fine for fish.app.
2016-09-23 11:52:51 -07:00
Aaron Gyes
503edf2d49 Report exec_path and the final config paths via debug()
I was surprised fish_indent was running from /usr/local/bin
instead of the git checkout when I ran ./fish
after building fish there. This was more easily noticable after my last
commit. I added some debug lines which probably fish could have been
doing already when looking into that.

This is a pretty major thing during fish initialization, commit it for
everyone.
2016-09-23 08:55:26 -07:00
Kurtis Rader
3a08a24259 remove diagnostic no one likes 2016-07-28 16:15:58 -07:00
Kurtis Rader
375de96016 deal with missing argv
A user reported that fish was dying from a SIGSEGV when launched by the
sjterm terminal app. This was traced to a bug in sjterm passing an empty
argv array to the shell. Which, while technically legal, is very unusual
and a bad practice.

Fixes #3269
2016-07-27 16:38:18 -07:00
Aaron Gyes
3d8e8a8715 Fix when fish isn't already installed
This was still wrong.
2016-07-01 04:34:04 -07:00
Aaron Gyes
af0f9e5308 Mispelling - surprised it didn't care. 2016-07-01 04:27:24 -07:00
Aaron Gyes
63120a9962 Fix fish_config in .app
* Copy docs into Resrouces
* Export $__fish_bin_dir
* Fix incorrect path in fish.cpp - fish is not in MacOS (it should be!)
2016-07-01 03:57:16 -07:00
Aaron Gyes
a6ec2dc3ed Remove oopsies while pasting.
(also, last commit log had a typo. "3.4.0-Microsoft" is the string we
should check for. Actual string in my code was correct.)
2016-06-25 01:10:58 -07:00
Aaron Gyes
6ec83568b5 Check for "Windows-3.4.0" as per MS's suggestion.
https://github.com/Microsoft/BashOnWindows/issues/545

Just looking for "Mirosoft" is rather general - we don't want to
enforce this strange behavior for Windows 12 (or the next beta.)
2016-06-25 00:31:46 -07:00
Aaron Gyes
fa78a7101c Make IWYU output in lint.cpp less messy
And re-run IWYU, adjust #includes.
2016-06-23 17:26:08 -07:00
Kurtis Rader
8e21d5de92 deal with broken ttys on MS Windows
The tty device timestamps on MS Windows aren't usable because they're always
the current time. So fish can't use them to decide if the entire prompt needs
to be repainted.

Fixes #2859
2016-06-18 19:33:54 -07:00
Aaron Gyes
9f0c31611c Lint Cleanup
This remove some stores that clang assures me are very dead.

And an assert() for an unlikely NULL pointer dereference I can't quite
figure out.
2016-06-14 19:27:00 -07:00
Kurtis Rader
0b385f145c simplify, and fix, setting the current locale
Fix test setup bogosities. Specifically, they weren't hermetic with respect to
locale env vars.

Rewrite the handling of locale vars to simplify the code and make it more like
the pattern most programs employ.

Fixes #3110
2016-06-05 15:49:34 -07:00
Kurtis Rader
73f2992a2e make debug() output more useful
This change does several things. First, and most important, it allows
dumping the "n" most recent stack frames on each debug() call. Second,
it demangles the C++ symbols. Third, it prepends each debug() message
with the debug level.

Unrelated to the above I've replaced all `assert(!is_forked_child());`
statements with `ASSERT_IS_NOT_FORKED_CHILD()` for consistency.
2016-05-17 14:52:55 -07:00
Kurtis Rader
bc6cc4c105 fix fork debug printf() calls
The fork (create new process) related debugging messages rely on an
undocumented env var and use `printf()` rather than `debug()`. There are
also errors in how the fork count is tracked that this fixes.

Fixes #2995
2016-05-05 20:22:20 -07:00
Kurtis Rader
075811e588 restyle fish modules to match project style
Reduces lint errors from 60 to 60 (-0%). Line count from 5599 to 4925 (-12%).

Another step in resolving issue #2902.
2016-04-30 19:52:13 -07:00