;;; thanos-commands.el --- custom commands/functions -*- lexical-binding: t; -*- ;; Copyright (C) 2023 Thanos Apollo ;; Author: Thanos Apollo ;; Keywords: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ╭━━━━┳╮╱╱╱╱╱╱╱╱╱╱╱╱╱╱╭━━━╮╱╱╱╱╱╭╮╭╮╱╱╱╱╱╱╱╱╭━━━╮ ;; ┃╭╮╭╮┃┃╱╱╱╱╱╱╱╱╱╱╱╱╱╱┃╭━╮┃╱╱╱╱╱┃┃┃┃╱╱╱╱╱╱╱╱┃╭━━╯ ;; ╰╯┃┃╰┫╰━┳━━┳━╮╭━━┳━━╮┃┃╱┃┣━━┳━━┫┃┃┃╭━━╮╱╱╱╱┃╰━━┳╮╭┳━━┳━━┳━━╮ ;; ╱╱┃┃╱┃╭╮┃╭╮┃╭╮┫╭╮┃━━┫┃╰━╯┃╭╮┃╭╮┃┃┃┃┃╭╮┃╭━━╮┃╭━━┫╰╯┃╭╮┃╭━┫━━┫ ;; ╱╱┃┃╱┃┃┃┃╭╮┃┃┃┃╰╯┣━━┃┃╭━╮┃╰╯┃╰╯┃╰┫╰┫╰╯┃╰━━╯┃╰━━┫┃┃┃╭╮┃╰━╋━━┃ ;; ╱╱╰╯╱╰╯╰┻╯╰┻╯╰┻━━┻━━╯╰╯╱╰┫╭━┻━━┻━┻━┻━━╯╱╱╱╱╰━━━┻┻┻┻╯╰┻━━┻━━╯ ;; ╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱┃┃ ;; ╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╱╰╯ ;;; Code: ;; VM (defvar vm-directory "~/virtual-machines/") (defun vm-create-image () "Create qcow2 image." (interactive) (let ((name (format "%s%s.qcow2" vm-directory (read-string "Name: "))) (size (format "%s" (read-string "Size(G): ")))) (shell-command (format "qemu-img create -f qcow2 %s %sG" name size)))) (defun vm-run () "Spawn Virtual Machine." (interactive) (let ((memory (format "%sG" (read-string "Memory(G): "))) (cores (read-string "Cores: ")) (image (read-file-name "Image: " vm-directory)) (iso (if (y-or-n-p "Load iso?? ") (read-file-name "ISO: ") nil))) (start-process-shell-command "virtual-machine" nil (format "qemu-system-x86_64 -enable-kvm -m %s -smp %s -hda %s -vga qxl -device virtio-serial-pci -spice port=5784,disable-ticketing -display spice-app %s " memory cores image (when iso (concat "-cdrom " iso)))))) ;; MISC (defun thanos/run-in-background (command) "Run COMMAND in the background." (let ((command-parts (split-string command "[ ]+"))) (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts))))) (defun thanos/emacs-keys () "Swap caps with ctrl." (interactive) (start-process-shell-command "setxkbmap" nil "setxkbmap us -option ctrl:swapcaps")) (defun thanos/center-buffer () (interactive) (set-fringe-mode (/ (- (frame-pixel-width) (* 150 (frame-char-width))) 2))) (defun thanos/git-clone (repository) "Clone git REPOSITORY." (interactive (list (read-string "repo: "))) (call-process-shell-command (concat "git clone " (shell-quote-argument repository)) nil 0)) ;; CREATE (defun create-text-scratch () "Create a scratch buffer." (interactive) (switch-to-buffer (get-buffer-create "*Text Scratch*")) (org-mode)) (defun create-scratch () "Create scratch buffer." (interactive) (switch-to-buffer (get-buffer-create "*scratch*")) (emacs-lisp-mode)) (defvar-keymap thanos/create-map :doc "Create custom buffers" "t" #'create-text-scratch "e" #'create-scratch) ;; THEMING (defvar wallpapers-dir "~/wallpapers/") (defun thanos/load-theme () "Disable current theme and load a new one." (interactive) (let ((theme (intern (completing-read "Theme: " (custom-available-themes))))) (disable-theme (car custom-enabled-themes)) (load-theme theme t))) (defun thanos/wallpaper-set (image) "Set IMAGE as wallpaper, using feh." (call-process-shell-command (concat "xwallpaper --focus " wallpapers-dir image) nil 0)) (defun thanos/wallpaper-random () "Set random wallpaper." (interactive) (let ((wallpapers (directory-files "~/wallpapers" nil "^[^.].*"))) (thanos/wallpaper-set (nth (random (length wallpapers)) wallpapers)))) (defun thanos/wallpaper-select () "Set wallpaper." (interactive) (let ((wallpaper (completing-read "Choose wallpaper: " (directory-files wallpapers-dir nil "^[^.].*")))) (thanos/wallpaper-set wallpaper))) (defvar-keymap thanos/applications-map :doc "Thanos commonly used programs" "m" #'mu4e "c" #'gptel-send "f" #'elfeed "e" #'emms-smart-browse "i" #'erc-libera "t" #'thanos/load-theme "w" #'thanos/wallpaper-select "C-c" thanos/create-map "C-e" #'emms-pause) (define-key global-map (kbd "C-c a") thanos/applications-map) (provide 'thanos-commands) ;;; thanos-commands.el ends here