fish-shell/src/builtin_pwd.cpp

40 lines
1.1 KiB
C++
Raw Normal View History

2017-06-15 04:31:05 +08:00
// Implementation of the pwd builtin.
#include "config.h" // IWYU pragma: keep
#include "builtin.h"
#include "builtin_pwd.h"
#include "common.h"
#include "fallback.h" // IWYU pragma: keep
#include "io.h"
#include "wutil.h" // IWYU pragma: keep
/// The pwd builtin. We don't respect -P to resolve symbolic links because we
/// try to always resolve them.
int builtin_pwd(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
UNUSED(parser);
const wchar_t *cmd = argv[0];
int argc = builtin_count_args(argv);
2017-06-15 13:12:29 +08:00
struct cmd_opts_help_only opts;
2017-06-15 04:31:05 +08:00
int optind;
2017-06-15 13:12:29 +08:00
int retval = parse_cmd_opts_help_only(&opts, &optind, argc, argv, parser, streams);
2017-06-15 04:31:05 +08:00
if (retval != STATUS_CMD_OK) return retval;
if (opts.print_help) {
builtin_print_help(parser, streams, cmd, streams.out);
return STATUS_CMD_OK;
}
if (optind != argc) {
streams.err.append_format(BUILTIN_ERR_ARG_COUNT1, cmd, 0, argc - 1);
return STATUS_INVALID_ARGS;
}
wcstring res = wgetcwd();
if (res.empty()) {
return STATUS_CMD_ERROR;
}
streams.out.append(res);
streams.out.push_back(L'\n');
return STATUS_CMD_OK;
}