Terminfo and shell integration for eat.el
This commit is contained in:
parent
4bf6964455
commit
0d9f742499
11 changed files with 218 additions and 0 deletions
119
eat/.emacs.d/elpa/eat-0.8/integration/bash
Normal file
119
eat/.emacs.d/elpa/eat-0.8/integration/bash
Normal file
|
|
@ -0,0 +1,119 @@
|
||||||
|
# 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_prompt_command () {
|
||||||
|
# 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" "$HOSTNAME" \
|
||||||
|
"${PWD/$HOME/'~'}" \
|
||||||
|
"$(test $UID -eq 0 && echo '#' || echo '$')"
|
||||||
|
}
|
||||||
|
|
||||||
|
__eat_preexec () {
|
||||||
|
# Get the real command typed by the user from the history.
|
||||||
|
__eat_current_command="$(history 1 | sed 's/ *[0-9]* *//')"
|
||||||
|
# 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" "$HOSTNAME" \
|
||||||
|
"${PWD/$HOME/'~'}" \
|
||||||
|
"$(test $UID -eq 0 && echo '#' || echo '$')" \
|
||||||
|
"$__eat_current_command"
|
||||||
|
}
|
||||||
|
|
||||||
|
__eat_before_prompt_command ()
|
||||||
|
{
|
||||||
|
__eat_exit_status="$?"
|
||||||
|
__eat_inhibit_preexec=yes
|
||||||
|
}
|
||||||
|
|
||||||
|
__eat_after_prompt_command ()
|
||||||
|
{
|
||||||
|
__eat_inhibit_preexec=no
|
||||||
|
}
|
||||||
|
|
||||||
|
__eat_before_exec () {
|
||||||
|
if test $__eat_inhibit_preexec = no \
|
||||||
|
&& test "$BASH_COMMAND" != __eat_before_prompt_command
|
||||||
|
then
|
||||||
|
__eat_inhibit_preexec=yes
|
||||||
|
__eat_preexec
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
__eat_enable_integration ()
|
||||||
|
{
|
||||||
|
__eat_integration_enabled=yes
|
||||||
|
__eat_current_command=""
|
||||||
|
__eat_exit_status=0
|
||||||
|
__eat_inhibit_preexec=yes
|
||||||
|
local __eat_prompt_start='\e]51;e;B\e\\'
|
||||||
|
local __eat_prompt_end='\e]51;e;C\e\\'
|
||||||
|
local __eat_continuation_start='\e]51;e;D\e\\'
|
||||||
|
local __eat_continuation_end='\e]51;e;E\e\\'
|
||||||
|
PS1="\[$__eat_prompt_start\]$PS1\[$__eat_prompt_end\]"
|
||||||
|
PS2="\[$__eat_continuation_start\]$PS2\[$__eat_continuation_end\]"
|
||||||
|
PROMPT_COMMAND+=(__eat_prompt_command)
|
||||||
|
trap '__eat_before_exec' DEBUG
|
||||||
|
# Wrap 'PROMPT_COMMAND' to avoid it getting trapped in 'DEBUG' trap.
|
||||||
|
# Step 1: Append to PROMPT_COMMAND.
|
||||||
|
PROMPT_COMMAND+=(__eat_after_prompt_command)
|
||||||
|
# Step 2: Prepend to PROMPT_COMMAND.
|
||||||
|
# Step 2.1: Move all elements to make the first index free.
|
||||||
|
# Fun fact: Microsoft doesn't still about know this simple trick.
|
||||||
|
# They ended up using something as silly and pityful as
|
||||||
|
# 'VAR=$PROMPT_COMMAND' to copy a Bash array in VSCode Bash
|
||||||
|
# integration script, which simply won't work ever, and then
|
||||||
|
# complain about Bash in the comments! xD
|
||||||
|
for i in $(eval "echo {${#PROMPT_COMMAND[*]}..1..-1}")
|
||||||
|
do
|
||||||
|
PROMPT_COMMAND[$i]=${PROMPT_COMMAND[$((i-1))]}
|
||||||
|
done
|
||||||
|
# Step 2.2: Assign the first element.
|
||||||
|
PROMPT_COMMAND[0]=__eat_before_prompt_command
|
||||||
|
}
|
||||||
|
|
||||||
|
# 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: bash
|
||||||
|
# End:
|
||||||
82
eat/.emacs.d/elpa/eat-0.8/integration/zsh
Normal file
82
eat/.emacs.d/elpa/eat-0.8/integration/zsh
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
# integration/zsh --- Zsh integration
|
||||||
|
|
||||||
|
# Copyright (C) 2022, 2023 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" "$HOST" | 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:
|
||||||
BIN
eat/.terminfo/65/eat-256color
Normal file
BIN
eat/.terminfo/65/eat-256color
Normal file
Binary file not shown.
BIN
eat/.terminfo/65/eat-color
Normal file
BIN
eat/.terminfo/65/eat-color
Normal file
Binary file not shown.
BIN
eat/.terminfo/65/eat-mono
Normal file
BIN
eat/.terminfo/65/eat-mono
Normal file
Binary file not shown.
BIN
eat/.terminfo/65/eat-truecolor
Normal file
BIN
eat/.terminfo/65/eat-truecolor
Normal file
Binary file not shown.
BIN
eat/.terminfo/e/eat-256color
Normal file
BIN
eat/.terminfo/e/eat-256color
Normal file
Binary file not shown.
BIN
eat/.terminfo/e/eat-color
Normal file
BIN
eat/.terminfo/e/eat-color
Normal file
Binary file not shown.
BIN
eat/.terminfo/e/eat-mono
Normal file
BIN
eat/.terminfo/e/eat-mono
Normal file
Binary file not shown.
BIN
eat/.terminfo/e/eat-truecolor
Normal file
BIN
eat/.terminfo/e/eat-truecolor
Normal file
Binary file not shown.
17
install-eat.sh
Normal file
17
install-eat.sh
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Install special files for the eat emacs terminal emulator.
|
||||||
|
# ama 2023
|
||||||
|
|
||||||
|
EAT_SHELL_INTEGRATION_DIR=~/.emacs.d/elpa/eat-0.8/integration
|
||||||
|
|
||||||
|
cp -r eat/* ~/
|
||||||
|
|
||||||
|
cat >>~/.bashrc <<-EOF
|
||||||
|
[ -e "$EAT_SHELL_INTEGRATION_DIR" ] \
|
||||||
|
&& source "$EAT_SHELL_INTEGRATION_DIR/bash"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat >>~/.zshrc <<-EOF
|
||||||
|
[ -e "$EAT_SHELL_INTEGRATION_DIR" ] \
|
||||||
|
&& source "$EAT_SHELL_INTEGRATION_DIR/zsh"
|
||||||
|
EOF
|
||||||
Loading…
Add table
Add a link
Reference in a new issue