Add shell integration script for GNU Bash

* integration/bash: New file.
* eat.el (eat-term-shell-integration-directory): New variable.
Contains path to the directory containing the scripts,
automatically updated when Eat is updated.
* eat.el (eat-exec, eat-eshell-mode): New enviroment variable
'EAT_SHELL_INTEGRATION_DIR'.
* eat.texi (Shell Integration): New chapter.
* eat.texi (Directory Tracking): Refer to 'Shell Integration'.
This commit is contained in:
Akib Azmain Turja 2022-12-03 11:14:01 +06:00
parent 5f4f4a87d1
commit d918dbae87
No known key found for this signature in database
GPG key ID: 5535FCF54D88616B
3 changed files with 54 additions and 7 deletions

24
eat.el
View file

@ -255,6 +255,7 @@ This value is used by terminal programs to identify the terminal."
"Path to directory where Eat is installed.")
(defvar eat-term-terminfo-directory)
(defvar eat-term-shell-integration-directory)
(let ((old-install-path eat--install-path))
(setq eat--install-path
(copy-sequence
@ -262,15 +263,27 @@ This value is used by terminal programs to identify the terminal."
buffer-file-name))))
(defcustom eat-term-terminfo-directory eat--install-path
"Directory where require terminfo databases can be found.
"Directory where required terminfo databases can be found.
This value is used by terminal programs to find the terminfo databases
that describe the capabilities of the terminal."
:type 'directory
:group 'eat-term)
(defcustom eat-term-shell-integration-directory
(expand-file-name "integration" eat--install-path)
"Directory where Eat shell integration scripts can be found.
This value is exposed to terminal programs as
`EAT_SHELL_INTEGRATION_DIR' environment variable."
:type 'directory
:group 'eat-ui
:group 'eat-eshell)
(when (eq eat-term-terminfo-directory old-install-path)
(setq eat-term-terminfo-directory eat--install-path)))
(setq eat-term-terminfo-directory eat--install-path
eat-term-shell-integration-directory
(expand-file-name "integration" eat--install-path))))
(defcustom eat-term-inside-emacs (format "%s,eat" emacs-version)
"Value for the `INSIDE_EMACS' environment variable."
@ -2212,7 +2225,6 @@ MODE should be one of nil and `x10', `normal', `button-event',
URL should be a URL in the format \"file://HOST/CWD/\"; HOST can be
empty."
(message "%S" url)
(let ((obj (url-generic-parse-url url)))
(when (and (string= (url-type obj) "file")
(or (null (url-host obj))
@ -4563,7 +4575,9 @@ same Eat buffer. The hook `eat-exec-hook' is run after each exec."
(list
(concat "TERM=" (eat-term-name))
(concat "TERMINFO=" eat-term-terminfo-directory)
(concat "INSIDE_EMACS=" eat-term-inside-emacs))
(concat "INSIDE_EMACS=" eat-term-inside-emacs)
(concat "EAT_SHELL_INTEGRATION_DIR="
eat-term-shell-integration-directory))
process-environment))
(process-connection-type t)
;; We should suppress conversion of end-of-line format.
@ -5103,6 +5117,8 @@ sane 2>%s ; if [ $1 = .. ]; then shift; fi; exec \"$@\""
`(("TERM" eat--eshell-term-name t)
("TERMINFO" eat-term-terminfo-directory t)
("INSIDE_EMACS" eat-term-inside-emacs t)
("EAT_SHELL_INTEGRATION_DIR"
eat-term-shell-integration-directory t)
,@eshell-variable-aliases-list))
(advice-add #'eshell-gather-process-output :around
#'eat--eshell-adjust-make-process-args))

View file

@ -71,6 +71,7 @@ Advanced Customizations
* Mouse Tracking:: Eat tracks mouse, but this can be changed.
* Clipboard:: Integrating kill ring with terminal.
* Directory Tracking:: Tracking the working directory of program.
* Shell Integration:: Getting the most from Eat and your shell.
* Colors:: Eat can show more than sixteen million colors.
* Fonts:: Eat can show up to sixty font different fonts.
* Blinking Text:: Annoying blinking texts.
@ -486,9 +487,10 @@ directory is changed back to the directory from where the program was
invoked.
To track, Eat needs the program to send this information. So, to
enable directory tracking, you'll need to setup your shell. You'll
need to arrange that your shell sends appropriate escape sequence at
each prompt, for example with the command:
enable directory tracking, you'll need to setup your shell
(@pxref{Shell Integration}). You'll need to arrange that your shell
sends appropriate escape sequence at each prompt, for example with the
command:
@example
printf "\\e]7;file://%s%s\\e\\\\" "$HOSTNAME" "$PWD"
@ -503,6 +505,24 @@ This controls directory tracking. When set to non-@code{nil}, Eat
tracks the current working directory of programs.
@end defopt
@node Shell Integration
@cindex shell integration
@cindex integration, shell
@chapter Shell Integration
Eat comes with shell scripts to integrate your favorite shell with
Eat. You can include the script in your shell configuration file,
it'll take care of everything.
Currently only GNU Bash is supported.
If you use GNU Bash, put the following in your @samp{.bashrc} file:
@example
[ -n "$EAT_SHELL_INTEGRATION_DIR" ] && \
source "$EAT_SHELL_INTEGRATION_DIR/bash"
@end example
@node Colors
@cindex colors
@cindex customizing colors

11
integration/bash Normal file
View file

@ -0,0 +1,11 @@
function _eat_prompt_command () {
# Send the current working directory, for directory tracking.
printf "\\e]7;file://%s%s\\e\\\\" "$HOSTNAME" "$PWD"
}
# Add '_eat_prompt_command' as the last element of 'PROMPT_COMMAND'.
PROMPT_COMMAND[${#PROMPT_COMMAND[*]}]=_eat_prompt_command
# Local Variables:
# mode: sh
# End: