Skip to content

Commit

Permalink
common: Configuration for VS Code shell integration
Browse files Browse the repository at this point in the history
  • Loading branch information
magicant committed Aug 3, 2024
1 parent e14ad8f commit 956d17c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
4 changes: 3 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
History of Yash
# History of Yash

## Yash 2.57 (Unreleased)

Expand All @@ -13,6 +13,8 @@ History of Yash
- [line-editing] Completion no longer inserts a redundant backslash
to escape a character included in the completed word
when the cursor follows another backslash.
- Updated the sample initialization script (yashrc):
- Added setup for VS Code shell integration.

## Yash 2.56.1 (2024-03-20)

Expand Down
4 changes: 3 additions & 1 deletion NEWS.ja
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Yash 更新履歴
# Yash 更新履歴

## Yash 2.57 (未リリース)

Expand All @@ -12,6 +12,8 @@ Yash 更新履歴
- [行編集] カーソルがバックスラッシュの直後にある時に補完をすると
補完する単語に含まれるエスケープが必要な文字に対して
余計なバックスラッシュが挿入されるのを修正
- 初期化スクリプト (yashrc) のサンプルを更新:
- VS Code シェル統合のための設定を追加

## Yash 2.56.1 (2024-03-20)

Expand Down
42 changes: 42 additions & 0 deletions share/initialization/common
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,48 @@ if [ "$_tsl" ] && [ "$_fsl" ]; then

fi

# support VS Code shell integration
if [ "${TERM_PROGRAM-}" = vscode ]; then

# wrap the prompt with markers
YASH_PS1="\[\e]633;A\e\\\\\]$YASH_PS1\[\e]633;B\e\\\\\]"
YASH_PS1R="\[\e]633;A\e\\\\\]$YASH_PS1R\[\e]633;B\e\\\\\]"
YASH_PS2="\[\e]633;A\e\\\\\]$YASH_PS2\[\e]633;B\e\\\\\]"

# notify the terminal before executing a command
_send_cmdline() {
# Following the pre-execution mark, we also print the command line content
# so the terminal can receive the correct command especially in the presence
# of the right prompt. Some characters need to be escaped, so we print them
# one by one.
printf '\033]633;C\033\\\033]633;E;'
typeset cmd="$COMMAND"
while [ "$cmd" ]; do
case "${cmd[1]}" in
(';'|[-' '])
printf '\\x%.2X' "'${cmd[1]}"
;;
(\\)
printf '\\\\'
;;
(*)
printf %c "${cmd[1]}"
;;
esac
cmd=${cmd[2,-1]}
done
printf '\033\\'
}
POST_PROMPT_COMMAND=("$POST_PROMPT_COMMAND" _send_cmdline)

# notify the terminal after executing a command
_send_exit_status() {
printf '\033]633;D;%d\033\\' "$?"
}
PROMPT_COMMAND=("$PROMPT_COMMAND" _send_exit_status)

fi

# define function that updates $_vcs_info and $_vcs_root
_update_vcs_info() {
typeset type branch
Expand Down

0 comments on commit 956d17c

Please sign in to comment.