dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

emacs-vterm-bash.sh (2117B)


      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     function clear(){
     22         vterm_printf "51;Evterm-clear-scrollback";
     23         tput clear;
     24     }
     25 fi
     26 
     27 # With vterm_cmd you can execute Emacs commands directly from the shell.
     28 # For example, vterm_cmd message "HI" will print "HI".
     29 # To enable new commands, you have to customize Emacs's variable
     30 # vterm-eval-cmds.
     31 vterm_cmd() {
     32     local vterm_elisp
     33     vterm_elisp=""
     34     while [ $# -gt 0 ]; do
     35         vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")"
     36         shift
     37     done
     38     vterm_printf "51;E$vterm_elisp"
     39 }
     40 
     41 # This is to change the title of the buffer based on information provided by the
     42 # shell. See, http://tldp.org/HOWTO/Xterm-Title-4.html, for the meaning of the
     43 # various symbols.
     44 PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND; }"'echo -ne "\033]0;${HOSTNAME}:${PWD}\007"'
     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 PS1=$PS1'\[$(vterm_prompt_end)\]'