From df36ee94f81fcf33afcb56e7f25b11e4ca11ea83 Mon Sep 17 00:00:00 2001 From: Marcel Kapfer Date: Mon, 15 Mar 2021 10:10:14 +0100 Subject: [PATCH] [fish] Added script for dealing with Emacs vterm All credits go to akermu: https://github.com/akermu/emacs-libvterm --- shells/fish/conf.d/90-emacs-vterm.fish | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 shells/fish/conf.d/90-emacs-vterm.fish diff --git a/shells/fish/conf.d/90-emacs-vterm.fish b/shells/fish/conf.d/90-emacs-vterm.fish new file mode 100644 index 0000000..7f26825 --- /dev/null +++ b/shells/fish/conf.d/90-emacs-vterm.fish @@ -0,0 +1,40 @@ +function vterm_printf; + if [ -n "$TMUX" ] + # tell tmux to pass the escape sequences through + printf "\ePtmux;\e\e]%s\007\e\\" "$argv" + else if string match -q -- "screen*" "$TERM" + # GNU screen (screen, screen-256color, screen-256color-bce) + printf "\eP\e]%s\007\e\\" "$argv" + else + printf "\e]%s\e\\" "$argv" + end +end + +function vterm_prompt_end; + vterm_printf '51;A'(whoami)'@'(hostname)':'(pwd) +end +functions --copy fish_prompt vterm_old_fish_prompt +function fish_prompt --description 'Write out the prompt; do not replace this. Instead, put this at end of your file.' + # Remove the trailing newline from the original prompt. This is done + # using the string builtin from fish, but to make sure any escape codes + # are correctly interpreted, use %b for printf. + printf "%b" (string join "\n" (vterm_old_fish_prompt)) + vterm_prompt_end +end + +function vterm_cmd --description 'Run an Emacs command among the ones been defined in vterm-eval-cmds.' + set -l vterm_elisp () + for arg in $argv + set -a vterm_elisp (printf '"%s" ' (string replace -a -r '([\\\\"])' '\\\\\\\\$1' $arg)) + end + vterm_printf '51;E'(string join '' $vterm_elisp) +end + +function find_file + set -q argv[1]; or set argv[1] "." + vterm_cmd find-file (realpath "$argv") +end + +function say + vterm_cmd message "%s" "$argv" +end