Commit Graph

89 Commits

Author SHA1 Message Date
Fabian Homborg
38b4d47560 Initialize empty_ios emptier
This placates the compiler.

The compiler is pleased.
2019-02-03 00:14:03 +01:00
ridiculousfish
3b1709180f Instantize env_get 2019-01-10 20:07:53 -08:00
ridiculousfish
c1dd284b3e Instantize env_set
Switch env_set to an instance method on environmnet_t.
2019-01-10 20:05:45 -08:00
ridiculousfish
895c2c4af0 Minor cleanup of parser interface 2019-01-10 20:29:10 -08:00
Stephen M. Coakley
d776a366fa Pass final Fish exit status to fish_exit event
For fish_exit to be a suitable replacement for --on-process-exit, we need to be able to provide scripts with access to the shell's final exit code.
2019-01-05 21:27:13 +01:00
Aaron Gyes
fe67cc4f6e Revert "Show how fish was executed, using argv[0] for program_name"
This reverts commit 1cb8b2a87b.

argv[0] has the full path in it for a user when he executes it
out of $PATH. This is really annoying in the title which uses $_.
2018-11-28 06:08:24 -08:00
Aaron Gyes
dd582abcc5 Revert "argv: don't reassign parameters"
This reverts commit ba455c81b4.
2018-11-28 06:07:58 -08:00
Aaron Gyes
ba455c81b4 argv: don't reassign parameters
OCLINT was ignoring this, but we can just not do the bad thing.
Declare argc and argv const. These are in the stack, they can
be modified, but we won't.

Fix a typo
2018-11-27 13:27:21 -08:00
Aaron Gyes
1cb8b2a87b Show how fish was executed, using argv[0] for program_name
... rather than hard code it to "fish". This affects
what is found in $_ and improves the errors:

For example, if fish was ran with ./fish, instead of
something like:

  fish: Expected 3 surprises, only got 2 surprises

we'll see:

 ./fish: Expected 3 surprises, only got 2 surprises

like most other shell utilities. It's just a tiny bit
of detail that can avoid confusion.
2018-11-27 11:57:09 -08:00
Aaron Gyes
9e7034c903 fish.cpp: Dirs relative to CMAKE_SOURCE_DIR, don't assume 'fish'
This was causing problems if "fish" wasn't in exec_path, like
if the binary had been renamed.

I also noticed that even with 'fish' not renamed, only paths.data
was made relative to my source tree. paths.sysconf, paths.doc, and
paths.bin were all relative to /usr/local.
2018-11-25 14:37:12 -08:00
Mahmoud Al-Qudsi
379f44fabe Add a --private option to launch fish in private mode
In private mode, access to previous history is blocked and new history
does not persist and is only available for the duration of the current
session.

This mode can be used when it is not desirable for commandline history
to leak into a session, e.g. via autocomplete or when it is desirable to
test the behavior of fish in the absence of history items without
permanently clearing the history.

I'm sure there are a lot more features that can be incorporated into
private mode, such as restricting access to certain user-specific
configuration files, etc.

This addresses a lot of the concerns raised in #1363 (which was later
changed to track mosh-specific problems). See also #102.
2018-10-24 19:33:48 +02:00
Mahmoud Al-Qudsi
6bc59db721 Detect when running out of cmake build directory
Load fish docs and configuration out of the source and/or build
directories rather from the installed paths when running directly out
of the cmake build directory.

Closes #5255.
2018-10-13 21:48:28 -05:00
Mahmoud Al-Qudsi
e212269ab1 Add status fish-path
Retrieves the fully resolved path to the currently executing fish binary
(regardless of PATH). Can be used to ensure that the same fish is
launched again from a script.

`get_executable_path()` moved from fish binary to libfish, also cleaned
up some duplicated (but differing!) definitions of PATH_MAX (which was
used by that function) in the process.
2018-10-09 22:34:41 -05:00
Mahmoud Al-Qudsi
236556ba05 Update get_executable_path() for FreeBSD
Remove dependency on the Linux compatibility layer's procfs being
installed and mounted when running under FreeBSD by directly querying
the MIB for the path to the running fish executable
(KERN_PROC_PATHNAME). Tested under FreeBSD 11.2-RELEASE.
2018-10-09 19:47:49 -05:00
ridiculousfish
20cb62440c Eliminate some mutable global variables
Make them const or otherwise get rid of them
2018-09-29 00:20:50 -04:00
ridiculousfish
a17a815c87 Revert "Add vector of cleanup/termination events to be executed before quit"
This reverts commit 8c14f0f30f.

This list is not reliable - there are many ways for fish to quit that does not
invoke these functions. It's also not necessary since the history is correctly
saved on exec.
2018-09-28 20:21:23 -04:00
ridiculousfish
a389ca694c Revert "Save history on exec"
This reverts commit 9d0050023c.

This change was not necessary. History is already saved on exec().
2018-09-28 20:20:54 -04:00
Mahmoud Al-Qudsi
9d0050023c Save history on exec
See https://github.com/fish-shell/fish-shell/issues/907

May not fully resolve the issue, needs to be tested before #907 can be closed.
2018-09-28 11:34:07 -05:00
Mahmoud Al-Qudsi
8c14f0f30f Add vector of cleanup/termination events to be executed before quit 2018-09-28 11:34:07 -05:00
ridiculousfish
7af3adc344 Revert "Don't require ./etc to exist in relocatable fish"
This reverts commit e2a3dae58b.

This idea failed because ./share was not complete when bliding via cmake;
it misses critical files such as config.fish.
2018-07-21 20:57:21 -07:00
ridiculousfish
e2a3dae58b Don't require ./etc to exist in relocatable fish
fish tries to be relocatable by looking for directories relative to its
executable. These directories are not found when running fish from
within a cmake build because the etc directory is not present. Stop requiring
this directory to be present since it's not critical for running fish.

Fixes #4825
2018-07-21 16:47:00 -07:00
ridiculousfish
d3201ad887 Set features from the environment
This enables users to opt in (or out) of specific features by setting
the fish_features environment variable.

For example `set -U fish_features stderr-nocaret` to opt into removing the
caret redirection.
2018-05-06 11:20:14 -07:00
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