Created
December 4, 2020 02:41
-
-
Save xiangchu0/e92d559ae731d97dc1fa6a0c011614ec to your computer and use it in GitHub Desktop.
emacs script
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 | |
# Open file on a remote Emacs server. | |
# https://andy.wordpress.com/2013/01/03/automatic-emacsclient/ with added sudo. | |
# /usr/local/bin/ecl -> ecc | |
# /usr/local/bin/ecr -> ecc | |
# /usr/local/bin/ecs -> ecc | |
EMACS_HOME=/1/emacs/bin/ | |
params=() | |
sudo=0 | |
local=0 | |
create=0 | |
remote=0 | |
echo $(basename $0) | |
case $(basename $0) in | |
"ecc") | |
create=1 | |
;; | |
"ecl") | |
local=1 | |
;; | |
"ecr") | |
remote=1 | |
;; | |
"ecs") | |
sudo=1 | |
;; | |
esac | |
if [ $create -eq 1 ]; then | |
$EMACS_HOME/emacsclient -n -c -f ~/.emacs.d/server/server | |
exit 0 | |
fi | |
for p in "${@}"; do | |
if [[ "${p:0:1}" == "+" ]]; then | |
params+=( "${p}" ) | |
else | |
# Setting field separator to newline so that filenames with spaces will | |
# not be split up into 2 array elements. | |
OLDIFS=${IFS} | |
IFS=$'\n' | |
if [ ${local} -eq 1 ]; then | |
params+=($(realpath -m "${p}") ) | |
elif [ ${sudo} -eq 1 ]; then | |
params+=( "/sudo:localhost:"$(realpath -m "${p}") ) | |
else | |
params+=( "/ssh:$(hostname -f):"$(realpath "${p}") ) | |
fi | |
IFS=${OLDIFS} | |
fi | |
done | |
$EMACS_HOME/emacsclient -n -f ~/.emacs.d/server/server "${params[@]}" |
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 | |
LC_CTYPE=zh_CN.UTF-8 emacs --daemon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment