diff options
author | xengineering <me@xengineering.eu> | 2022-12-02 21:02:14 +0100 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2022-12-02 21:02:14 +0100 |
commit | 558796bd5187d6b3e33d297ab8e035d62707939e (patch) | |
tree | b73dadeead2f82f025158b05bbd7a3e98b66d3a3 | |
parent | c4278c16bd6022709a6268f318e5ef8594e16117 (diff) | |
download | dotfiles-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-- | .bashrc | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -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 |