hautils

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 161e211a774b0865864dbad7dbaa46d77d3bac9b
parent 2f4ac4d842041e9c009f9964483e62351ea42222
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu,  6 Jan 2022 15:36:20 +0100

pwd: new command

Diffstat:
M.gitignore | 1+
MMakefile | 1+
Apwd.ha | 40++++++++++++++++++++++++++++++++++++++++
3 files changed, 42 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -10,3 +10,4 @@ tee true uname wc +pwd diff --git a/Makefile b/Makefile @@ -11,6 +11,7 @@ utils=\ false \ head \ nl \ + pwd \ sleep \ tee \ true \ diff --git a/pwd.ha b/pwd.ha @@ -0,0 +1,40 @@ +use getopt; +use main; +use os; +use fmt; + +type mode = enum { + NORM, + NORMLINK, +}; + +export fn utilmain() (main::error | void) = { + const help: []getopt::help = [ + "prints the working directory", + ('L', "print normalized path"), + ('P', "print normalized path without links"), + ]; + const cmd = getopt::parse(os::args, help...); + defer getopt::finish(&cmd); + + let mode = mode::NORM; + for (let i = 0z; i < len(cmd.opts); i += 1) { + const opt = cmd.opts[i]; + switch (opt.0) { + case 'L' => + mode = mode::NORM; + case 'P' => + mode = mode::NORMLINK; + case => abort(); + }; + }; + + const path = switch (mode) { + case mode::NORM => + yield os::resolve(os::getcwd()); + case mode::NORMLINK => + abort(); // TODO + }; + + fmt::println(path)?; +};