From 856bf478f1e82ca0b5995f28727a88faa60c9309 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 31 Jul 2026 04:36:10 +0545 Subject: [PATCH] hterm: copy the files here They're only a few KB each. --- .bin/hterm-notify | 121 +++++++++++++++++++++++++++++++++- .bin/hterm-show-file | 134 +++++++++++++++++++++++++++++++++++++- .bin/osc52 | 150 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 402 insertions(+), 3 deletions(-) mode change 120000 => 100755 .bin/hterm-notify mode change 120000 => 100755 .bin/hterm-show-file mode change 120000 => 100644 .bin/osc52 diff --git a/.bin/hterm-notify b/.bin/hterm-notify deleted file mode 120000 index 1970932..0000000 --- a/.bin/hterm-notify +++ /dev/null @@ -1 +0,0 @@ -/usr/local/src/extensions/apps/libapps/hterm/etc/hterm-notify.sh \ No newline at end of file diff --git a/.bin/hterm-notify b/.bin/hterm-notify new file mode 100755 index 0000000..1159355 --- /dev/null +++ b/.bin/hterm-notify @@ -0,0 +1,120 @@ +#!/bin/sh +# Copyright 2017 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Write an error message and exit. +# Usage: +die() { + echo "ERROR: $*" + exit 1 +} + +# Send a DCS sequence through tmux. +# Usage: +tmux_dcs() { + printf '\033Ptmux;\033%s\033\\' "$1" +} + +# Send a DCS sequence through screen. +# Usage: +screen_dcs() { + # Screen limits the length of string sequences, so we have to break it up. + # Going by the screen history: + # (v4.2.1) Apr 2014 - today: 768 bytes + # Aug 2008 - Apr 2014 (v4.2.0): 512 bytes + # ??? - Aug 2008 (v4.0.3): 256 bytes + # Since v4.2.0 is only ~4 years old, we'll use the 256 limit. + # We can probably switch to the 768 limit in 2022. + local limit=256 + # We go 4 bytes under the limit because we're going to insert two bytes + # before (\eP) and 2 bytes after (\e\) each string. + echo "$1" | \ + sed -E "s:.{$(( limit - 4 ))}:&\n:g" | \ + sed -E -e 's:^:\x1bP:' -e 's:$:\x1b\\:' | \ + tr -d '\n' +} + +# Send an escape sequence to hterm. +# Usage: +print_seq() { + local seq="$1" + + case ${TERM-} in + screen*) + # Since tmux defaults to setting TERM=screen (ugh), we need to detect + # it here specially. + if [ -n "${TMUX-}" ]; then + tmux_dcs "${seq}" + else + screen_dcs "${seq}" + fi + ;; + tmux*) + tmux_dcs "${seq}" + ;; + *) + printf '%s' "${seq}" + ;; + esac +} + +# Send a notification. +# Usage: [title] [body] +notify() { + local title="${1-}" body="${2-}" + print_seq "$(printf '\033]777;notify;%s;%s\a' "${title}" "${body}")" +} + +# Write tool usage and exit. +# Usage: [error message] +usage() { + if [ $# -gt 0 ]; then + exec 1>&2 + fi + cat < [body] + +Send a notification to hterm. + +Notes: +- The title should not have a semi-colon in it. +- Neither field should have escape sequences in them. + Best to stick to plain text. +EOF + + if [ $# -gt 0 ]; then + echo + die "$@" + else + exit 0 + fi +} + +main() { + set -e + + while [ $# -gt 0 ]; do + case $1 in + -h|--help) + usage + ;; + -*) + usage "Unknown option: $1" + ;; + *) + break + ;; + esac + done + + if [ $# -eq 0 ]; then + die "Missing message to send" + fi + if [ $# -gt 2 ]; then + usage "Too many arguments" + fi + + notify "$@" +} +main "$@" diff --git a/.bin/hterm-show-file b/.bin/hterm-show-file deleted file mode 120000 index 50f6696..0000000 --- a/.bin/hterm-show-file +++ /dev/null @@ -1 +0,0 @@ -/usr/local/src/extensions/apps/libapps/hterm/etc/hterm-show-file.sh \ No newline at end of file diff --git a/.bin/hterm-show-file b/.bin/hterm-show-file new file mode 100755 index 0000000..9c66d57 --- /dev/null +++ b/.bin/hterm-show-file @@ -0,0 +1,133 @@ +#!/bin/sh +# Copyright 2017 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Write an error message and exit. +# Usage: +die() { + echo "ERROR: $*" + exit 1 +} + +# Send a DCS sequence through tmux. +# Usage: +tmux_dcs() { + printf '\033Ptmux;\033%s\033\\' "$1" +} + +# Send a DCS sequence through screen. +# Usage: +screen_dcs() { + # Screen limits the length of string sequences, so we have to break it up. + # Going by the screen history: + # (v4.2.1) Apr 2014 - today: 768 bytes + # Aug 2008 - Apr 2014 (v4.2.0): 512 bytes + # ??? - Aug 2008 (v4.0.3): 256 bytes + # Since v4.2.0 is only ~4 years old, we'll use the 256 limit. + # We can probably switch to the 768 limit in 2022. + local limit=256 + # We go 4 bytes under the limit because we're going to insert two bytes + # before (\eP) and 2 bytes after (\e\) each string. + echo "$1" | \ + sed -E "s:.{$(( limit - 4 ))}:&\n:g" | \ + sed -E -e 's:^:\x1bP:' -e 's:$:\x1b\\:' | \ + tr -d '\n' +} + +# Send an escape sequence to hterm. +# Usage: +print_seq() { + local seq="$1" + + case ${TERM-} in + screen*) + # Since tmux defaults to setting TERM=screen (ugh), we need to detect + # it here specially. + if [ -n "${TMUX-}" ]; then + tmux_dcs "${seq}" + else + screen_dcs "${seq}" + fi + ;; + tmux*) + tmux_dcs "${seq}" + ;; + *) + printf '%s' "${seq}" + ;; + esac +} + +# Base64 encode stdin. +b64enc() { + base64 | tr -d '\n' +} + +# Get the image height/width via imagemagick if possible. +# Usage: +dimensions() { + identify -format 'width=%wpx;height=%hpx;' "$1" 2>/dev/null +} + +# Send the 1337 OSC sequence to display the file. +# Usage: +show() { + local name="$1" + local opts="inline=1;$2" + + print_seq "$(printf '\033]1337;File=name=%s;%s%s:%s\a' \ + "$(echo "$(basename "${name}")" | b64enc)" \ + "$(dimensions "${name}")" \ + "${opts}" \ + "$(b64enc <"${name}")")" +} + +# Write tool usage and exit. +# Usage: [error message] +usage() { + if [ $# -gt 0 ]; then + exec 1>&2 + fi + cat < [options] + +Send a file to hterm. It can be shown inline or downloaded. +This can also be used for small file transfers. +EOF + + if [ $# -gt 0 ]; then + echo + die "$@" + else + exit 0 + fi +} + +main() { + set -e + + while [ $# -gt 0 ]; do + case $1 in + -h|--help) + usage + ;; + -*) + usage "Unknown option: $1" + ;; + *) + break + ;; + esac + done + + if [ $# -eq 0 ]; then + die "Missing file to send" + fi + if [ $# -gt 2 ]; then + usage "Too many arguments" + fi + + show "$@" +} +main "$@" diff --git a/.bin/osc52 b/.bin/osc52 deleted file mode 120000 index 0b6c7dd..0000000 --- a/.bin/osc52 +++ /dev/null @@ -1 +0,0 @@ -/usr/local/src/extensions/apps/libapps/hterm/etc/osc52.sh \ No newline at end of file diff --git a/.bin/osc52 b/.bin/osc52 new file mode 100644 index 0000000..f0ed980 --- /dev/null +++ b/.bin/osc52 @@ -0,0 +1,149 @@ +#!/bin/sh +# Copyright 2012 The ChromiumOS Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# Max length of the OSC 52 sequence. Sequences longer than this will not be +# sent to the terminal. +OSC_52_MAX_SEQUENCE="100000" + +# Write an error message and exit. +# Usage: +die() { + echo "ERROR: $*" + exit 1 +} + +# Send a DCS sequence through tmux. +# Usage: +tmux_dcs() { + printf '\033Ptmux;\033%s\033\\' "$1" +} + +# Send a DCS sequence through screen. +# Usage: +screen_dcs() { + # Screen limits the length of string sequences, so we have to break it up. + # Going by the screen history: + # (v4.2.1) Apr 2014 - today: 768 bytes + # Aug 2008 - Apr 2014 (v4.2.0): 512 bytes + # ??? - Aug 2008 (v4.0.3): 256 bytes + # Since v4.2.0 is only ~4 years old, we'll use the 256 limit. + # We can probably switch to the 768 limit in 2022. + local limit=256 + # We go 4 bytes under the limit because we're going to insert two bytes + # before (\eP) and 2 bytes after (\e\) each string. + echo "$1" | \ + sed -E "s:.{$(( limit - 4 ))}:&\n:g" | \ + sed -E -e 's:^:\x1bP:' -e 's:$:\x1b\\:' | \ + tr -d '\n' +} + +# Send an escape sequence to hterm. +# Usage: +print_seq() { + local seq="$1" + + case ${TERM-} in + screen*) + # Since tmux defaults to setting TERM=screen (ugh), we need to detect + # it here specially. + if [ -n "${TMUX-}" ]; then + tmux_dcs "${seq}" + else + screen_dcs "${seq}" + fi + ;; + tmux*) + tmux_dcs "${seq}" + ;; + *) + printf '%s' "${seq}" + ;; + esac +} + +# Base64 encode stdin. +b64enc() { + base64 | tr -d '\n' +} + +# Send the OSC 52 sequence to copy the content. +# Usage: [string] +copy() { + local str + + if [ $# -eq 0 ]; then + str="$(b64enc)" + else + str="$(echo "$@" | b64enc)" + fi + + if [ ${OSC_52_MAX_SEQUENCE} -gt 0 ]; then + local len=${#str} + if [ ${len} -gt ${OSC_52_MAX_SEQUENCE} ]; then + die "selection too long to send to terminal:" \ + "${OSC_52_MAX_SEQUENCE} limit, ${len} attempted" + fi + fi + + print_seq "$(printf '\033]52;c;%s\a' "${str}")" +} + +# Write tool usage and exit. +# Usage: [error message] +usage() { + if [ $# -gt 0 ]; then + exec 1>&2 + fi + cat < 52. + +The data can either be read from stdin: + $ echo "hello world" | osc52.sh + +Or specified on the command line: + $ osc52.sh "hello world" + +Options: + -h, --help This screen. + -f, --force Ignore max byte limit (${OSC_52_MAX_SEQUENCE}) +EOF + + if [ $# -gt 0 ]; then + echo + die "$@" + else + exit 0 + fi +} + +main() { + set -e + + while [ $# -gt 0 ]; do + case $1 in + -h|--help) + usage + ;; + -f|--force) + OSC_52_MAX_SEQUENCE=0 + ;; + -*) + usage "Unknown option: $1" + ;; + *) + break + ;; + esac + shift + done + + copy "$@" +} +main "$@" -- 2.47.3