Skip to content

Commit 864f014

Browse files
committed
Add vterm_cmd to etc/shells
1 parent 216f266 commit 864f014

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ For `fish`, put this in your `~/.config/fish/config.fish`:
456456
function vterm_prompt_end;
457457
vterm_printf '51;A'(whoami)'@'(hostname)':'(pwd)
458458
end
459-
functions -c fish_prompt vterm_old_fish_prompt
459+
functions --copy fish_prompt vterm_old_fish_prompt
460460
function fish_prompt --description 'Write out the prompt; do not replace this. Instead, put this at end of your file.'
461461
# Remove the trailing newline from the original prompt. This is done
462462
# using the string builtin from fish, but to make sure any escape codes
@@ -510,7 +510,7 @@ vterm_cmd() {
510510
```
511511
`fish`:
512512
```sh
513-
function vterm_cmd --description 'Run an emacs command that\'s been defined in vterm-eval-cmds'
513+
function vterm_cmd --description 'Run an emacs command among the ones been defined in vterm-eval-cmds.'
514514
set -l vterm_elisp ()
515515
for arg in $argv
516516
set -a vterm_elisp (printf '"%s" ' (string replace -a -r '([\\\\"])' '\\\\\\\\$1' $arg))

etc/emacs-vterm-bash.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
2525
}
2626
fi
2727

28+
# With vterm_cmd you can execute Emacs commands directly from the shell.
29+
# For example, vterm_cmd message "HI" will print "HI".
30+
# To enable new commands, you have to customize Emacs's variable
31+
# vterm-eval-cmds.
32+
vterm_cmd() {
33+
local vterm_elisp
34+
vterm_elisp=""
35+
while [ $# -gt 0 ]; do
36+
vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")"
37+
shift
38+
done
39+
vterm_printf "51;E$vterm_elisp"
40+
}
41+
2842
# This is to change the title of the buffer based on information provided by the
2943
# shell. See, http://tldp.org/HOWTO/Xterm-Title-4.html, for the meaning of the
3044
# various symbols.

etc/emacs-vterm-zsh.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ if [[ "$INSIDE_EMACS" = 'vterm' ]]; then
2222
alias clear='vterm_printf "51;Evterm-clear-scrollback";tput clear'
2323
fi
2424

25+
# With vterm_cmd you can execute Emacs commands directly from the shell.
26+
# For example, vterm_cmd message "HI" will print "HI".
27+
# To enable new commands, you have to customize Emacs's variable
28+
# vterm-eval-cmds.
29+
vterm_cmd() {
30+
local vterm_elisp
31+
vterm_elisp=""
32+
while [ $# -gt 0 ]; do
33+
vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")"
34+
shift
35+
done
36+
vterm_printf "51;E$vterm_elisp"
37+
}
38+
2539
# This is to change the title of the buffer based on information provided by the
2640
# shell. See, http://tldp.org/HOWTO/Xterm-Title-4.html, for the meaning of the
2741
# various symbols.

etc/emacs-vterm.fish

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ function fish_title
3434
pwd
3535
end
3636

37+
# With vterm_cmd you can execute Emacs commands directly from the shell.
38+
# For example, vterm_cmd message "HI" will print "HI".
39+
# To enable new commands, you have to customize Emacs's variable
40+
# vterm-eval-cmds.
41+
function vterm_cmd --description 'Run an Emacs command among the ones defined in vterm-eval-cmds.'
42+
set -l vterm_elisp ()
43+
for arg in $argv
44+
set -a vterm_elisp (printf '"%s" ' (string replace -a -r '([\\\\"])' '\\\\\\\\$1' $arg))
45+
end
46+
vterm_printf '51;E'(string join '' $vterm_elisp)
47+
end
48+
3749
# Sync directory and host in the shell with Emacs's current directory.
3850
# You may need to manually specify the hostname instead of $(hostname) in case
3951
# $(hostname) does not return the correct string to connect to the server.
@@ -43,7 +55,9 @@ end
4355
function vterm_prompt_end;
4456
vterm_printf '51;A'(whoami)'@'(hostname)':'(pwd)
4557
end
46-
functions -c fish_prompt vterm_old_fish_prompt
58+
59+
# We are going to add a portion to the prompt, so we copy the old one
60+
functions --copy fish_prompt vterm_old_fish_prompt
4761

4862
function fish_prompt --description 'Write out the prompt; do not replace this. Instead, put this at end of your file.'
4963
# Remove the trailing newline from the original prompt. This is done

0 commit comments

Comments
 (0)