From 6181781f3d99c5a1750debce6840b4aad895086f Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 20 May 2016 09:41:29 +0100 Subject: [PATCH] Change dir to $HOME when no parameters are given to cd Fixes #678 --- src/commands.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/commands.cc b/src/commands.cc index ce240c94..56a94430 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1857,7 +1857,7 @@ const CommandDesc change_working_directory_cmd = { "cd", nullptr, "cd : change server working directory to ", - single_name_param, + single_optional_name_param, CommandFlags::None, CommandHelper{}, PerArgumentCommandCompleter{{ @@ -1871,8 +1871,10 @@ const CommandDesc change_working_directory_cmd = { }}, [](const ParametersParser& parser, Context&, const ShellContext&) { - if (chdir(parse_filename(parser[0]).c_str()) != 0) - throw runtime_error(format("cannot change to directory '{}'", parser[0])); + + StringView target = parser.positional_count() == 1 ? parser[0] : "~"; + if (chdir(parse_filename(target).c_str()) != 0) + throw runtime_error(format("cannot change to directory '{}'", target)); for (auto& buffer : BufferManager::instance()) buffer->update_display_name(); }