From 558796bd5187d6b3e33d297ab8e035d62707939e Mon Sep 17 00:00:00 2001
From: xengineering <me@xengineering.eu>
Date: Fri, 2 Dec 2022 21:02:14 +0100
Subject: Let Bash emit the OSC-7 escape sequence

This allows the foot terminal emulator to launch a new instance in the
same directory [1].

[1]: https://codeberg.org/dnkl/foot/wiki#shell-integration
---
 .bashrc | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/.bashrc b/.bashrc
index b1740d0..a1ae98b 100644
--- a/.bashrc
+++ b/.bashrc
@@ -66,8 +66,24 @@ rand_util() {
     pacman -Ql coreutils | grep bin | awk '{print $2}' | sed '/^.*\/$/d' | shuf -n 1 - | xargs man
 }
 
-
 # set prompt
 PS1='[\e[31m$(get_nonzero_retcode)\e[0m\e[32;1m$(date +"%H:%M:%S")\e[0m \e[35;1m\u@\h\e[0m\e[33;1m$(parse_git_branch)\e[0m \e[36;1m\W\e[0m]
 $ '
 
+# Emit OSC-7 escape sequence to allow the foot terminal emulator to spawn a new
+# terminal in the same folder.
+osc7_cwd() {
+    local strlen=${#PWD}
+    local encoded=""
+    local pos c o
+    for (( pos=0; pos<strlen; pos++ )); do
+        c=${PWD:$pos:1}
+        case "$c" in
+            [-/:_.!\'\(\)~[:alnum:]] ) o="${c}" ;;
+            * ) printf -v o '%%%02X' "'${c}" ;;
+        esac
+        encoded+="${o}"
+    done
+    printf '\e]7;file://%s%s\e\\' "${HOSTNAME}" "${encoded}"
+}
+PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND; }osc7_cwd
-- 
cgit v1.2.3-70-g09d2