Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zsh shell integration fixes #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions source/misc/zsh_startup.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,46 @@ ST_NAME=`hostname -f`
echo Here we go
[ x"$TERM" = "xscreen" ] && exit

# iTerm2 inform terminal that command starts here
_iterm_ft_cmd () {
printf $'\e]133;%s\x07' $@
}
_iterm_si_cmd () {
printf $'\e]1337;%s=%s\x07' $@
}

# iTerm2 inform terminal that command ends & output starts here
before_cmd_executes() {
printf "\033]133;D;$?\007\033]1337;RemoteHost='$USER'@`hostname -f`\007\033]1337;CurrentDir=$PWD\007"
_iterm_ft_cmd 'C'
}

# iTerm2 tell terminal to create a mark at this location
after_cmd_executes() {
printf "\033]133;C\007"
_iterm_ft_cmd "D;$?" # return value of previous command
_iterm_si_cmd "RemoteHost" "'$USER'@$(hostname -f)"
_iterm_si_cmd "CurrentDir" "$PWD"
}

after_pwd_changes() {
_iterm_si_cmd "CurrentDir" "$PWD"
}

# iTerm2 mark start of prompt
# iTerm2 mark start of prompt / end of previous output.
# Command marker in gutter will be inserted here.
iterm_prompt_start() {
print -Pn "\033]133;A\007"
_iterm_ft_cmd "A"
}

# iTerm2 mark end of prompt
# iTerm2 mark end of prompt / start of command input.
iterm_prompt_end() {
print -Pn "\033]133;B\007"
_iterm_ft_cmd "B"
}

PS1="%{$(iterm_prompt_start)%}$PS1%{$(iterm_prompt_end)%}"

precmd() {
after_cmd_executes
}
PROMPT="%{$(iterm_prompt_start)%}$PROMPT%{$(iterm_prompt_end)%}"

preexec() {
before_cmd_executes
}
autoload -Uz add-zsh-hook
add-zsh-hook preexec before_cmd_executes
add-zsh-hook precmd after_cmd_executes
add-zsh-hook chpwd after_pwd_changes

printf "\033]1337;RemoteHost='$USER'@`hostname -f`\007"
printf "\033]1337;CurrentDir=$PWD\007"
printf "\033]1337;ShellIntegrationVersion=1\007"
_iterm_si_cmd "RemoteHost" "'$USER'@$(hostname -f)"
_iterm_si_cmd "CurrentDir" "$PWD"
_iterm_si_cmd "ShellIntegrationVersion" "1"