Send OSC escape sequences

This commit is contained in:
Adolfo Perez Alvarez 2024-06-17 12:10:27 +02:00
parent 9465227fe7
commit 66c1da49fb
2 changed files with 61 additions and 0 deletions

18
osc Executable file
View File

@ -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

43
osc.1 Normal file
View File

@ -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