summaryrefslogtreecommitdiff
path: root/modules/system-utils.el
blob: 53992481aff05576a86af4c6b3768123004ff109 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;;; system-utils --- System-Wide Utilities -*- lexical-binding: t; -*-
;; author Craig Jennings <c@cjennings.net>
;;; Commentary:

;;; Code:

(require 'cl-lib)
(require 'host-environment)

;; ---------------------------- Edit A File With Sudo ----------------------------

(use-package sudo-edit
  :defer 1
  :bind ("C-x M-f" . sudo-edit))

(defun cj/open-file-with (command)
  "Asynchronously run COMMAND on the current buffer's file."
  (interactive "MOpen with program: ")
  (let ((display-buffer-alist
		 '(("\\*Async Shell Command\\*" display-buffer-no-window))))
	(async-shell-command (format "%s \"%s\"" command buffer-file-name))))

;; ------------------------------ Server Shutdown ------------------------------

(defun server-shutdown ()
  "Save buffers, kill Emacs and shutdown the server."
  (interactive)
  (save-some-buffers)
  (kill-emacs))
(global-set-key (kbd "C-<f10>") #'server-shutdown)
(global-set-key (kbd "<f10>")     #'save-buffers-kill-terminal)

;; ------------------------ List Buffers With Nerd Icons -----------------------

(global-set-key [remap list-buffers] #'ibuffer)
(use-package nerd-icons-ibuffer
  :defer 0.5
  :after nerd-icons
  :hook (ibuffer-mode . nerd-icons-ibuffer-mode)
  :config
  (setq nerd-icons-ibuffer-icon            t
		nerd-icons-ibuffer-color-icon      t
		nerd-icons-ibuffer-human-readable-size t))

;; -------------------------- Scratch Buffer Happiness -------------------------

;; Customize the scratch buffer
(defvar scratch-emacs-version-and-system
  (concat ";; Welcome to Emacs " emacs-version
		  " running on " system-configuration ".\n"))
(defvar scratch-greet
  (concat ";; Emacs ♥ you, " user-login-name ". Happy Hacking!\n\n"))
(setq initial-scratch-message
	  (concat scratch-emacs-version-and-system scratch-greet))
(setq initial-major-mode 'org-mode)

;; --------------------------------- Dictionary --------------------------------

(use-package sdcv
  :defer 1
  :bind ("C-h d" . sdcv-search-input))

;; -------------------------------- Log Silently -------------------------------

(defun cj/log-silently (text)
  "Append TEXT to *Messages* buffer without echoing in the minibuffer."
  (let ((inhibit-read-only t))
	(with-current-buffer (get-buffer-create "*Messages*")
	  (goto-char (point-max))
	  (unless (bolp) (insert "\n"))
	  (insert text)
      (unless (bolp) (insert "\n")))))

;; ------------------------------ Process Monitor ------------------------------

(use-package proced
  :ensure nil ;; built-in
  :defer 0.5
  :commands proced
  :bind ("C-M-p" . proced)
  :custom
  (proced-auto-update-flag t)
  (proced-show-remote-processes t)
  (proced-enable-color-flag t)
  (proced-format 'custom)
  :config
  (add-to-list 'proced-format-alist
			   '(custom user pid ppid sess tree pcpu pmem rss start time
						state (args comm))))

(provide 'system-utils)
;;; system-utils.el ends here