Implement Zsh integration
* integration/zsh: New file. * eat.texi (Shell Integration): Add instructions for Zsh. * integration/bash: Always return zero on succuss.
This commit is contained in:
parent
eab01e693b
commit
792a98810e
3 changed files with 99 additions and 5 deletions
9
eat.texi
9
eat.texi
|
@ -374,7 +374,7 @@ Eat. When shell integration is enabled and the script is loaded in
|
||||||
your shell, it'll take care of everything and provide many useful
|
your shell, it'll take care of everything and provide many useful
|
||||||
features.
|
features.
|
||||||
|
|
||||||
Currently only GNU Bash is supported.
|
Currently only GNU Bash and Zsh are supported.
|
||||||
|
|
||||||
If you use GNU Bash, put the following in your @samp{.bashrc} file:
|
If you use GNU Bash, put the following in your @samp{.bashrc} file:
|
||||||
|
|
||||||
|
@ -383,6 +383,13 @@ If you use GNU Bash, put the following in your @samp{.bashrc} file:
|
||||||
source "$EAT_SHELL_INTEGRATION_DIR/bash"
|
source "$EAT_SHELL_INTEGRATION_DIR/bash"
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
|
If you use Zsh, put the following in your @samp{.zshrc} file:
|
||||||
|
|
||||||
|
@example
|
||||||
|
[ -n "$EAT_SHELL_INTEGRATION_DIR" ] && \
|
||||||
|
source "$EAT_SHELL_INTEGRATION_DIR/zsh"
|
||||||
|
@end example
|
||||||
|
|
||||||
@cindex directory tracking
|
@cindex directory tracking
|
||||||
@cindex tracking directory
|
@cindex tracking directory
|
||||||
@cindex working directory tracking
|
@cindex working directory tracking
|
||||||
|
|
|
@ -43,8 +43,8 @@ __eat_preexec () {
|
||||||
"$(printf "%s" "$__eat_current_command" | base64)"
|
"$(printf "%s" "$__eat_current_command" | base64)"
|
||||||
# Send pre-exec sequence.
|
# Send pre-exec sequence.
|
||||||
printf '\e]51;e;G\e\\'
|
printf '\e]51;e;G\e\\'
|
||||||
# Update title to including the command running.
|
# Update title to include the command running.
|
||||||
# "${PWD/$HOME/'~'}" converts "/home/akib/org/" to "~/org/".
|
# "${PWD/$HOME/'~'}" converts "/home/akib/foo/" to "~/foo/".
|
||||||
# The next one is substituted with '$', or '#' if we're "root".
|
# The next one is substituted with '$', or '#' if we're "root".
|
||||||
printf '\e]2;%s@%s:%s%s %s\e\\' "$USER" "$HOSTNAME" \
|
printf '\e]2;%s@%s:%s%s %s\e\\' "$USER" "$HOSTNAME" \
|
||||||
"${PWD/$HOME/'~'}" \
|
"${PWD/$HOME/'~'}" \
|
||||||
|
@ -105,10 +105,15 @@ __eat_enable_integration ()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Enable.
|
# Enable.
|
||||||
test -z "$__eat_integration_enabled" && \
|
if test -z "$__eat_integration_enabled" && \
|
||||||
test "${TERM:0:4}" = "eat-" && \
|
test "${TERM:0:4}" = "eat-"
|
||||||
|
then
|
||||||
__eat_enable_integration
|
__eat_enable_integration
|
||||||
|
else
|
||||||
|
true
|
||||||
|
fi
|
||||||
|
|
||||||
# Local Variables:
|
# Local Variables:
|
||||||
# mode: sh
|
# mode: sh
|
||||||
|
# sh-shell: bash
|
||||||
# End:
|
# End:
|
||||||
|
|
82
integration/zsh
Normal file
82
integration/zsh
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
# integration/bash --- Bash integration
|
||||||
|
|
||||||
|
# Copyright (C) 2022 Akib Azmain Turja.
|
||||||
|
|
||||||
|
# This file is not part of GNU Emacs.
|
||||||
|
|
||||||
|
# This file is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 3, or (at your option)
|
||||||
|
# any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
# For a full copy of the GNU General Public License
|
||||||
|
# see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
__eat_precmd () {
|
||||||
|
__eat_exit_status="$?"
|
||||||
|
# Send exit status.
|
||||||
|
if test -n "$__eat_current_command"
|
||||||
|
then
|
||||||
|
printf '\e]51;e;H;%i\e\\' "$__eat_exit_status"
|
||||||
|
fi
|
||||||
|
__eat_current_command=""
|
||||||
|
# Send the current working directory, for directory tracking.
|
||||||
|
printf '\e]51;e;A;%s;%s\e\\' "$(printf "%s" "$HOSTNAME" | base64)" \
|
||||||
|
"$(printf "%s" "$PWD" | base64)"
|
||||||
|
# Update title.
|
||||||
|
# "${PWD/$HOME/'~'}" converts "/home/akib/org/" to "~/org/".
|
||||||
|
# The next one is substituted with '$', or '#' if we're "root".
|
||||||
|
printf '\e]2;%s@%s:%s%s\e\\' "$USER" "$HOST" "${PWD/$HOME/~}" \
|
||||||
|
"$(test $UID -eq 0 && echo '#' || echo '%')"
|
||||||
|
}
|
||||||
|
|
||||||
|
__eat_preexec () {
|
||||||
|
__eat_current_command="$1"
|
||||||
|
# Send current command.
|
||||||
|
printf '\e]51;e;F;%s\e\\' \
|
||||||
|
"$(printf "%s" "$__eat_current_command" | base64)"
|
||||||
|
# Send pre-exec sequence.
|
||||||
|
printf '\e]51;e;G\e\\'
|
||||||
|
# Update title to include the command running.
|
||||||
|
# "${PWD/$HOME/~}" converts "/home/akib/foo/" to "~/foo/".
|
||||||
|
# The next one is substituted with '%', or '#' if we're "root".
|
||||||
|
printf '\e]2;%s@%s:%s%s %s\e\\' "$USER" "$HOST" "${PWD/$HOME/~}" \
|
||||||
|
"$(test $UID -eq 0 && echo '#' || echo '%')" \
|
||||||
|
"$__eat_current_command"
|
||||||
|
}
|
||||||
|
|
||||||
|
__eat_enable_integration ()
|
||||||
|
{
|
||||||
|
__eat_integration_enabled=yes
|
||||||
|
__eat_current_command=""
|
||||||
|
__eat_exit_status=0
|
||||||
|
local __eat_prompt_start="$(printf '\e]51;e;B\e\\')"
|
||||||
|
local __eat_prompt_end="$(printf '\e]51;e;C\e\\')"
|
||||||
|
local __eat_continuation_start="$(printf '\e]51;e;D\e\\')"
|
||||||
|
local __eat_continuation_end="$(printf '\e]51;e;E\e\\')"
|
||||||
|
PS1="%{$__eat_prompt_start%}$PS1%{$__eat_prompt_end%}"
|
||||||
|
PS2="%{$__eat_continuation_start%}$PS2%{$__eat_continuation_end%}"
|
||||||
|
# TODO: What to do about RPS1 and friends?
|
||||||
|
autoload -Uz add-zsh-hook
|
||||||
|
add-zsh-hook precmd __eat_precmd
|
||||||
|
add-zsh-hook preexec __eat_preexec
|
||||||
|
}
|
||||||
|
|
||||||
|
# Enable.
|
||||||
|
if test -z "$__eat_integration_enabled" && \
|
||||||
|
test "${TERM:0:4}" = "eat-"
|
||||||
|
then
|
||||||
|
__eat_enable_integration
|
||||||
|
else
|
||||||
|
true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Local Variables:
|
||||||
|
# mode: sh
|
||||||
|
# sh-shell: zsh
|
||||||
|
# End:
|
Loading…
Add table
Reference in a new issue