From 56701f91f90415329fe60a3bb8fb269fb0a71129 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 16 Dec 2020 23:23:55 +0100 Subject: [PATCH] ln: Make the 'path' argument optional If 'path' is omitted, we create a link with the basename of whatever the target is. This matches what other systems do. --- Userland/ln.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Userland/ln.cpp b/Userland/ln.cpp index fd462e6ede3..ac9077ec0bd 100644 --- a/Userland/ln.cpp +++ b/Userland/ln.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -44,9 +45,15 @@ int main(int argc, char** argv) Core::ArgsParser args_parser; args_parser.add_option(symbolic, "Create a symlink", "symbolic", 's'); args_parser.add_positional_argument(target, "Link target", "target"); - args_parser.add_positional_argument(path, "Link path", "path"); + args_parser.add_positional_argument(path, "Link path", "path", Core::ArgsParser::Required::No); args_parser.parse(argc, argv); + String path_buffer; + if (!path) { + path_buffer = LexicalPath(target).basename(); + path = path_buffer.characters(); + } + if (symbolic) { int rc = symlink(target, path); if (rc < 0) {