Commit graph

117 commits

Author SHA1 Message Date
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
ridiculousfish
52ae5f885e Improve history robustness against corrupt files
Fixes #1581
2014-07-29 14:42:03 -07:00
ridiculousfish
30ae473d85 Clean up default environment variables.
This stops unconditionally setting values for HOME and USER,
if we find those values in the environment. It also saves about 16KB
on OS X, which getpwuid allocates.
2014-07-25 10:49:13 -07:00
ridiculousfish
7def139020 Turn the 'mode' parameter of environment variables into an enum 2014-07-13 17:30:48 -07:00
Kevin Ballard
7b12fd26f3 Change how we separate toplevel and global scopes
Instead of introducing a new local scope at the point of `set`, merely
push a new local scope at the end of env_init(). This means we have a
single toplevel local scope across the lifetime of the fish process,
which means that

    set -l foo bar
    echo $foo

behaves as expected, without modifying the global environment.
2014-07-13 13:21:06 -07:00
Kevin Ballard
dcc043df3b Add an optional mode to env_get_string()
The mode restricts the scope in which the variable is searched for.

Use this new restricted scope functionality in the `set` builtin. This
fixes `set -g` to not show local shadowing variable values, and also
allows for scoped erasing of slices.
2014-07-12 15:35:34 -07:00
Kevin Ballard
2457997cd9 set: Print an error when setting a special var in the wrong scope
When attempting to set a readonly or electric variable in the local or
universal scopes, print an appropriate error. Similarly, print an error
when setting an electric variable as exported. In most cases this is
simply a nicer error instead of the 'read-only' one, but for the 'umask'
variable it prevents `set -l umask 0023` from silently changing the
global value.
2014-07-12 14:07:55 -07:00
Kevin Ballard
d9bed68fe9 Mark COLUMNS/LINES as electric vars
They're dynamically calculated, so they qualify. This also removes them
from the list of exported global variables, because they're actually not
exported.
2014-07-12 14:07:55 -07:00
Kevin Ballard
2eb65b3625 set: Don't treat toplevel scope the same as global
When using the `set` command with the -l flag, if we're at the top
level, create a temporary local scope. This makes query/assignment
behavior be consistent with the value-printing behavior.

This works by marking the current block as needing to pop the
environment if a local scope was pushed. I assume this is safe to do. I
also assume the current block is the right one to modify, rather than
trying to walk up the stack to the root.
2014-07-12 14:07:55 -07:00
Kevin Ballard
76fdfe6890 Rewrite env_exists() for better scope handling
env_exists() wasn't properly handling multiple scopes in some cases,
notably with readonly/electric variables. Rewrite it to operate in a
more straightforward fashion.
2014-07-12 14:07:55 -07:00
Kevin Ballard
383aaa236e Don't allow readonly/electric values to come in through the env
When initializing fish, ignore any inherited environment variables that
match any of the readonly or electric variable names.

This prevents really weird behavior when e.g. fish is launched with
COLUMNS already set to something. In that case, testing $COLUMNS within
fish behaves normally, but any subprocesses get the value that fish
itself had inherited.
2014-07-12 00:53:23 -07:00
ridiculousfish
5cda1e55e0 Must load universal variables earlier, and issue a barrier after erasing
one.

Fixes #1526
2014-07-06 18:12:18 -07:00
David Adam
1cfd055f82 env.cpp: allow all users to change $USER and $HOME
Closes 1425 (https://github.com/fish-shell/fish-shell/issues/1425)
2014-06-28 19:16:29 +08:00
ridiculousfish
ee8e9c0291 Remove env_universal.h and env_universal.cpp from project 2014-06-18 10:14:35 -07:00
ridiculousfish
3513ce3ac0 Universal variable callbacks should only be announced for changed
values, not every value. Also support erase notifications.
2014-06-16 12:27:28 -07:00
ridiculousfish
6277a2e4a4 Migrate global functions out of env_universal. Have env operate directly
on an env_universal_t.
2014-06-15 17:30:50 -07:00
ridiculousfish
735195e8ea Teach env_universal_remove to directly report whether the variable was
successfully removed.
2014-06-13 15:15:11 -07:00
ridiculousfish
ef646f0f78 Removal of more fishd artifacts and headers 2014-06-09 12:07:40 -07:00
ridiculousfish
ecf56606dc Remove large parts of fishd interaction, including
env_universal_server
2014-06-06 10:34:42 -07:00
David Adam
3225d7e169 avoid symlink attacks in __fish_print_packages and spawning fishd
* use $XDG_CACHE_HOME for __fish_print_packages completion caches
 * when starting fishd, redirect fishd output to /dev/null, not a
   predictable path

Fix for CVE-2014-3219.

Closes #1440.
2014-05-12 09:30:05 +08:00
Konrad Borowski
f8e35de18d Shorten compilation times
Now fish shell stores version is a small file called by other files.
This means that a slight change which modifies one file won't cause
many of files to recompile.

The compilation unit is intentionally small, this is by design. The
smaller it is, the faster it will recompile, and it will be compiled
a lot.
2014-05-01 09:46:27 +02:00
ridiculousfish
a475dd15e6 Migrate universal variables to env_var_t structure. Encapsulate
universal variable storage into a class for better testability.
2014-04-25 16:09:26 -07:00
Julian Aron Prenner
cd64a777c3 Set $fish_bind_mode to default on fish startup; set $fish_key_bindings
when sourcing fish_vi_mode.fish
2014-01-19 10:27:39 +01:00
ridiculousfish
b2c78dbd57 Fix for issue where we compute a default USER variable, but never set
its value.
2014-01-12 13:42:26 -08:00
ridiculousfish
b34721b3f4 Miscellaneous optimizations to reduce string copying 2014-01-07 14:57:58 -08:00
ridiculousfish
85ce80d72e Stop insisting on trying to add /usr/bin and /bin to $PATH.
https://github.com/fish-shell/fish-shell/pull/854
2013-08-27 18:23:33 -07:00
David Adam (zanchey)
2a06c72113 Generate version numbers dynamically
This commit hooks the Makefile up to generate a FISH_BUILD_VERSION
symbol and kills off PACKAGE_VERSION in .cpp files.

It also modifies the tarball generation script to add the necessary
version file for releases.
2013-08-11 23:13:38 +08:00
ridiculousfish
c64a86efae Fix some warnings exposed by -Wall 2013-07-16 13:40:11 -07:00
Dag Odenhall
9f0775c873 Fix $LINES = $COLUMNS bug
Fixes #745
2013-05-24 23:23:29 -07:00
ridiculousfish
fe6699f0bf Rely on $PWD instead of getcwd() more often
Fixes https://github.com/fish-shell/fish-shell/issues/696
2013-04-27 00:45:38 -07:00
ridiculousfish
8bbd8ab073 Hack up dcgettext to try to fix CentOS build
https://github.com/fish-shell/fish-shell/issues/645
2013-04-08 12:02:43 -07:00
David Adam (zanchey)
daf5ef1bbd Kill termio.h and sys/termios.h
On FreeBSD, compilation complains that "this file includes
<sys/termios.h> which is deprecated, use <termios.h> instead". On Linux
and FreeBSD, <sys/termios.h> literally just pulls in <termios.h>. On OS
X and Solaris, <termios.h> pulls in <sys/termios.h>.

<termio.h> doesn't exist on FreeBSD or Mac OS X, and on Linux is marked
as deprecated and just includes <termios.h>. It does exist on Solaris,
but no `struct termio` is ever actually used in the codebase.
2013-03-05 12:25:00 -08:00
ridiculousfish
a8e92639af Cleanup and simplify null_terminated_array_t and its clients 2013-02-22 16:22:56 -08:00
ridiculousfish
fbedf020bc Null initialize an ivar (oops) 2013-02-19 23:16:44 -08:00
ridiculousfish
aaa0c25ff7 Large set of changes to how PATH is handled. Changed fish to no longer modify PATH in share/config.fish. Introduced variable fish_user_paths, and a glue function __fish_reconstruct_path that splices together PATH with fish_user_paths. Changed fish to no longer validate changes to PATH unless the paths are new (i.e. don't recheck what's already there). Modified certain sets to store const wchar_t instead of wcstring to save a few allocations.
https://github.com/fish-shell/fish-shell/issues/527
2013-02-19 18:05:20 -08:00
ridiculousfish
6d522e6ed6 First round of fixes based on cppcheck
https://github.com/fish-shell/fish-shell/issues/575
2013-02-16 00:02:40 -08:00
ridiculousfish
8d95d0834d First stab at builtin set_color. Moved set_color.cpp to builtin_set_color.cpp and taught fish about it. 2013-02-14 15:52:24 -08:00
Siteshwar Vashisht
694ab455cd Fixed broken export_func
Fix for https://github.com/fish-shell/fish-shell/issues/573
2013-02-12 13:50:43 +01:00
ridiculousfish
46edc07ae4 Clean up export_func 2013-02-12 00:14:27 -08:00
ridiculousfish
2a7fc9c3a5 Clean up env_var_table_t. Switch from storing var_uni_entry_t* to var_uni_entry_t. Various other cleanups. 2013-02-11 23:16:50 -08:00
Cheer Xiao
274f018494 Remove trailing whitespaces 2013-01-21 10:34:18 +08:00
ridiculousfish
6d61919941 Rearrange some variables for possibly better alignment. int -> bool 2013-01-19 13:32:12 -08:00
ridiculousfish
e07de09460 Big cleanup of env_set. Changed var_table_t to use direct var_entry_t instead of pointers. Changed some ints to bools. 2013-01-19 13:32:06 -08:00
Jan Kanis
9ee7b0a501 really fix bug in export status of universal vars; add tests for that bug 2013-01-02 23:31:30 -08:00
Jan Kanis
3c116f6ab3 fix bug in export status of universal variable assignment 2013-01-02 23:31:30 -08:00
ridiculousfish
705793eae6 Make fish more robust when multiple instances are started at once 2012-12-27 20:26:16 -08:00
ridiculousfish
8a66ba6c35 Merge branch 'event-bug-test' of git://github.com/JanKanis/fish-shell into JanKanis-event-bug-test 2012-12-22 12:20:41 -08:00
Jan Kanis
71233ee894 Make event_t.arguments into a vector instead of an auto_ptr<vector>.
Yay for less indirection and less code! The resulting event_t structure is two pointers larger, but cuts out an indirection and allocation.
2012-12-20 16:13:14 +01:00
ridiculousfish
644607c29f Eliminate str2wcs 2012-12-19 13:31:06 -08:00
ridiculousfish
26678682ca Fix indentation of switch statements 2012-11-19 00:31:03 -08:00