dev.fron.io nixrc / a1507e5
emacs: lots of stuff from before my mental fog Tony Olagbaiye a month ago
8 changed file(s) with 149 addition(s) and 121 deletion(s). Raw diff Collapse all Expand all
0 { config, lib, usr, pkgs, domains, ... }:
1
2 {
3 emacs.loader.bookmark = {
4 demand = true;
5 package = lib.const null;
6 config = ''
7 (defun bookmark-save-advice (&rest r)
8 (let ((save-silently t))
9 (bookmark-save)))
10 (advice-add 'bookmark-set :after #'bookmark-save-advice)
11 '';
12 };
13 }
44 demand = true;
55 after = [ "exwm-input" ];
66 config = ''
7 (progn
8 (desktop-environment-mode))
7 (setq desktop-environment-volume-get-command "amixer -c0 get Master")
8 (setq desktop-environment-volume-set-command "amixer -c0 set Master %s")
9 (setq desktop-environment-volume-toggle-command "amixer -c0 set Master toggle")
10 (define-key desktop-environment-mode-map (kbd "<269025043>") #'desktop-environment-volume-increment) ; mouse v-up
11 (define-key desktop-environment-mode-map (kbd "S-<269025043>") #'desktop-environment-volume-increment-slowly)
12 (define-key desktop-environment-mode-map (kbd "<269025041>") #'desktop-environment-volume-decrement) ; mouse v-down
13 (define-key desktop-environment-mode-map (kbd "S-<269025041>") #'desktop-environment-volume-decrement-slowly)
14 (define-key desktop-environment-mode-map (kbd "<269025073>") #'emms-pause) ; headset btn
15
16 (desktop-environment-mode)
917 '';
1018 };
1119 }
5656 (nixos (unwords (cons cmd (transient-args 'nixos-dispatch)))))
5757
5858 (defcmd nixos-garbage-collect
59 (nixos-with-args "sudo nix-collect-garbage"))
59 (nixos-with-args "doas nix-collect-garbage"))
6060
6161 (defcmd nixos-rebuild
62 (nixos-with-args "sudo nix-channel --update nixpkgs; sudo nixos-rebuild switch"))
62 (nixos-with-args "doas nix run '<nixos>'"))
6363
6464 (defcmd nixos-check-vulnerabilities
65 (nixos "sudo vulnix --system"))
65 (nixos "doas vulnix --system"))
6666
6767 (define-infix-argument nixos:--delete-older-than ()
6868 :description "delete older than"
7777 :argument "--option tarball-ttl ")
7878
7979 (defcmd nix-store-verify
80 (nixos "sudo nix-store --verify --check-contents"))
80 (nixos "doas nix-store --verify --check-contents"))
8181
8282 (defcmd nix-store-repair
83 (nixos "sudo nix-store --verify --check-contents --repair"))
83 (nixos "doas nix-store --verify --check-contents --repair"))
8484
8585 (defcmd nix-store-optimize
86 (nixos "sudo nix-store --optimise -vv"))
86 (nixos "doas nix-store --optimise -vv"))
8787
8888 (defun nix-store-query-dependents (path)
8989 (interactive "sPath: ")
90 (nixos (s-lex-format "sudo nix-store --query --roots ''${path}")))
90 (nixos (s-lex-format "doas nix-store --query --roots ''${path}")))
9191
9292 (defun nix-store-delete (path)
9393 (interactive "sPath: ")
94 (nixos (s-lex-format "sudo nix-store --delete ''${path}")))
94 (nixos (s-lex-format "doas nix-store --delete ''${path}")))
9595
9696 (defun nixos-search-options (option)
9797 (interactive "sOption: ")
107107
108108 (defun nixos-index ()
109109 (interactive)
110 (nixos "sudo nix-index"))
110 (nixos "doas nix-index"))
111
112 (define-transient-command nixos-garbage-collect-dispatch ()
113 ["Garbage collection"
114 (nixos:--delete-older-than)
115 ("g" "collect garbage" nixos-garbage-collect)])
111116
112117 (define-transient-command nixos-dispatch ()
113118 ["Arguments"
128133 ("s k" "delete" nix-store-delete)
129134 ("s o" "optimize" nix-store-optimize)])
130135
131 (define-transient-command nixos-garbage-collect-dispatch ()
132 ["Garbage collection"
133 (nixos:--delete-older-than)
134 ("g" "collect garbage" nixos-garbage-collect)])
136 (define-key global-map (kbd "C-c n") #'nixos-dispatch)
135137 '';
136138 };
137139 }
0 (defun bqv/pmbootstrap-log ()
1 "Open pmbootstrap log in a buffer."
2 (interactive)
3 (switch-to-buffer
4 (let* ((title "*pmbootstrap-log*")
5 (buffer (get-buffer title)))
6 (or buffer
7 (save-excursion
8 (with-current-buffer (window-buffer
9 (async-shell-command "pmbootstrap log"))
10 (rename-buffer title t)))))))
11
12 (defun comint-sudo-run (program)
13 "Run sudo PROGRAM in a Comint buffer and switch to it.
14 See `comint-run'."
15 (declare (interactive-only make-comint))
16 (interactive "sRun program: ")
17 (let ((name (file-name-nondirectory program)))
18 (switch-to-buffer (make-comint name "sudo" nil program))
19 (run-hooks (intern-soft (concat "comint-" name "-hook")))))
20
210 ;; source: http://steve.yegge.googlepages.com/my-dot-emacs-file
221 (defun rename-file-and-buffer (new-name)
232 "Renames both current buffer and file it's visiting to NEW-NAME."
3312 (rename-buffer new-name)
3413 (set-visited-file-name new-name)
3514 (set-buffer-modified-p nil))))))
36
37 (defun bookmark-save-advice (&rest r)
38 (let ((save-silently t))
39 (bookmark-save)))
40 (advice-add 'bookmark-set :after #'bookmark-save-advice)
41
42 (setq desktop-environment-volume-get-command "amixer -c0 get Master")
43 (setq desktop-environment-volume-set-command "amixer -c0 set Master %s")
44 (setq desktop-environment-volume-toggle-command "amixer -c0 set Master toggle")
45 (define-key desktop-environment-mode-map (kbd "<269025043>") #'desktop-environment-volume-increment) ; mouse v-up
46 (define-key desktop-environment-mode-map (kbd "S-<269025043>") #'desktop-environment-volume-increment-slowly)
47 (define-key desktop-environment-mode-map (kbd "<269025041>") #'desktop-environment-volume-decrement) ; mouse v-down
48 (define-key desktop-environment-mode-map (kbd "S-<269025041>") #'desktop-environment-volume-decrement-slowly)
49 (define-key desktop-environment-mode-map (kbd "<269025073>") #'emms-pause) ; headset btn
11 (setq shell-file-name (executable-find "bash"))
22 (setq async-shell-command-buffer 'confirm-rename-buffer)
33 (setq async-shell-command-display-buffer nil)
4 (do-buffers (setenv "PAGER" "cat"))
4
5 (do-buffers (setenv "PAGER" "cat")) ; depends: ace-window-config
6
7 (defun comint-sudo-run (program)
8 "Run sudo PROGRAM in a Comint buffer and switch to it.
9 See `comint-run'."
10 (declare (interactive-only make-comint))
11 (interactive "sRun program: ")
12 (let ((name (file-name-nondirectory program)))
13 (switch-to-buffer (make-comint name "sudo" nil program))
14 (run-hooks (intern-soft (concat "comint-" name "-hook")))))
515
616 (defun shell-region (start end)
717 "execute region in an inferior shell"
818 (interactive "r")
919 (shell-command (buffer-substring-no-properties start end)))
1020 (global-set-key (kbd "C-x !") #'shell-region)
21
1122 (defun async-shell-region (start end)
1223 "execute region in an inferior shell"
1324 (interactive "r")
1425 (async-shell-command (buffer-substring-no-properties start end)))
1526 (global-set-key (kbd "C-x &") #'async-shell-region)
1627
17 (defun ivy-shell-keymap (&optional async &key initial-input)
18 (let ((keymap (make-keymap)))
19 (define-key keymap (kbd "<RET>") `(lambda ()
20 (interactive)
21 (if (string-equal (ivy--input) "")
22 (ivy-done)
23 (ivy-immediate-done))))
24 (define-key keymap (kbd "<tab>") #'completion-at-point)
25 (define-key keymap (kbd "C-i") `(lambda ()
26 (interactive)
27 (add-to-list 'completion-at-point-functions
28 'comint-completion-at-point)
29 (completion-at-point)))
30 (define-key keymap (kbd "<backtab>") #'ivy-insert-current)
31 (define-key keymap (kbd "<C-tab>") `(lambda ()
32 (interactive)
33 (ivy-quit-and-run
34 (ivy-shell ,(not async)
35 :initial-input ,initial-input))))
36 keymap))
37
38 (setq enable-recursive-minibuffers t)
39 (defun ivy-shell (&optional async &key initial-input)
40 (ivy-read (format "[%s] shell: " (if async "async" "synch"))
41 shell-command-history
42 :caller 'ivy-shell
43 :keymap (ivy-shell-keymap async :initial-input initial-input)
44 :action (if async #'async-shell-command #'shell-command)
45 :initial-input (or initial-input "")
46 :history 'shell-command-history))
47 (defun ivy-shell-sync (&optional pfx)
48 (interactive "p")
49 (minibuffer-with-setup-hook
50 (lambda ()
51 (shell-completion-vars)
52 (setq-local minibuffer-default-add-function
53 #'minibuffer-default-add-shell-commands))
54 (ivy-shell nil :initial-input (if (= (or pfx 1) -1) (car shell-command-history)))))
55 (global-set-key (kbd "M-!") #'ivy-shell-sync)
56 (global-set-key (kbd "´") #'ivy-shell-sync)
57 (evil-define-key 'normal 'global (kbd "´") #'ivy-shell-sync)
58 (defun ivy-shell-async (&optional pfx)
59 (interactive "p")
60 (minibuffer-with-setup-hook
61 (lambda ()
62 (shell-completion-vars)
63 (setq-local minibuffer-default-add-function
64 #'minibuffer-default-add-shell-commands))
65 (ivy-shell t :initial-input (if (= (or pfx 1) -1) (car shell-command-history)))))
66 (global-set-key (kbd "M-&") #'ivy-shell-async)
67 (global-set-key (kbd "`") #'ivy-shell-async)
68 (evil-define-key 'normal 'global (kbd "`") #'ivy-shell-async)
69
70 (defun ivy-term (&optional &key initial-input)
71 (interactive)
72 (ivy-read (format "[%s] term: " "vterm")
73 shell-command-history
74 :caller 'ivy-term
75 :keymap (ivy-shell-keymap :initial-input initial-input)
76 :action #'vterm-shell-command
77 :initial-input (or initial-input "")
78 :history 'shell-command-history))
79 (defalias #'ivy-vterm #'ivy-term)
80 (global-set-key (kbd "C-x M-&") #'ivy-term)
81
8228 (provide 'scraps+shell)
8329 ;;; scraps+shell.el ends here
+0
-4
emacs/scraps+web.el less more
0 (when (executable-find "xdg-open")
1 (with-eval-after-load 'browse-url
2 (setq browse-url-generic-program "xdg-open"
3 browse-url-browser-function 'browse-url-generic)))
66 ${builtins.readFile ./scraps+bufmgmt.el}
77 ${builtins.readFile ./scraps+misc.el}
88 ${builtins.readFile ./scraps+shell.el}
9 ${builtins.readFile ./scraps+web.el}
109 '';
1110 };
1211 }
0 { config, lib, usr, pkgs, ... }:
1
2 {
3 emacs.loader.treemacs-magit = {
4 demand = true;
5 after = [ "treemacs" "magit" ];
6 config = ''
7 (defun ivy-shell-keymap (&optional async &key initial-input)
8 (let ((keymap (make-keymap)))
9 (define-key keymap (kbd "<RET>") `(lambda ()
10 (interactive)
11 (if (string-equal (ivy--input) "")
12 (ivy-done)
13 (ivy-immediate-done))))
14 (define-key keymap (kbd "<tab>") #'completion-at-point)
15 (define-key keymap (kbd "C-i") `(lambda ()
16 (interactive)
17 (add-to-list 'completion-at-point-functions
18 'comint-completion-at-point)
19 (completion-at-point)))
20 (define-key keymap (kbd "<backtab>") #'ivy-insert-current)
21 (define-key keymap (kbd "<C-tab>") `(lambda ()
22 (interactive)
23 (ivy-quit-and-run
24 (ivy-shell ,(not async)
25 :initial-input ,initial-input))))
26 keymap))
27
28 (setq enable-recursive-minibuffers t)
29 (defun ivy-shell (&optional async &key initial-input)
30 (ivy-read (format "[%s] shell: " (if async "async" "synch"))
31 shell-command-history
32 :caller 'ivy-shell
33 :keymap (ivy-shell-keymap async :initial-input initial-input)
34 :action (if async #'async-shell-command #'shell-command)
35 :initial-input (or initial-input "")
36 :history 'shell-command-history))
37 (defun ivy-shell-sync (&optional pfx)
38 (interactive "p")
39 (minibuffer-with-setup-hook
40 (lambda ()
41 (shell-completion-vars)
42 (setq-local minibuffer-default-add-function
43 #'minibuffer-default-add-shell-commands))
44 (ivy-shell nil :initial-input (if (= (or pfx 1) -1) (car shell-command-history)))))
45 (global-set-key (kbd "M-!") #'ivy-shell-sync)
46 (global-set-key (kbd "´") #'ivy-shell-sync)
47 (evil-define-key 'normal 'global (kbd "´") #'ivy-shell-sync)
48 (defun ivy-shell-async (&optional pfx)
49 (interactive "p")
50 (minibuffer-with-setup-hook
51 (lambda ()
52 (shell-completion-vars)
53 (setq-local minibuffer-default-add-function
54 #'minibuffer-default-add-shell-commands))
55 (ivy-shell t :initial-input (if (= (or pfx 1) -1) (car shell-command-history)))))
56 (global-set-key (kbd "M-&") #'ivy-shell-async)
57 (global-set-key (kbd "`") #'ivy-shell-async)
58 (evil-define-key 'normal 'global (kbd "`") #'ivy-shell-async)
59
60 (defun ivy-term (&optional &key initial-input)
61 (interactive)
62 (ivy-read (format "[%s] term: " "vterm")
63 shell-command-history
64 :caller 'ivy-term
65 :keymap (ivy-shell-keymap :initial-input initial-input)
66 :action #'vterm-shell-command
67 :initial-input (or initial-input "")
68 :history 'shell-command-history))
69 (defalias #'ivy-vterm #'ivy-term)
70 (global-set-key (kbd "C-x M-&") #'ivy-term)
71
72 (define-transient-command nixos-dispatch ()
73 ["Arguments"
74 ("-t" "show trace" "--show-trace")
75 (nixos:--tarball-ttl)]
76 ["NixOS"
77 ("r" "rebuild" nixos-rebuild)
78 ("o" "search options" nixos-search-options)
79 ("p" "search packages" nixos-search-packages)
80 ("h" "check channels" nixos-howoldis)
81 ("i" "index" nixos-index)]
82 ["Garbage collection"
83 ("g" "collect garbage" nixos-garbage-collect-dispatch)]
84 ["Nix Store"
85 ("s v" "verify" nix-store-verify)
86 ("s r" "repair" nix-store-repair)
87 ("s d" "query dependents" nix-store-query-dependents)
88 ("s k" "delete" nix-store-delete)
89 ("s o" "optimize" nix-store-optimize)])
90
91 (define-transient-command nixos-garbage-collect-dispatch ()
92 ["Garbage collection"
93 (nixos:--delete-older-than)
94 ("g" "collect garbage" nixos-garbage-collect)])
95 '';
96 };
97 }