diff --git a/emacs/.emacs.d/config/init-vterm.el b/emacs/.emacs.d/config/init-vterm.el index 4251773..bbdb5d6 100644 --- a/emacs/.emacs.d/config/init-vterm.el +++ b/emacs/.emacs.d/config/init-vterm.el @@ -6,7 +6,12 @@ (if (projectile-project-root) (call-interactively #'projectile-run-vterm) (call-interactively #'vterm))) + :config + (evil-collection-vterm-setup) :general - (leader-map "v" #'project-vterm)) + (leader-map "v" #'project-vterm) + :custom + (vterm-environment '("TYPEWRITTEN_CURSOR=terminal")) + (vterm-ignore-blink-cursor t)) (provide 'init-vterm) diff --git a/zsh/.zshrc b/zsh/.zshrc index 75b7589..56ed155 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -4,21 +4,7 @@ # Path to your oh-my-zsh installation. export ZSH="$HOME/.oh-my-zsh" -# Load up typewritten theme if it exists -if [[ -d "$HOME/typewritten" ]] -then - export TYPEWRITTEN_CURSOR="terminal" - fpath+=$HOME/typewritten - autoload -U promptinit; promptinit - prompt typewritten - ZSH_THEME="" -else - # Set name of the theme to load --- if set to "random", it will - # load a random theme each time oh-my-zsh is loaded, in which case, - # to know which specific one was loaded, run: echo $RANDOM_THEME - # See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes - ZSH_THEME="robbyrussell" -fi +ZSH_THEME="typewritten" # Set list of themes to pick from when loading at random # Setting this variable when ZSH_THEME=random will cause zsh to load @@ -80,7 +66,7 @@ fi # Custom plugins may be added to $ZSH_CUSTOM/plugins/ # Example format: plugins=(rails git textmate ruby lighthouse) # Add wisely, as too many plugins slow down shell startup. -plugins=(git direnv pyenv) +plugins=(git direnv pyenv npm nvm) source $ZSH/oh-my-zsh.sh @@ -114,3 +100,59 @@ alias k="kubectl" alias kns="kubens" alias kctx="kubectx" alias tf="terraform" + +# VTerm integration +# Some of the most useful features in emacs-libvterm require shell-side +# configurations. The main goal of these additional functions is to enable the +# shell to send information to `vterm` via properly escaped sequences. A +# function that helps in this task, `vterm_printf`, is defined below. + +function vterm_printf(){ + if [ -n "$TMUX" ] && ([ "${TERM%%-*}" = "tmux" ] || [ "${TERM%%-*}" = "screen" ] ); then + # Tell tmux to pass the escape sequences through + printf "\ePtmux;\e\e]%s\007\e\\" "$1" + elif [ "${TERM%%-*}" = "screen" ]; then + # GNU screen (screen, screen-256color, screen-256color-bce) + printf "\eP\e]%s\007\e\\" "$1" + else + printf "\e]%s\e\\" "$1" + fi +} + +# Completely clear the buffer. With this, everything that is not on screen +# is erased. +if [[ "$INSIDE_EMACS" = 'vterm' ]]; then + alias clear='vterm_printf "51;Evterm-clear-scrollback";tput clear' +fi + +# With vterm_cmd you can execute Emacs commands directly from the shell. +# For example, vterm_cmd message "HI" will print "HI". +# To enable new commands, you have to customize Emacs's variable +# vterm-eval-cmds. +vterm_cmd() { + local vterm_elisp + vterm_elisp="" + while [ $# -gt 0 ]; do + vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")" + shift + done + vterm_printf "51;E$vterm_elisp" +} + +# This is to change the title of the buffer based on information provided by the +# shell. See, http://tldp.org/HOWTO/Xterm-Title-4.html, for the meaning of the +# various symbols. +autoload -U add-zsh-hook +add-zsh-hook -Uz chpwd (){ print -Pn "\e]2;%m:%2~\a" } + +# Sync directory and host in the shell with Emacs's current directory. +# You may need to manually specify the hostname instead of $(hostname) in case +# $(hostname) does not return the correct string to connect to the server. +# +# The escape sequence "51;A" has also the role of identifying the end of the +# prompt +vterm_prompt_end() { + vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"; +} +setopt PROMPT_SUBST +PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'