I showed you my source code, pls respond
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB

  1. #+TITLE: Shell
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+PROPERTY: header-args:emacs-lisp :tangle shell.el :comments org
  5. #+PROPERTY: header-args :results silent :eval no-export :comments org
  6. #+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  7. #+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  8. Override the default behaviour of the Shell environment to integrate with Emacs.
  9. * Profile
  10. :PROPERTIES:
  11. :header-args: :tangle ../config/profile :comments org
  12. :END:
  13. Override the default shell profile under *Bash*.
  14. ** Force colours
  15. Manually set the terminal type to ~xterm-256color~ for better colours on TTY Emacs.
  16. #+begin_src shell
  17. export TERM=xterm-256color
  18. #+end_src
  19. ** Setting up the $PATH
  20. Ensure ~~/.local/bin~ added to the =$PATH= environment variable.
  21. #+begin_src shell
  22. export PATH=$PATH:~/.local/bin
  23. #+end_src
  24. ** Starting Emacs by default on TTY1
  25. When launching into a new session on ~TTY1~, if the display server is not running, run *StartX*[fn:3]. This will launch the window manager.
  26. #+begin_src shell
  27. if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
  28. exec startx
  29. fi
  30. #+end_src
  31. ** Creating symbolic links
  32. The system looks for the default shell profile under *Bash* at ~~/.profile~. Creating a symbolic link from this location to our configuration will override the startup behaviour.
  33. #+begin_src emacs-lisp
  34. (dotfiles/symlink "~/.emacs.d/config/profile"
  35. "~/.profile")
  36. #+end_src
  37. * Methods
  38. Define methods for interaction between Emacs and the underlying shell environment.
  39. ** Run an external process
  40. Define a method to run an external process, launching any application on a new process without interferring with Emacs.
  41. #+begin_src emacs-lisp
  42. (defun dotfiles/run (cmd)
  43. "Run an external process."
  44. (interactive (list (read-shell-command "λ ")))
  45. (start-process-shell-command cmd nil cmd))
  46. #+end_src
  47. ** Apply command to call process
  48. Define a method to apply commands to the current call process, this is to avoid issues with hooks but can impact the performance of Emacs.
  49. #+begin_src emacs-lisp
  50. (defun dotfiles/run-in-background (cmd)
  51. (let ((command-parts (split-string cmd "[ ]+")))
  52. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  53. #+end_src
  54. ** Keybindings
  55. Place keybindings for executing shell commands behind =SPC x=:
  56. + Run shell commands with =x=
  57. + Run async shell commands with =z=
  58. #+begin_src emacs-lisp
  59. (dotfiles/leader
  60. "x" '(:ignore t :which-key "Run")
  61. "xx" '(dotfiles/run :which-key "Run")
  62. "xz" '(async-shell-command :which-key "Async"))
  63. #+end_src