Instantly share code, notes, and snippets.

Embed
What would you like to do?
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