Skip to content

Commit

Permalink
Deprecate "." command. Fixes #310.
Browse files Browse the repository at this point in the history
Needs documentation (for the new name), but manages to move . to source,
while preserving compatibility.
  • Loading branch information
Konrad Borowski committed Aug 14, 2013
1 parent d407d68 commit 5818289
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 3 additions & 3 deletions builtin.cpp
Expand Up @@ -3014,15 +3014,15 @@ static int builtin_source(parser_t &parser, wchar_t ** argv)
if ((fd = wopen_cloexec(argv[1], O_RDONLY)) == -1)
{
append_format(stderr_buffer, _(L"%ls: Error encountered while sourcing file '%ls':\n"), argv[0], argv[1]);
builtin_wperror(L".");
builtin_wperror(L"source");
return STATUS_BUILTIN_ERROR;
}

if (fstat(fd, &buf) == -1)
{
close(fd);
append_format(stderr_buffer, _(L"%ls: Error encountered while sourcing file '%ls':\n"), argv[0], argv[1]);
builtin_wperror(L".");
builtin_wperror(L"source");
return STATUS_BUILTIN_ERROR;
}

Expand Down Expand Up @@ -3953,7 +3953,6 @@ static int builtin_history(parser_t &parser, wchar_t **argv)
*/
static const builtin_data_t builtin_datas[]=
{
{ L".", &builtin_source, N_(L"Evaluate contents of file") },
{ L"[", &builtin_test, N_(L"Test a condition") },
{ L"and", &builtin_generic, N_(L"Execute command if previous command suceeded") },
{ L"begin", &builtin_begin, N_(L"Create a block of code") },
Expand Down Expand Up @@ -3993,6 +3992,7 @@ static const builtin_data_t builtin_datas[]=
{ L"return", &builtin_return, N_(L"Stop the currently evaluated function") },
{ L"set", &builtin_set, N_(L"Handle environment variables") },
{ L"set_color", &builtin_set_color, N_(L"Set the terminal color") },
{ L"source", &builtin_source, N_(L"Evaluate contents of file") },
{ L"status", &builtin_status, N_(L"Return status information about fish") },
{ L"switch", &builtin_switch, N_(L"Conditionally execute a block of commands") },
{ L"test", &builtin_test, N_(L"Test a condition") },
Expand Down
6 changes: 3 additions & 3 deletions fish.cpp
Expand Up @@ -217,8 +217,8 @@ static int read_init(const struct config_paths_t &paths)
{
parser_t &parser = parser_t::principal_parser();
const io_chain_t empty_ios;
parser.eval(L"builtin . " + paths.data + L"/config.fish 2>/dev/null", empty_ios, TOP);
parser.eval(L"builtin . " + paths.sysconf + L"/config.fish 2>/dev/null", empty_ios, TOP);
parser.eval(L"builtin source " + paths.data + L"/config.fish 2>/dev/null", empty_ios, TOP);
parser.eval(L"builtin source " + paths.sysconf + L"/config.fish 2>/dev/null", empty_ios, TOP);


/*
Expand All @@ -233,7 +233,7 @@ static int read_init(const struct config_paths_t &paths)
if (path_get_config(config_dir))
{
wcstring config_dir_escaped = escape_string(config_dir, 1);
wcstring eval_buff = format_string(L"builtin . %ls/config.fish 2>/dev/null", config_dir_escaped.c_str());
wcstring eval_buff = format_string(L"builtin source %ls/config.fish 2>/dev/null", config_dir_escaped.c_str());
parser.eval(eval_buff, empty_ios, TOP);
}

Expand Down
13 changes: 13 additions & 0 deletions share/config.fish
Expand Up @@ -109,3 +109,16 @@ function __fish_on_interactive --on-event fish_prompt
functions -e __fish_on_interactive
end

# "." command for compatibility with old fish versions.
function . --description 'Evaluate contents of file (deprecated, see "source")'
if begin
test (count $argv) -eq 0
# Uses tty directly, as isatty depends on "."
and tty 0>&0 >/dev/null
end
echo "source: '.' command is deprecated, and doesn't work with STDIN anymore. Did you mean 'source' or './'?" >&2
return 1
else
source $argv
end
end

1 comment on commit 5818289

@zanchey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also needs completions updated

Please sign in to comment.