Skip to content

Instantly share code, notes, and snippets.

@skyline75489
Last active September 22, 2020 02:34
Show Gist options
  • Save skyline75489/b95a03f9967dbce25ac439fb19cdbd56 to your computer and use it in GitHub Desktop.
Save skyline75489/b95a03f9967dbce25ac439fb19cdbd56 to your computer and use it in GitHub Desktop.
Windows Terminal OSC 7 for Git Bash
__wt_osc7 () {
_win_path="$(cygpath -m $(pwd))"
printf "\033]7;file://%s/%s\033\\" "$HOSTNAME" "$_win_path"
}
[ -n "$BASH_VERSION" ] && [ -n "$WT_SESSION" ] && PROMPT_COMMAND="__wt_osc7"
@TBBle
Copy link

TBBle commented Sep 21, 2020

-w produces backslashes. Try -m which produces forward-slashes instead, but is otherwise the same.

Also, you can use cygpath even outside /[c-z]/, it'll determine the actual Windows working directory for the Cygwin path. So I don't think this needs the "MSYS Path" leg of the if.

What I ended up with is the single-line version:

printf "\033]7;file://%s/%s\033\\" "${HOSTNAME}" "$(cygpath --mixed ${PWD})"

@TBBle
Copy link

TBBle commented Sep 21, 2020

Also, might need to append to PROMPT_COMMAND (if possible) or slurp it in, since there's already a default, at least in my env (I don't recall changing it) of history -a.

Edit: Hmm. That's in my ~/.bashrc, so perhaps it is something I enabled years ago. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment