b9c4e2e82337594c2899db1f9ca005bb02fe20cd
- Author
- Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/tools/changelog.sh b/tools/changelog.sh
2index a5cc468f2451d28ffa2fe939cb69ae25e5b4a0ee..5f7a14d03f5380aaf1b1aa95c26ee014b9d041f0 100755
3--- a/tools/changelog.sh
4+++ b/tools/changelog.sh
5@@ -157,6 +157,89 @@ function parse-commit {
6 fi
7 }
8
9+################################
10+# SUPPORTS HYPERLINKS FUNCTION #
11+################################
12+
13+# The code for checking if a terminal supports hyperlinks is copied from install.sh
14+
15+# The [ -t 1 ] check only works when the function is not called from
16+# a subshell (like in `$(...)` or `(...)`, so this hack redefines the
17+# function at the top level to always return false when stdout is not
18+# a tty.
19+if [ -t 1 ]; then
20+ is_tty() {
21+ true
22+ }
23+else
24+ is_tty() {
25+ false
26+ }
27+fi
28+
29+# This function uses the logic from supports-hyperlinks[1][2], which is
30+# made by Kat Marchán (@zkat) and licensed under the Apache License 2.0.
31+# [1] https://github.com/zkat/supports-hyperlinks
32+# [2] https://crates.io/crates/supports-hyperlinks
33+#
34+# Copyright (c) 2021 Kat Marchán
35+#
36+# Licensed under the Apache License, Version 2.0 (the "License");
37+# you may not use this file except in compliance with the License.
38+# You may obtain a copy of the License at
39+#
40+# http://www.apache.org/licenses/LICENSE-2.0
41+#
42+# Unless required by applicable law or agreed to in writing, software
43+# distributed under the License is distributed on an "AS IS" BASIS,
44+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
45+# See the License for the specific language governing permissions and
46+# limitations under the License.
47+supports_hyperlinks() {
48+ # $FORCE_HYPERLINK must be set and be non-zero (this acts as a logic bypass)
49+ if [ -n "$FORCE_HYPERLINK" ]; then
50+ [ "$FORCE_HYPERLINK" != 0 ]
51+ return $?
52+ fi
53+
54+ # If stdout is not a tty, it doesn't support hyperlinks
55+ is_tty || return 1
56+
57+ # DomTerm terminal emulator (domterm.org)
58+ if [ -n "$DOMTERM" ]; then
59+ return 0
60+ fi
61+
62+ # VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc)
63+ if [ -n "$VTE_VERSION" ]; then
64+ [ $VTE_VERSION -ge 5000 ]
65+ return $?
66+ fi
67+
68+ # If $TERM_PROGRAM is set, these terminals support hyperlinks
69+ case "$TERM_PROGRAM" in
70+ Hyper|iTerm.app|terminology|WezTerm) return 0 ;;
71+ esac
72+
73+ # kitty supports hyperlinks
74+ if [ "$TERM" = xterm-kitty ]; then
75+ return 0
76+ fi
77+
78+ # Windows Terminal also supports hyperlinks
79+ if [ -n "$WT_SESSION" ]; then
80+ return 0
81+ fi
82+
83+ # Konsole supports hyperlinks, but it's an opt-in setting that can't be detected
84+ # https://github.com/ohmyzsh/ohmyzsh/issues/10964
85+ # if [ -n "$KONSOLE_VERSION" ]; then
86+ # return 0
87+ # fi
88+
89+ return 1
90+}
91+
92 #############################
93 # RELEASE CHANGELOG DISPLAY #
94 #############################
95@@ -208,7 +291,13 @@ function display-release {
96 local hash="${1:-$hash}"
97 case "$output" in
98 raw) printf '%s' "$hash" ;;
99- text) printf '\e[33m%s\e[0m' "$hash" ;; # red
100+ text)
101+ local text="\e[33m$hash\e[0m"; # red
102+ if supports_hyperlinks; then
103+ printf "\e]8;;%s\a%s\e]8;;\a" "https://github.com/ohmyzsh/ohmyzsh/commit/$hash" $text;
104+ else