Rework emacsclient and fix direnv

Signed-off-by: Magic_RB <magic_rb@redalder.org>
This commit is contained in:
Magic_RB 2021-06-10 20:37:59 +02:00
parent e374a3324a
commit 218d8a6417
No known key found for this signature in database
GPG key ID: 08D5287CC5DDCA0E

View file

@ -16,37 +16,43 @@ alias cat='@bat@/bin/bat'
export PS1="\u@\[\e[37m\]\h\[\e[m\]:\[\e[32m\]\w\[\e[m\]\[\e[31m\]\\$\[\e[m\] " export PS1="\u@\[\e[37m\]\h\[\e[m\]:\[\e[32m\]\w\[\e[m\]\[\e[31m\]\\$\[\e[m\] "
EMACSCLIENT="`command -v -- emacsclient >/dev/null 2>&1 && printf emacsclient || printf emacsclient-$(uname -m)`" emacsclient() {
E() { if [[ -e "$HOME/.ssh/emacs-server" ]] ; then
if [[ ! -z "${INSIDE_EMACS+x}" ]] && [[ ! -z "${SSH_CONNECTION+x}" ]]
then params=()
emacsclient-remote --sudo "$1" sudo=0
elif [[ ! -z "${INSIDE_EMACS}" ]] nowait=0
then
"${EMACSCLIENT}" -a emacs "/sudo::/${1}" host=$(echo $SSH_CONNECTION | cut -d' ' -f3)
port=$(echo $SSH_CONNECTION | cut -d' ' -f4)
for p in "${@}"; do
if [[ "${p}" == "-s" || "${p}" == "--sudo" ]]; then
sudo=1
elif [[ "${p}" == "-n" || "${p}" == "--no-wait" ]]; then
params+=( "-nowait" )
else
if [[ ${sudo} -eq 1 ]]; then
params+=( "-file /ssh:${USER}@${host}#${port}|sudo::"$(realpath -m "${p}") )
else
params+=( "-file /ssh:${USER}@${host}#${port}:"$(realpath "${p}") )
fi
fi
done
if [[ ${nowait} -eq 0 ]] ; then
printf 'Waiting for Emacs...\n'
fi
echo "${params[@]}" | nc -U "$HOME/.ssh/emacs-server" >/dev/null 2>&1
else else
"${EMACSCLIENT}" -t -a emacs "/sudo::/${1}" env emacsclient "${@}"
fi
}
e() {
if [[ ! -z "${INSIDE_EMACS+x}" ]] && [[ ! -z "${SSH_CONNECTION+x}" ]]
then
emacsclient-remote "$1"
elif [[ ! -z "${INSIDE_EMACS}" ]]
then
"${EMACSCLIENT}" -a emacs "${1}"
else
"${EMACSCLIENT}" -t -a emacs "${1}"
fi fi
} }
alias e='emacsclient'
alias E='emacsclient -s'
[[ ! -z "${INSIDE_EMACS+x}" ]] && alias vim="e"
if [[ "@direnvEnabled@" == "true" ]] ; then
eval "$(direnv hook bash)"
fi
## Set prompt ## Set prompt
@ -66,3 +72,7 @@ if [[ "$INSIDE_EMACS" = 'vterm' ]] \
&& [[ -f ${EMACS_VTERM_PATH}/etc/emacs-vterm-bash.sh ]]; then && [[ -f ${EMACS_VTERM_PATH}/etc/emacs-vterm-bash.sh ]]; then
source ${EMACS_VTERM_PATH}/etc/emacs-vterm-bash.sh source ${EMACS_VTERM_PATH}/etc/emacs-vterm-bash.sh
fi fi
if [[ "@direnvEnabled@" == "true" ]] ; then
eval "$(direnv hook bash)"
fi