Commit Graph

100 Commits

Author SHA1 Message Date
ridiculousfish
b6555a0dc4 Add print-rusage-self to fish
This adds an option --print-rusage-self to the fish executable. When set,
this option prints some getrusage stats to the console in a human-readable
way. This will be used by upcoming benchmarking support.
2019-04-10 14:33:45 -07:00
Aaron Gyes
dd9a26715d fcntl a little less
Setting O_CLOEXEC on closed file descriptors and getting E_BADF
should be faster than actually checking if an fd is open first.
2019-04-08 11:23:00 -07:00
Aaron Gyes
aaacdb89b6 Switches over to cstring from string.h. 2019-03-12 15:09:36 -07:00
Aaron Gyes
d5ac239f68 This commit changes wchar.h includes to cwchar, and uses std::
for everything it provides.
2019-03-12 15:09:36 -07:00
ridiculousfish
1a4bb50cd5 Combine status and pipestatus into statuses_t
In most places where we set one, we want to set both. Make this less
error-prone by combining them into a single type statuses_t.
2019-02-26 20:07:37 -08:00
ridiculousfish
4b292c777d Clean up and clarify reader_exit() 2019-02-24 13:24:03 -08:00
ridiculousfish
780b53ba73 Convert event_type_t to an enum class 2019-02-23 13:17:28 -08:00
Aaron Gyes
634e97a85e Remove unnecessary _NSGetExecutablePath declaration
We do this in common.cpp now, and are including dyld.h anyhow.
2019-02-10 16:47:05 -08:00
ridiculousfish
d3fa58d621 Cleanup common.h
Remove a bunch of headers, simplify lots of code, migrate it into .cpp files.

Debug build time improves by ~3 seconds on my Mac.
2019-02-03 18:22:38 -08:00
ridiculousfish
22d05dc18b Try once more to fix the Travis build 2019-02-02 17:45:21 -08:00
ridiculousfish
6ba0d4c88a Revert io_bufferfill_t stack
This reverts commit 88dc484858 onwards.
2019-02-02 17:53:40 -08:00
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