summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2022-12-02 21:02:14 +0100
committerxengineering <me@xengineering.eu>2022-12-02 21:02:14 +0100
commit558796bd5187d6b3e33d297ab8e035d62707939e (patch)
treeb73dadeead2f82f025158b05bbd7a3e98b66d3a3
parentc4278c16bd6022709a6268f318e5ef8594e16117 (diff)
downloaddotfiles-558796bd5187d6b3e33d297ab8e035d62707939e.tar
dotfiles-558796bd5187d6b3e33d297ab8e035d62707939e.tar.zst
dotfiles-558796bd5187d6b3e33d297ab8e035d62707939e.zip
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
-rw-r--r--.bashrc18
1 files changed, 17 insertions, 1 deletions
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