From b0a4bcb688d0e03b5f4608b4b1d29ca08f0f6987 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Sat, 31 Jul 2021 20:22:27 -0700 Subject: [PATCH] shot: Make output filename a hyperlink when applicable The hyperlink only gets printed when stdout is a TTY, so e.g. something like `shot | cat` will not get the hyperlink escapes. --- Userland/Utilities/shot.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Userland/Utilities/shot.cpp b/Userland/Utilities/shot.cpp index f920e7b577..f15ce17a33 100644 --- a/Userland/Utilities/shot.cpp +++ b/Userland/Utilities/shot.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -166,6 +167,25 @@ int main(int argc, char** argv) return 1; } - outln("{}", output_path); + bool printed_hyperlink = false; + if (isatty(STDOUT_FILENO)) { + auto full_path = Core::File::real_path_for(output_path); + if (!full_path.is_null()) { + char hostname[HOST_NAME_MAX]; + VERIFY(gethostname(hostname, sizeof(hostname)) == 0); + + auto url = URL::create_with_file_scheme(full_path, {}, hostname); + out("\033]8;;{}\033\\", url.serialize()); + printed_hyperlink = true; + } + } + + out("{}", output_path); + + if (printed_hyperlink) { + out("\033]8;;\033\\"); + } + + outln(""); return 0; }