dotfiles

My dotfiles.
git clone git://git.ryanmj.xyz/dotfiles.git
Log | Files | Refs | LICENSE

emacs-vterm-zsh.sh (2185B)


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