Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/colonelpanic8/term-manager

Manage ansi-term buffers using projectile
https://github.com/colonelpanic8/term-manager

Last synced: about 2 months ago
JSON representation

Manage ansi-term buffers using projectile

Awesome Lists containing this project

README

        

term-manager [[http://melpa.org/#/term-manager][file:http://melpa.org/packages/term-manager-badge.svg]] [[https://stable.melpa.org/#/term-manager][file:https://stable.melpa.org/packages/term-manager-badge.svg]]

term-projectile [[http://melpa.org/#/term-projectile][file:http://melpa.org/packages/term-projectile-badge.svg]]
[[https://stable.melpa.org/#/term-projectile][file:https://stable.melpa.org/packages/term-projectile-badge.svg]]

* About
~term-projectile~ manages terminals in groups based on the current projectile context. With a single keystroke, it will either create a new terminal for the current project, or take you to one that already exists. If more than one terminal exists for your project, it will let you easily cycle through those existing terminals. ~term-manager~ is used to support ~term-projectile~, though it can theoretically be used without ~term-projectile~.
* Installation
Install from MELPA with ~M-x package-install term-projectile~. See the [[https://github.com/milkypostman/melpa][melpa repository]] for details about how to set up MELPA if you have not already done so.
* Setup
** Emacs Configuration
The author ([[http://ivanmalison.github.io/dotfiles/#termprojectile][config here]]) prefers to set up term-projectile using the following (now quite complicated) [[https://github.com/abo-abo/hydra][hydra]]:
#+BEGIN_SRC emacs-lisp
(defun imalison:maybe-symbol-name (arg)
(if (symbolp arg)
(symbol-name arg)
arg))

(defun imalison:concat-symbols (&rest args)
(intern (mapconcat 'imalison:maybe-symbol-name args "")))

(defvar imalison:term-hydra-original-default-directory)

(defhydra imalison:term-hydra-default-directory
(:body-pre
(term-projectile-default-directory-forward-restored))
"term - default-directory"
("f" term-projectile-default-directory-forward-restored)
("b" term-projectile-default-directory-backward-restored)
("c" term-projectile-default-directory-create-new-restored)
("d" term-projectile-default-directory-forward-restored)
("g" imalison:term-hydra-global/body-restored :exit t)
("p" imalison:term-hydra-projectile/body-restored :exit t))

(defhydra imalison:term-hydra-projectile
(:body-pre
(progn
(term-projectile-forward-restored)))
"term - projectile"
("f" term-projectile-forward-restored)
("b" term-projectile-backward-restored)
("c" term-projectile-create-new-restored)
("d" imalison:term-hydra-default-directory/body-restored :exit t)
("g" imalison:term-hydra-global/body-restored :exit t)
("p" term-projectile-forward-restored))

(defhydra imalison:term-hydra-global
(:body-pre
(progn (setq imalison:term-hydra-original-default-directory
default-directory)
(term-projectile-global-forward-restored)))
"term - global"
("f" term-projectile-global-forward-restored)
("b" term-projectile-global-backward-restored)
("c" term-projectile-global-create-new-restored)
("d" imalison:term-hydra-default-directory/body-restored :exit t)
("g" term-projectile-global-forward-restored)
("p" imalison:term-hydra-projectile/body-restored :exit t))

(mapcar (lambda (term-projectile-function)
(defalias (imalison:concat-symbols term-projectile-function '-restored)
(lambda (&rest args)
(interactive)
(let ((default-directory imalison:term-hydra-original-default-directory))
(apply term-projectile-function args)))))
'(term-projectile-default-directory-forward
term-projectile-default-directory-backward
term-projectile-default-directory-create-new
term-projectile-forward
term-projectile-backward
term-projectile-create-new
term-projectile-global-forward
term-projectile-global-backward
term-projectile-global-create-new
imalison:term-hydra-global/body
imalison:term-hydra-projectile/body
imalison:term-hydra-default-directory/body))
#+END_SRC

When term-projectile-forward is executed in a projectile project where no terminal currently exists, a new ansi-term instance will be created. If one already exists, pressing that key binding will take the user to the existing ansi-term instance for that project.

** Terminal Support
To get automatic directory changing You will need to add something like the
following to your shell's configuration file, along with the snippet from one of
the headings below that corresponds to your shell of choice.
#+BEGIN_SRC sh
function environment_variable_exists {
eval "value=\"\${$1+x}\""
[ ! -z $value ]
}

function emacs_ansi_term_support {
echo -e "\033AnSiTu" "$LOGNAME" # $LOGNAME is more portable than using whoami.
echo -e "\033AnSiTc" "$(pwd)"
if [ $(uname) = "SunOS" ]; then
# The -f option does something else on SunOS and is not needed anyway.
hostname_options="";
else
hostname_options="-f";
fi
# XXX/TODO: This disables correct setting of the current directory
# when in an sshed shell when inside of emacs
# echo -e "\033AnSiTh" "$(hostname $hostname_options)" # Using the -f option can #
# cause problems on some OSes.
}
#+END_SRC
*** zsh
#+BEGIN_SRC sh
if environment_variable_exists INSIDE_EMACS; then
if [[ $INSIDE_EMACS == *"term"* ]]
then
add-zsh-hook precmd emacs_ansi_term_support
fi
fi
#+END_SRC
*** bash
#+BEGIN_SRC sh
if environment_variable_exists INSIDE_EMACS; then
if [[ $INSIDE_EMACS == *"term"* ]]
then
PROMPT_COMMAND='emacs_ansi_term_support'
fi
fi
#+END_SRC