diff options
| author | Gabriele Bozzola <sbozzolator@gmail.com> | 2020-09-06 17:08:30 -0700 |
|---|---|---|
| committer | Gabriele Bozzola <sbozzolator@gmail.com> | 2020-09-06 17:08:30 -0700 |
| commit | 864f014de75686f55b64bf15d690d2875eb20ad7 (patch) | |
| tree | 034f231604791f168db7a6fa62af285fe216e0b7 | |
| parent | 216f2662d4967170c7273618078fb098b3c55f0e (diff) | |
Add vterm_cmd to etc/shells
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | etc/emacs-vterm-bash.sh | 14 | ||||
| -rw-r--r-- | etc/emacs-vterm-zsh.sh | 14 | ||||
| -rw-r--r-- | etc/emacs-vterm.fish | 16 |
4 files changed, 45 insertions, 3 deletions
@@ -456,7 +456,7 @@ For `fish`, put this in your `~/.config/fish/config.fish`: function vterm_prompt_end; vterm_printf '51;A'(whoami)'@'(hostname)':'(pwd) end -functions -c fish_prompt vterm_old_fish_prompt +functions --copy fish_prompt vterm_old_fish_prompt function fish_prompt --description 'Write out the prompt; do not replace this. Instead, put this at end of your file.' # Remove the trailing newline from the original prompt. This is done # using the string builtin from fish, but to make sure any escape codes @@ -510,7 +510,7 @@ vterm_cmd() { ``` `fish`: ```sh -function vterm_cmd --description 'Run an emacs command that\'s been defined in vterm-eval-cmds' +function vterm_cmd --description 'Run an emacs command among the ones been defined in vterm-eval-cmds.' set -l vterm_elisp () for arg in $argv set -a vterm_elisp (printf '"%s" ' (string replace -a -r '([\\\\"])' '\\\\\\\\$1' $arg)) diff --git a/etc/emacs-vterm-bash.sh b/etc/emacs-vterm-bash.sh index 395188b..15bf353 100644 --- a/etc/emacs-vterm-bash.sh +++ b/etc/emacs-vterm-bash.sh @@ -25,6 +25,20 @@ if [[ "$INSIDE_EMACS" = 'vterm' ]]; then } 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. diff --git a/etc/emacs-vterm-zsh.sh b/etc/emacs-vterm-zsh.sh index 7708cc2..b01f52d 100644 --- a/etc/emacs-vterm-zsh.sh +++ b/etc/emacs-vterm-zsh.sh @@ -22,6 +22,20 @@ 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. diff --git a/etc/emacs-vterm.fish b/etc/emacs-vterm.fish index 6c9d205..25169a6 100644 --- a/etc/emacs-vterm.fish +++ b/etc/emacs-vterm.fish @@ -34,6 +34,18 @@ function fish_title pwd end +# 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. +function vterm_cmd --description 'Run an Emacs command among the ones defined in vterm-eval-cmds.' + set -l vterm_elisp () + for arg in $argv + set -a vterm_elisp (printf '"%s" ' (string replace -a -r '([\\\\"])' '\\\\\\\\$1' $arg)) + end + vterm_printf '51;E'(string join '' $vterm_elisp) +end + # 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. @@ -43,7 +55,9 @@ end function vterm_prompt_end; vterm_printf '51;A'(whoami)'@'(hostname)':'(pwd) end -functions -c fish_prompt vterm_old_fish_prompt + +# We are going to add a portion to the prompt, so we copy the old one +functions --copy fish_prompt vterm_old_fish_prompt function fish_prompt --description 'Write out the prompt; do not replace this. Instead, put this at end of your file.' # Remove the trailing newline from the original prompt. This is done |
