From c7b1d83a36ff7451f0759dd30faa4242e71468e3 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 16 Apr 2014 03:06:21 -0400 Subject: improve emacs/bash integration --- .config/bash/rc.d/emacs.sh | 135 ++++++++++++++++++++++++++++++++------------- 1 file changed, 96 insertions(+), 39 deletions(-) diff --git a/.config/bash/rc.d/emacs.sh b/.config/bash/rc.d/emacs.sh index 9c1bf4d..165d71e 100644 --- a/.config/bash/rc.d/emacs.sh +++ b/.config/bash/rc.d/emacs.sh @@ -1,41 +1,98 @@ #!/bin/bash -case "$TERM" in - eterm*) - SELECTED_EDITOR='emacsclient' - EDITOR=$SELECTED_EDITOR - VISUAL=$SELECTED_EDITOR - export SELECTED_EDITOR EDITOR VISUAL - # The following uses the variable _EMACS_BUFFER to store some state - _emacs_quote() { - local str="$*" - str="${str//\\/\\\\}" - str="${str//\"/\\\"}" - str="\"${str}\"" - printf '%s' "$str" - } - _emacs_rename_terminal() { - local name="$(_emacs_quote "$(_emacs_get_desired_buffer_name)")" - if [[ -n $_EMACS_BUFFER ]]; then - local buffer="(get-buffer $_EMACS_BUFFER)" - else - local buffer='(window-buffer (selected-window))' - fi - _EMACS_BUFFER="$(emacsclient -e "(with-current-buffer ${buffer} (rename-buffer ${name} t)))" 2>/dev/null)" - } - _emacs_get_short_cwd() { - local base=$1 - local suffix='' - if [[ $base =~ (/(src|pkg|doc|pkg-libre|src-libre|trunk|tags|branches))*$ ]]; then - suffix=$BASH_REMATCH - base=${base%$suffix} - fi - base=${base##*/} - echo ${base}${suffix} - } - _emacs_get_desired_buffer_name() { - echo "*ansi-term*<$(_emacs_get_short_cwd "$PWD")>" - } - PROMPT_COMMAND='_emacs_rename_terminal "$(_emacs_get_desired_buffer_name)"' - :;; -esac +if [[ $TERM == eterm* ]]; then + SELECTED_EDITOR='emacsclient' + EDITOR=$SELECTED_EDITOR + VISUAL=$SELECTED_EDITOR + export SELECTED_EDITOR EDITOR VISUAL + + ## Primatives for interacting with Emacs ############################### + + # _emacs_run LISP + _emacs_run() { + emacsclient -e "$*" 2>/dev/null + } + # _emacs_quote UNQUOTED_STRING + _emacs_quote() { + local str="$*" + str="${str//\\/\\\\}" # \ -> \\ + str="${str//\"/\\\"}" # " -> \" + str="\"${str}\"" # wrap it in quotes + printf '%s' "$str" + } + # _emacs_unquote QUOTED_STRING + _emacs_unquote() { + + local str="$*" + if [[ $str =~ ^\"(.*)\"$ ]]; then + str=${BASH_REMATCH[1]} # un-quote it + str="${str//\\\\/\\}" # \\ -> \ + str="${str//\\\"/\"}" # \" -> " + fi + printf '%s' "$str" + } + + ## Deal with renaming the terminal ##################################### + + # _emacs_rename_terminal NEW_BUFFER_NAME + # This function uses the variable _EMACS_BUFFER to store some state + _emacs_rename_terminal() { + local name=$(_emacs_quote "$*") + if [[ -n $_EMACS_BUFFER ]]; then + local buffer="(get-buffer $_EMACS_BUFFER)" + else + local buffer='(window-buffer (selected-window))' + fi + _EMACS_BUFFER=$(_emacs_run "(with-current-buffer ${buffer} (rename-buffer ${name} t))") + } + # _emacs_get_short_cwd + _emacs_get_short_cwd() { + local base=$PWD + local suffix='' + # The regex here is a list of directory names + # that aren't really helpful, and that the + # parent directory should be included also. + if [[ $base =~ (/(src|pkg|doc|pkg-libre|src-libre|trunk|tags|branches))*$ ]]; then + suffix=$BASH_REMATCH + base=${base%$suffix} + fi + base=${base##*/} + echo ${base}${suffix} + } + # _emacs_get_desired_buffer_name + _emacs_get_desired_buffer_name() { + echo "*ansi-term*<$(_emacs_get_short_cwd)>" + } + + ## High-level tasks #################################################### + + # Like uniquify on the buffer name (shell -> emacs) + _emacs_set_buffer_name() { + # This doesn't work correctly on remote hosts. + # The "correct" solution is probably to hook into + # default-directory being set in term.el + _emacs_rename_terminal "$(_emacs_get_desired_buffer_name)" + } + # Set the TRAMP directory for remote hosts (shell -> emacs) + _emacs_set_remote_dir() { + if [[ -n $SSH_CONNECTION ]]; then + printf '\eAnSiT%s %s\n' \ + u "$USER" \ + c "$PWD" \ + h "$HOSTNAME" + fi + } + # Set the shell's X11 display (emacs -> shell) + _emacs_set_shell_DISPLAY() { + export DISPLAY=$(_emacs_unquote "$(_emacs_run "(cdr (assoc 'display (frame-parameters)))")") + } + + ## Do those things ##################################################### + + _emacs_PROMPT_COMMAND() { + _emacs_set_buffer_name + _emacs_set_remote_dir + _emacs_set_shell_DISPLAY + } + PROMPT_COMMAND=_emacs_PROMPT_COMMAND +fi -- cgit v1.2.3-2-g168b From 2a7c3a704093cc9008c8f5cbf026713ba8192a48 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 16 Apr 2014 03:06:46 -0400 Subject: bash: alias userctl='systemctl --user' --- .config/bash/aliases.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.config/bash/aliases.sh b/.config/bash/aliases.sh index aabd073..c9a1987 100644 --- a/.config/bash/aliases.sh +++ b/.config/bash/aliases.sh @@ -40,6 +40,7 @@ alias l='ls -CF' alias tree='tree --charset utf8' alias cd=pushd alias gitk='gitk --all --date-order' +alias userctl='systemctl --user' ###################################################################### # Remember lat/long for redshift # -- cgit v1.2.3-2-g168b From 6a9d6a88f21ef48464905f0ed4135d868704846d Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 16 Apr 2014 03:08:41 -0400 Subject: do away with ~/.sessions --- .config/login.sh | 11 +++++------ .config/ssh/config | 2 +- .config/systemd/user/default.target.wants/gpg-agent.service | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.config/login.sh b/.config/login.sh index 3c29c99..c28ca17 100644 --- a/.config/login.sh +++ b/.config/login.sh @@ -28,8 +28,7 @@ export TMPDIR="$HOME/tmp" # XDG ################################################################ . "$HOME/.local/lib/xdg.sh" -mkdir -p -- "$XDG_RUNTIME_DIR/sessions" -ln -sfT -- "$XDG_RUNTIME_DIR/sessions" ~/.sessions +ln -sfT -- "$XDG_RUNTIME_DIR" ~/.runtime # Settings ########################################################### @@ -52,10 +51,10 @@ if [[ -z $GPGKEY ]] && [[ -f "${HOME}/.gnupg/gpg.conf" ]]; then echo 'login: Setting GPGKEY' export GPGKEY=`sed -nr 's/^\s*default-key\s+//p' "${HOME}/.gnupg/gpg.conf"` fi -if [[ -f ~/.sessions/gpg ]]; then +if [[ -f ~/.runtime/gpg ]]; then echo 'login: Setting gpg-agent info:' - cat ~/.sessions/gpg - . ~/.sessions/gpg + cat ~/.runtime/gpg + . ~/.runtime/gpg export GPG_AGENT_INFO #export SSH_AUTH_SOCK fi @@ -73,7 +72,7 @@ export _JAVA_OPTIONS # X11 if [[ -z $XAUTHORITY ]]; then #export XAUTHORITY="$HOME/.Xauthority" - export XAUTHORITY=$HOME/.sessions/Xauthority + export XAUTHORITY=$HOME/.runtime/Xauthority fi # D-Bus diff --git a/.config/ssh/config b/.config/ssh/config index b6e53d6..9b366ed 100644 --- a/.config/ssh/config +++ b/.config/ssh/config @@ -1,7 +1,7 @@ Host * Protocol 2 ControlMaster auto - ControlPath ~/.sessions/ssh-%r@%h:%p + ControlPath ~/.runtime/ssh-%r@%h:%p Compression yes Host lore diff --git a/.config/systemd/user/default.target.wants/gpg-agent.service b/.config/systemd/user/default.target.wants/gpg-agent.service index a9de9b2..93c12b0 100644 --- a/.config/systemd/user/default.target.wants/gpg-agent.service +++ b/.config/systemd/user/default.target.wants/gpg-agent.service @@ -3,7 +3,7 @@ Description="GnuPG agent daemon" [Service] Type=forking -ExecStart=/usr/bin/gpg-agent --daemon --write-env-file ${HOME}/.sessions/gpg +ExecStart=/usr/bin/gpg-agent --daemon --write-env-file ${XDG_RUNTIME_DIR}/gpg [Install] WantedBy=default.target -- cgit v1.2.3-2-g168b From 3462bc3b8b0c3ceef23c68829147795ae42b8c45 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 16 Apr 2014 03:09:20 -0400 Subject: launch clipit to sync clipboards --- .config/wmii-hg/autostart | 1 + 1 file changed, 1 insertion(+) diff --git a/.config/wmii-hg/autostart b/.config/wmii-hg/autostart index 9c47a9d..cd040b3 100755 --- a/.config/wmii-hg/autostart +++ b/.config/wmii-hg/autostart @@ -5,6 +5,7 @@ daemon xcompmgr &> /dev/null daemon lxpanel &> /dev/null daemon nm-applet &> /dev/null daemon dunst &> /dev/null +daemon clipit -dn &> /dev/null #Action rbar_cpu 01 & #Action rbar_wifi 97 & -- cgit v1.2.3-2-g168b From f6742e8302f615b75eb6a2dd4faf3b306be56012 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 21 Apr 2014 13:33:39 -0400 Subject: login.sh: leave .Xauthority in $HOME --- .config/login.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.config/login.sh b/.config/login.sh index c28ca17..e1650b2 100644 --- a/.config/login.sh +++ b/.config/login.sh @@ -71,8 +71,8 @@ export _JAVA_OPTIONS # X11 if [[ -z $XAUTHORITY ]]; then - #export XAUTHORITY="$HOME/.Xauthority" - export XAUTHORITY=$HOME/.runtime/Xauthority + export XAUTHORITY="$HOME/.Xauthority" + #export XAUTHORITY=$HOME/.runtime/Xauthority fi # D-Bus -- cgit v1.2.3-2-g168b