Last active
September 20, 2018 09:37
-
-
Save paxperscientiam/1bfb5bbc7a5cb1bfee05d300a43c0813 to your computer and use it in GitHub Desktop.
Querying and commanding an emacs daemon with nc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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