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.

85 lines
2.4 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. ** Setting up the $PATH
  15. Ensure ~~/.local/bin~ added to the =$PATH= environment variable.
  16. #+begin_src shell
  17. PATH=$PATH:~/.local/bin
  18. export PATH
  19. #+end_src
  20. ** Starting Emacs by default on TTY1
  21. 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.
  22. #+begin_src shell
  23. if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
  24. exec startx
  25. fi
  26. #+end_src
  27. ** Creating symbolic links
  28. 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.
  29. #+begin_src emacs-lisp
  30. (dotfiles/symlink "~/.emacs.d/config/profile"
  31. "~/.profile")
  32. #+end_src
  33. * Methods
  34. Define methods for interaction between Emacs and the underlying shell environment.
  35. ** Run an external process
  36. Define a method to run an external process, launching any application on a new process without interferring with Emacs.
  37. #+begin_src emacs-lisp
  38. (defun dotfiles/run (cmd)
  39. "Run an external process."
  40. (interactive (list (read-shell-command "λ ")))
  41. (start-process-shell-command cmd nil cmd))
  42. #+end_src
  43. ** Apply command to call process
  44. 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.
  45. #+begin_src emacs-lisp
  46. (defun dotfiles/run-in-background (cmd)
  47. (let ((command-parts (split-string cmd "[ ]+")))
  48. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  49. #+end_src
  50. ** Keybindings
  51. Place keybindings for executing shell commands behind =SPC x=:
  52. + Run shell commands with =x=
  53. + Run async shell commands with =z=
  54. #+begin_src emacs-lisp
  55. (dotfiles/leader
  56. "x" '(:ignore t :which-key "Run")
  57. "xx" '(dotfiles/run :which-key "Run")
  58. "xz" '(async-shell-command :which-key "Async"))
  59. #+end_src