Skip to content

Instantly share code, notes, and snippets.

@paxperscientiam
Last active September 20, 2018 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save paxperscientiam/1bfb5bbc7a5cb1bfee05d300a43c0813 to your computer and use it in GitHub Desktop.
Save paxperscientiam/1bfb5bbc7a5cb1bfee05d300a43c0813 to your computer and use it in GitHub Desktop.
Querying and commanding an emacs daemon with nc
#!/usr/bin/env bash
# usage:
# message_daemon $'(length (frame-list))' /path/to/socketfile
# => 2
message_daemon () {
local result
local socket
local CMD="${1}"
if [[ "${#2}" -gt 0 ]]; then
socket="${2}"
read -r result < <(nc -U "${socket}" <<< \
$"-eval ${CMD// /&_}" | \
awk $'FNR == 2 {printf $2}')
printf '%s' "${result}"
return 0
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment