From 66c1da49fb0e1c91ba39e2cb2b7517a8ff3cdb41 Mon Sep 17 00:00:00 2001 From: Adolfo Perez Alvarez Date: Mon, 17 Jun 2024 12:10:27 +0200 Subject: [PATCH] Send OSC escape sequences --- osc | 18 ++++++++++++++++++ osc.1 | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100755 osc create mode 100644 osc.1 diff --git a/osc b/osc new file mode 100755 index 0000000..d261e28 --- /dev/null +++ b/osc @@ -0,0 +1,18 @@ +#!/usr/bin/env ksh +(( $# < 1 )) && exit 64 +[[ -v X_OSC_DISABLE || ! -t 1 ]] && exit 0 +case $1 in + link) + [[ -z $2 ]] && exit 64 + printf "\e]8;%s\e\\" "$2" + ;; + pwd) + (( $# != 1 )) && exit 64 + printf "\e]7;file://%s%s\e\\" "$HOSTNAME" "$PWD" + ;; + title) + (( $# == 1 )) && exit 64 + shift; + printf '\e]2;%s\e\\' "$*" + ;; +esac diff --git a/osc.1 b/osc.1 new file mode 100644 index 0000000..ce43f94 --- /dev/null +++ b/osc.1 @@ -0,0 +1,43 @@ +.Dd Jun 11, 2024 +.Dt TS 1 +.Os +.Sh NAME +.Nm osc +.Nd Print OSC escape sequences +.Sh SYNOPSIS +.Nm +.Cm pwd +.Nm +.Cm link +.Ar URI +.Nm +.Cm title +.Ar word ... +.Sh DESCRIPTION +.Nm +prints an OSC escape sequence to stdout if connected to a tty. +If stdout is not a TTY, prints nothing. +.Pp +Three escape sequences are supported: +.Bl -tag +.It pwd +ESC 7, set current working directory. +.It link +ESC 8, display an URI. +.It title +ESC 2, set a title for the current window. +.El +.Pp +Whatever it is done with these escape sequences depends on the +terminal emulator. To avoid printing anything, even on ttys, define +.Ev X_OSC_DISABLE +with any value. +.Sh ENVIRONMENT +.Bl -tag -width X_OSC_DISABLE +.It Ev X_OSC_DISABLE +Don't do anything. +.El +.Sh EXIT STATUS +.Ex -std +.Sh AUTHORS +.An Adolfo Perez Alvarez Aq Mt adolfopa@sdf.org