Skip to content

Instantly share code, notes, and snippets.

@shayelkin
Created December 10, 2025 22:09
Show Gist options
  • Select an option

  • Save shayelkin/1e93befcb7674f1a8832f0bf27d366ad to your computer and use it in GitHub Desktop.

Select an option

Save shayelkin/1e93befcb7674f1a8832f0bf27d366ad to your computer and use it in GitHub Desktop.
Runs emacsclient on the host the current user is physically sitting at
function ec -d 'Runs emacsclient on the host the current user is physically sitting at'
if test -z $argv
echo "Error: at least one argument is required"
return 1
end
set -l origin (echo "$SSH_CLIENT" | awk '{print $1}')
if test -z $origin
echo "Could not find remote host, using local emacsclient"
emacsclient $argv
return $status
end
# Needs a login shell (-l), so PATH would be evaluated, as the emacsclient binary
# location can differ.
set -l remote_cmd 'sh -l -c "'
set -a remote_cmd 'emacsclient -T "/ssh:$(echo $SSH_CLIENT | awk \'{print $1}\'):"'
# Rewrite files in argv to their full path, as expansion would be handled on the remote
for arg in $argv
if test -e $arg
set -a remote_cmd (realpath $arg)
else
set -a remote_cmd $arg
end
end
set -a remote_cmd '"'
echo "Running $remote_cmd[2..-2] on $origin"
ssh $origin $remote_cmd
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment