mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 12:23:09 +00:00
parent
5ae09c37a6
commit
5fc17dcc82
5 changed files with 24 additions and 24 deletions
|
@ -868,7 +868,7 @@ The user can change the settings of `fish` by changing the values of certain var
|
|||
|
||||
- `version`, the version of the currently running fish
|
||||
|
||||
- `SHLVL`, the level of nesting of shells
|
||||
- `shlvl`, the level of nesting of shells
|
||||
|
||||
- `COLUMNS` and `LINES`, the current size of the terminal in height and width. These values are only used by fish if the operating system does not report the size of the terminal. Both variables must be set in that case otherwise a default of 80x24 will be used. They are updated when the window size changes.
|
||||
|
||||
|
|
10
src/env.cpp
10
src/env.cpp
|
@ -862,7 +862,7 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
|||
wcstring(L"PWD"),
|
||||
wcstring(L"version") }) {
|
||||
env_read_only.emplace(std::move(k));
|
||||
// L"SHLVL" is readonly but will be inserted below after we increment it.
|
||||
// L"shlvl" is readonly but will be inserted below after we increment it.
|
||||
};
|
||||
|
||||
// Names of all dynamically calculated variables.
|
||||
|
@ -928,8 +928,8 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
|||
wcstring version = str2wcstring(get_fish_version());
|
||||
env_set_one(L"version", ENV_GLOBAL, version);
|
||||
|
||||
// Set up SHLVL variable.
|
||||
const auto shlvl_var = env_get(L"SHLVL");
|
||||
// Set up shlvl variable.
|
||||
const auto shlvl_var = env_get(L"shlvl");
|
||||
wcstring nshlvl_str = L"1";
|
||||
if (!shlvl_var.missing_or_empty()) {
|
||||
const wchar_t *end;
|
||||
|
@ -939,8 +939,8 @@ void env_init(const struct config_paths_t *paths /* or NULL */) {
|
|||
nshlvl_str = to_string<long>(shlvl_i + 1);
|
||||
}
|
||||
}
|
||||
env_set_one(L"SHLVL", ENV_GLOBAL | ENV_EXPORT, nshlvl_str);
|
||||
env_read_only.emplace(L"SHLVL");
|
||||
env_set_one(L"shlvl", ENV_GLOBAL | ENV_EXPORT, nshlvl_str);
|
||||
env_read_only.emplace(L"shlvl");
|
||||
|
||||
// Set up the HOME variable.
|
||||
// Unlike $USER, it doesn't seem that `su`s pass this along
|
||||
|
|
|
@ -375,8 +375,8 @@ void internal_exec(job_t *j, const io_chain_t &&all_ios) {
|
|||
// commands in the pipeline will apply to exec. However, using exec in a pipeline doesn't
|
||||
// really make sense, so I'm not trying to fix it here.
|
||||
if (!setup_child_process(0, all_ios)) {
|
||||
// Decrement SHLVL as we're removing ourselves from the shell "stack".
|
||||
auto shlvl_var = env_get(L"SHLVL", ENV_GLOBAL | ENV_EXPORT);
|
||||
// Decrement shlvl as we're removing ourselves from the shell "stack".
|
||||
auto shlvl_var = env_get(L"shlvl", ENV_GLOBAL | ENV_EXPORT);
|
||||
wcstring shlvl_str = L"0";
|
||||
if (shlvl_var) {
|
||||
long shlvl = fish_wcstol(shlvl_var->as_string().c_str());
|
||||
|
@ -384,7 +384,7 @@ void internal_exec(job_t *j, const io_chain_t &&all_ios) {
|
|||
shlvl_str = to_string<long>(shlvl - 1);
|
||||
}
|
||||
}
|
||||
env_set_one(L"SHLVL", ENV_GLOBAL | ENV_EXPORT, shlvl_str);
|
||||
env_set_one(L"shlvl", ENV_GLOBAL | ENV_EXPORT, shlvl_str);
|
||||
|
||||
// launch_process _never_ returns.
|
||||
launch_process_nofork(j->processes.front().get());
|
||||
|
|
|
@ -285,16 +285,16 @@ set -q testu
|
|||
or echo testu undef in top level shell
|
||||
../test/root/bin/fish -c 'set -q testu; or echo testu undef in sub shell'
|
||||
|
||||
# test SHLVL
|
||||
# test shlvl
|
||||
# use a subshell to ensure a clean slate
|
||||
env SHLVL= ../test/root/bin/fish -c 'echo SHLVL: $SHLVL; ../test/root/bin/fish -c \'echo SHLVL: $SHLVL\''
|
||||
# exec should decrement SHLVL
|
||||
env SHLVL= ../test/root/bin/fish -c 'echo SHLVL: $SHLVL; exec ../test/root/bin/fish -c \'echo SHLVL: $SHLVL\''
|
||||
# garbage SHLVLs should be treated as garbage
|
||||
env SHLVL=3foo ../test/root/bin/fish -c 'echo SHLVL: $SHLVL'
|
||||
env shlvl= ../test/root/bin/fish -c 'echo shlvl: $shlvl; ../test/root/bin/fish -c \'echo shlvl: $shlvl\''
|
||||
# exec should decrement shlvl
|
||||
env shlvl= ../test/root/bin/fish -c 'echo shlvl: $shlvl; exec ../test/root/bin/fish -c \'echo shlvl: $shlvl\''
|
||||
# garbage shlvls should be treated as garbage
|
||||
env shlvl=3foo ../test/root/bin/fish -c 'echo shlvl: $shlvl'
|
||||
# whitespace is allowed though (for bash compatibility)
|
||||
env SHLVL="3 " ../test/root/bin/fish -c 'echo SHLVL: $SHLVL'
|
||||
env SHLVL=" 3" ../test/root/bin/fish -c 'echo SHLVL: $SHLVL'
|
||||
env shlvl="3 " ../test/root/bin/fish -c 'echo shlvl: $shlvl'
|
||||
env shlvl=" 3" ../test/root/bin/fish -c 'echo shlvl: $shlvl'
|
||||
|
||||
# Test transformation of inherited variables
|
||||
env DISPLAY="localhost:0.0" ../test/root/bin/fish -c 'echo Elements in DISPLAY: (count $DISPLAY)'
|
||||
|
|
|
@ -33,13 +33,13 @@ Testing Universal Startup
|
|||
2
|
||||
testu undef in top level shell
|
||||
testu undef in sub shell
|
||||
SHLVL: 1
|
||||
SHLVL: 2
|
||||
SHLVL: 1
|
||||
SHLVL: 1
|
||||
SHLVL: 1
|
||||
SHLVL: 4
|
||||
SHLVL: 4
|
||||
shlvl: 1
|
||||
shlvl: 2
|
||||
shlvl: 1
|
||||
shlvl: 1
|
||||
shlvl: 1
|
||||
shlvl: 4
|
||||
shlvl: 4
|
||||
Elements in DISPLAY: 1
|
||||
Elements in FOO: 4
|
||||
MANPATH=man1:man2:man3
|
||||
|
|
Loading…
Reference in a new issue