0001-add-POSIX-sh-for-OSC7.patch

on kitten's pastes | raw

expires: 21 May, 2024

 1From 6c7d5e87e0b44fc05669ba2a0177a7a89817d2a1 Mon Sep 17 00:00:00 2001
 2From: sewn <sewn@disroot.org>
 3Date: Wed, 21 Feb 2024 18:52:25 +0300
 4Subject: [PATCH] add POSIX sh for OSC7
 5
 6---
 7 Home.md | 30 ++++++++++++++++++++++++++++++
 8 1 file changed, 30 insertions(+)
 9
10diff --git a/Home.md b/Home.md
11index 3e87bdb..598bd56 100644
12--- a/Home.md
13+++ b/Home.md
14@@ -388,6 +388,36 @@ This is done with the OSC-7 escape sequence. Most shells can be
15 scripted to do this, if they do not support it natively. See examples
16 for bash, zsh and fish below:
17 
18+##### POSIX sh
19+
20+Add the following to your `$ENV` or relevant startup script:
21+
22+```sh
23+
24+osc7_cd() {
25+    cd "$1" || return $?
26+
27+    tmp="$PWD"
28+    encoded=""
29+    while [ -n "$tmp" ]; do
30+        n="${tmp#?}"
31+        c="${tmp%"$n"}"
32+        case "$c" in
33+            [-/:_.!\'\(\)~[:alnum:]]) encoded="$encoded$c" ;;
34+            *) encoded="${encoded}$(printf '%%%02X' "$c")"  ;;
35+        esac
36+        tmp="$n"
37+        unset n c
38+    done
39+
40+    printf "\033]7;file://%s%s\033\\" "$(hostname)" "$encoded"
41+    unset tmp decoded
42+}
43+
44+osc7_cd "$PWD" # first-run
45+alias cd=osc7_cd
46+```
47+
48 ##### Bash
49 
50 Add the following to your `.bashrc`:
51-- 
522.43.2
53