dotemacs

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

emacs-vterm.fish (2632B)


      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 begin; [  -n "$TMUX" ]  ; and  string match -q -r "screen|tmux" "$TERM"; end 
      8         # tell tmux to pass the escape sequences through
      9         printf "\ePtmux;\e\e]%s\007\e\\" "$argv"
     10     else if string match -q -- "screen*" "$TERM"
     11         # GNU screen (screen, screen-256color, screen-256color-bce)
     12         printf "\eP\e]%s\007\e\\" "$argv"
     13     else
     14         printf "\e]%s\e\\" "$argv"
     15     end
     16 end
     17 
     18 # Completely clear the buffer. With this, everything that is not on screen
     19 # is erased.
     20 if [ "$INSIDE_EMACS" = 'vterm' ]
     21     function clear
     22         vterm_printf "51;Evterm-clear-scrollback";
     23         tput clear;
     24     end
     25 end
     26 
     27 # This is to change the title of the buffer based on information provided by the
     28 # shell. See, http://tldp.org/HOWTO/Xterm-Title-4.html, for the meaning of the
     29 # various symbols.
     30 function fish_title
     31     hostname
     32     echo ":"
     33     pwd
     34 end
     35 
     36 # With vterm_cmd you can execute Emacs commands directly from the shell.
     37 # For example, vterm_cmd message "HI" will print "HI".
     38 # To enable new commands, you have to customize Emacs's variable
     39 # vterm-eval-cmds.
     40 function vterm_cmd --description 'Run an Emacs command among the ones defined in vterm-eval-cmds.'
     41     set -l vterm_elisp ()
     42     for arg in $argv
     43         set -a vterm_elisp (printf '"%s" ' (string replace -a -r '([\\\\"])' '\\\\\\\\$1' $arg))
     44     end
     45     vterm_printf '51;E'(string join '' $vterm_elisp)
     46 end
     47 
     48 # Sync directory and host in the shell with Emacs's current directory.
     49 # You may need to manually specify the hostname instead of $(hostname) in case
     50 # $(hostname) does not return the correct string to connect to the server.
     51 #
     52 # The escape sequence "51;A" has also the role of identifying the end of the
     53 # prompt
     54 function vterm_prompt_end;
     55     vterm_printf '51;A'(whoami)'@'(hostname)':'(pwd)
     56 end
     57 
     58 # We are going to add a portion to the prompt, so we copy the old one
     59 functions --copy fish_prompt vterm_old_fish_prompt
     60 
     61 function fish_prompt --description 'Write out the prompt; do not replace this. Instead, put this at end of your file.'
     62     # Remove the trailing newline from the original prompt. This is done
     63     # using the string builtin from fish, but to make sure any escape codes
     64     # are correctly interpreted, use %b for printf.
     65     printf "%b" (string join "\n" (vterm_old_fish_prompt))
     66     vterm_prompt_end
     67 end