complete-computing-environment/shell_vars.org

79 lines
2.8 KiB
Org Mode

:PROPERTIES:
:ID: 9ce3cedf-7f1b-45e0-aa12-e1bd7d739cbb
:END:
#+TITLE: Configuring Shell Variables
#+filetags: :Emacs:CCE:Shells:
#+PROPERTY: header-args :mkdirp yes :results none
#+PROPERTY: header-args:emacs-lisp :tangle shell-vars.el
#+PROPERTY: header-args:nix :tangle ~/arroyo-nix/hm/prompt.nix
#+ARROYO_MODULE_WANTS: cce/emacs_shell_mode_is_good_enough.org
#+ARROYO_EMACS_MODULE: shell-vars
#+CCE_PREDICATE: nil
#+CCE_PRIORITY: 40
#+AUTO_TANGLE: t
While [[id:configuring_profile_variables][Configuring Profile Variables]] concerns itself primarily with some basic configurations that goes in to =~/.bash_profile=, this document concerns itself with things that go in my =~/.bashrc=, things which are run by every new interactive bash shell process, rather than being run by the system once and inherited by sub-processes.
#+ARROYO_HOME_MODULE: hm/prompt.nix
#+begin_src nix :noweb yes
{ ... }:
{
programs.bash.enable = true;
#+end_src
I use [[id:20220906T101932.011701][Atuin]] for shell search history right now.
I cribbed my =PS1= from [[id:f4d0be16-1f68-4598-a02c-0327759e034c][Tor]] a long time ago, it is a simple on that simply puts a smiley-face if the previous command returned successfully, and a frown-face if the previous command returned an error-code.
#+begin_src nix :noweb yes
home.sessionVariables = {
PS1 = ''\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \[\033[00m\]\`if [ \$? == 0 ]; then echo \:\); else echo \:\(; fi\` $ '';
};
}
#+end_src
That =PS1= will prevent [[id:cce/emacs][Emacs]]'s command-interpreter ("comint") from working properly. One must set [[help:comint-prompt-regexp][comint-prompt-regexp]] to make it behave properly:
#+begin_src emacs-lisp
(defun cce/fixup-comint ()
(interactive)
(setq-local comint-prompt-regexp "^[^#$%>)(\n]*[#$%>)(] +"))
(add-hook 'shell-mode-hook #'cce/fixup-comint)
(provide 'cce/shell-vars)
#+end_src
Eshell "smart" mode
#+begin_src emacs-lisp
(require 'em-smart)
(setq eshell-where-to-jump 'begin)
(setq eshell-review-quick-commands nil)
(setq eshell-smart-space-goes-to-end t)
(evil-define-key 'insert 'eshell-mode-map (kbd "M-a") #'eshell-bol)
(defun eshell/lcd (&optional directory)
(if (file-remote-p default-directory)
(with-parsed-tramp-file-name default-directory nil
(eshell/cd (tramp-make-tramp-file-name
(tramp-file-name-method v)
(tramp-file-name-user v)
nil
(tramp-file-name-host v)
nil
(or directory "")
(tramp-file-name-hop v))))
(eshell/cd directory)))
#+end_src
Eshell can now "emulate a terminal"
#+begin_src emacs-lisp
(use-package eat
:hook
(eshell-load . eat-eshell-mode)
(eshell-load . eat-eshell-visual-command-mode))
#+end_src