config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

emacs-vterm-zsh.sh (2100B)


      1 # Some of the most useful features in emacs-libvterm require shell-side
      2 # configurations. The main goal of these additional functions is to enable the
      3 # shell to send information to `vterm` via properly escaped sequences. A
      4 # function that helps in this task, `vterm_printf`, is defined below.
      5 
      6 function vterm_printf(){
      7     if [ -n "$TMUX" ] && ([ "${TERM%%-*}" = "tmux" ] || [ "${TERM%%-*}" = "screen" ] ); then
      8         # Tell tmux to pass the escape sequences through
      9         printf "\ePtmux;\e\e]%s\007\e\\" "$1"
     10     elif [ "${TERM%%-*}" = "screen" ]; then
     11         # GNU screen (screen, screen-256color, screen-256color-bce)
     12         printf "\eP\e]%s\007\e\\" "$1"
     13     else
     14         printf "\e]%s\e\\" "$1"
     15     fi
     16 }
     17 
     18 # Completely clear the buffer. With this, everything that is not on screen
     19 # is erased.
     20 if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
     21     alias clear='vterm_printf "51;Evterm-clear-scrollback";tput clear'
     22 fi
     23 
     24 # With vterm_cmd you can execute Emacs commands directly from the shell.
     25 # For example, vterm_cmd message "HI" will print "HI".
     26 # To enable new commands, you have to customize Emacs's variable
     27 # vterm-eval-cmds.
     28 vterm_cmd() {
     29     local vterm_elisp
     30     vterm_elisp=""
     31     while [ $# -gt 0 ]; do
     32         vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")"
     33         shift
     34     done
     35     vterm_printf "51;E$vterm_elisp"
     36 }
     37 
     38 # This is to change the title of the buffer based on information provided by the
     39 # shell. See, http://tldp.org/HOWTO/Xterm-Title-4.html, for the meaning of the
     40 # various symbols.
     41 autoload -U add-zsh-hook
     42 add-zsh-hook -Uz chpwd (){ print -Pn "\e]2;%m:%2~\a" }
     43 
     44 # Sync directory and host in the shell with Emacs's current directory.
     45 # You may need to manually specify the hostname instead of $(hostname) in case
     46 # $(hostname) does not return the correct string to connect to the server.
     47 #
     48 # The escape sequence "51;A" has also the role of identifying the end of the
     49 # prompt
     50 vterm_prompt_end() {
     51     vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"
     52 }
     53 setopt PROMPT_SUBST
     54 PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'