From e4e86775200ccbf88ff5e4e032a960c2e0266481 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 14 Dec 2023 07:10:50 +0100 Subject: Engage! --- README.md | 5 ++ emacs.el | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ shenanigans.sh | 128 +++++++++++++++++++++++++++++++++++++++++++++++ vimrc | 52 +++++++++++++++++++ 4 files changed, 339 insertions(+) create mode 100644 README.md create mode 100755 emacs.el create mode 100755 shenanigans.sh create mode 100644 vimrc diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3ea7dd --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +```sh +ln -s ~/.dotfiles/emacs.el ~/.config/emacs/init.el +ln -s ~/.dotfiles/vimrc ~/.vimrc +ln -s ~/.dotfiles/shenanigans.sh ~/.shenanigans.sh +``` diff --git a/emacs.el b/emacs.el new file mode 100755 index 0000000..7ad08c0 --- /dev/null +++ b/emacs.el @@ -0,0 +1,154 @@ +(require 'package) +(add-to-list 'package-archives '("melpa-stable" . "http://stable.melpa.org/packages/") t) +(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/")) +(add-to-list 'package-archives '("nongnu" . "https://elpa.nongnu.org/nongnu/")) +(package-initialize) + +(setq custom-file "~/.config/emacs/custom.el") +(when (file-exists-p custom-file) + (load custom-file)) + +;; Function to install packages if they're not already installed +(defvar my-packages + '(go-mode yaml-mode web-mode markdown-mode tree-sitter tree-sitter-langs + editorconfig company drag-stuff eglot helm elfeed crux)) + +(defun install-my-packages () + (unless package-archive-contents + (package-refresh-contents)) + (dolist (package my-packages) + (unless (package-installed-p package) + (package-install package)))) + +(install-my-packages) + +;; General stuff +(menu-bar-mode -1) +(setq inhibit-startup-message t) +(setq visible-bell t) +(setq echo-keystrokes 0.1) +(setq gc-cons-threshold 20000000) +(setq make-backup-files nil) +(setq create-lockfiles nil) +(setq auto-save-default nil) +(setq global-auto-revert-non-file-buffers t) +(setq auto-revert-verbose nil) +(setq-default tab-width 4) +(setq-default truncate-lines t) +(set-default 'indicate-empty-lines t) +(setq electric-pair-preserve-balance nil) +(setq byte-compile-warnings '(cl-functions)) +(global-display-line-numbers-mode 1) +(global-auto-revert-mode 1) +(electric-pair-mode t) +(show-paren-mode 1) +(setq-default fill-column 80) +(global-hl-line-mode 1) +(set-face-background hl-line-face "gray13") +(add-to-list 'default-frame-alist '(foreground-color . "#ffffff")) +(add-to-list 'default-frame-alist '(background-color . "#151515")) + +;; Key rebinds +(global-set-key (kbd "C-z") 'undo-only) +(global-set-key (kbd "C-S-z") 'undo-redo) +(global-set-key (kbd "M-s") 'save-buffer) +(global-set-key (kbd "C-f") 'isearch-forward) +(global-set-key (kbd "M-f") 'fill-paragraph) +(global-set-key (kbd "C-x C-c") 'kill-emacs) +(global-set-key (kbd "M-q") 'kill-emacs) +(global-set-key (kbd "M-") 'end-of-line) +(global-set-key (kbd "M-") 'beginning-of-line) +(global-set-key (kbd "M-d") 'crux-duplicate-current-line-or-region) +(global-set-key (kbd "M-k") 'crux-kill-whole-line) +(global-set-key (kbd "C-h") 'crux-kill-line-backwards) +(global-set-key (kbd "C-k") 'crux-kill-other-buffers) +(global-set-key (kbd "M-v") 'visual-line-mode) +(global-set-key (kbd "C-_") (lambda() (interactive) (comment-line 1) (previous-line 1))) + +;; Move line up and down +(drag-stuff-mode t) +(global-set-key (kbd "M-") 'drag-stuff-up) +(global-set-key (kbd "M-") 'drag-stuff-down) + +;; Save a list of recent files visited. (open recent file with C-x f) +(recentf-mode 1) +(setq recentf-max-saved-items 100) + +;; Helm stuff +(require 'helm) +(helm-autoresize-mode 1) +(setq helm-autoresize-max-height 25 helm-autoresize-min-height 25) +(global-set-key (kbd "M-x") 'helm-M-x) +(global-set-key (kbd "C-p") 'helm-find-files) +(global-set-key (kbd "C-b") 'helm-buffers-list) +(global-set-key (kbd "C-x C-_") 'helm-find) + +;; Enables editorconfig +(editorconfig-mode 1) + +;; Enable company mode completion +(add-hook 'after-init-hook 'global-company-mode) + +;; Eglot LSP +(setq eglot-ignored-server-capabilities '(:inlayHintProvider)) +(add-hook 'c-mode-hook 'eglot-ensure) +(add-hook 'go-mode-hook 'eglot-ensure) +(add-hook 'tcl-mode-hook 'eglot-ensure) +(add-hook 'sh-mode-hook 'eglot-ensure) +(add-hook 'python-mode-hook 'eglot-ensure) +(add-hook 'lua-mode-hook 'eglot-ensure) +(add-hook 'js-mode-hook 'eglot-ensure) + +;; Go format before save +(add-hook 'go-mode-hook + (lambda () + (add-hook 'before-save-hook 'gofmt-before-save) + (setq tab-width 4) + (setq indent-tabs-mode 1))) + +;; Enables tree sitter +(global-tree-sitter-mode) +(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode) + +;; Templating engines +(require 'web-mode) +(add-to-list 'auto-mode-alist '("\\.twig\\'" . web-mode)) +(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode)) +(add-to-list 'auto-mode-alist '("\\.django\\'" . web-mode)) +(setq web-mode-enable-auto-pairing t) +(setq web-mode-enable-auto-closing t) +(setq web-mode-enable-current-element-highlight t) +(setq web-mode-enable-current-column-highlight t) + +;; RSS Feeds +(setq elfeed-search-filter "@48-months-ago") +(setq elfeed-feeds '( + ("https://landley.net/rss.xml") + ("https://blog.regehr.org/feed") + ("https://szymonkaliski.com/feed.xml") + ("https://world.hey.com/dhh/feed.atom") + ("https://workchronicles.com/feed/") + ("https://mitchellh.com/feed.xml") + ("https://matt-rickard.com/rss") + ("https://solar.lowtechmagazine.com/posts/index.xml") + ("https://utcc.utoronto.ca/~cks/space/blog/?atom") + ("https://gosamples.dev/index.xml") + ("https://neil.computer/rss/") + ("https://matduggan.com/rss/") + ("https://michael.stapelberg.ch/feed.xml") + ("https://offbeatpursuit.com/blog/index.rss") + ("https://offbeatpursuit.com/paste/index.rss") + ("https://offbeatpursuit.com/notes/index.rss") + ("https://emacsredux.com/atom.xml") + ("https://journal.valeriansaliou.name/rss/") + ("https://www.taniarascia.com/rss.xml") + ("https://crawl.develz.org/wordpress/feed") + ("https://snarky.ca/rss/") + ("https://www.jeffgeerling.com/blog.xml") + ("https://serokell.io/blog.rss.xml") + ("https://www.duskborn.com/index.xml") + ("https://mirzapandzo.com/rss.xml") + ("https://blog.boot.dev/index.xml") + ("https://macwright.com/rss.xml") +)) + diff --git a/shenanigans.sh b/shenanigans.sh new file mode 100755 index 0000000..040f8bc --- /dev/null +++ b/shenanigans.sh @@ -0,0 +1,128 @@ +# Software list. +# cifs-utils tree jq xmlstarlet s3cmd xclip neovim mc gnupg +# tilix fzf ripgrep + +# Magical environment variables. + +NIX_SHELL_PRESERVE_PROMPT=1 +TERM=xterm-256color +EDITOR=vim + +# Better prompt. + +parse_git_branch() { + git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' +} + +is_inside_nix_shell() { + nix_shell_name="$(basename "$IN_NIX_SHELL" 2>/dev/null)" + if [[ -n "$nix_shell_name" ]]; then + echo " \e[0;36m(nix-shell)\e[0m" + fi +} + +export PS1="[\033[38;5;9m\]\u@\h\[$(tput sgr0)\]]$(is_inside_nix_shell)\[\033[33m\]\$(parse_git_branch)\[\033[00m\] \w\[$(tput sgr0)\] \n$ " + +# General aliases. + +alias c='clear' +alias l='ls -lh' +alias ll='ls -lha' +alias t='tree -L 2' +alias ..='cd ..' +alias h='history' +alias x='exit' +alias grep='grep --color=always' +alias less='less -R' +alias e='emacs' +alias n='nvim' +alias gg='lazygit' +alias gt='git-town' +alias server='python3 -m http.server 6969' + +# Custom folder jump commands. + +alias p='cd ~/Vault/projects' +alias j='cd ~/Junk' +alias d='cd ~/Downloads' +alias v='cd ~/Vault' + +# Additional path settings. + +export PATH=$HOME/Vault/bin:$PATH +export PATH=$HOME/Applications:$PATH +export PATH=$HOME/.local/bin:$PATH +export PATH=$HOME/go/bin:$PATH + +export PATH=$HOME/Android/Sdk/platform-tools:$PATH +export PATH=$HOME/Android/Sdk/tools:$PATH + +# History and search. + +HISTCONTROL=ignoreboth +shopt -s histappend +export HISTSIZE= +export HISTFILESIZE= +export HISTFILE=~/.bash_history_infinite +PROMPT_COMMAND="history -a; history -n; ${PROMPT_COMMAND}" +bind '"\e[A": history-search-backward' +bind '"\e[B": history-search-forward' +alias hh=hstr +export HSTR_CONFIG=hicolor +if [[ $- =~ .i. ]]; then bind '"\C-h": "\C-a hstr -- \C-j"'; fi + +# Useful function. Much wow! + +backup() { + VHOME=/home/$USER/Vault + ME=$(whoami)@$(hostname) + + mkdir -p $VHOME/dotfiles + cd $VHOME/dotfiles + + # Make a copy of dotfiles. + cp /home/$USER/.shenanigans.sh shenanigans.sh + cp /home/$USER/.bash_history bash_history + cp /home/$USER/.bash_history_infinite bash_history_infinite + cp /home/$USER/.smbcredentials smbcredentials + cp /home/$USER/.gitconfig gitconfig + cp /home/$USER/.s3cfg s3cfg + + cp /home/$USER/.vimrc vimrc + cp /home/$USER/.config/nvim/init.lua neovim.lua + cp /home/$USER/.config/emacs/init.el init.el + + cp -Rf /home/$USER/.ssh/ ./ + cp -Rf /home/$USER/.aws/ ./ + + dconf dump /com/gexperts/Tilix/ > tilix.dconf + # dconf load /com/gexperts/Tilix/ < tilix.dconf + + # Backup screenshots. + mkdir -p $VHOME/pictures + cp -rfn ~/Pictures/* $VHOME/pictures/ + + # Backup screencasts. + mkdir -p $VHOME/videos + cp -rfn ~/Videos/* $VHOME/videos/ + + # Sync with NAS. + rsync -azv \ + --exclude '.venv/' \ + --exclude '.git/' \ + --exclude 'node_modules/' \ + --delete \ + $VHOME/ /media/Void/Backup/$ME/ + + # Sync to off-site DO S3 bucket. + s3cmd sync \ + --host-bucket=vault \ + --delete-removed \ + --exclude 'node_modules/*' \ + --exclude '.git/*' \ + --exclude '.venv/*' \ + $VHOME/ s3://vault/backup/$ME/ + + # Add to log file. + echo `date +"%D %T"` >> ~/.vault.log +} diff --git a/vimrc b/vimrc new file mode 100644 index 0000000..b8af15e --- /dev/null +++ b/vimrc @@ -0,0 +1,52 @@ +set nocompatible + +" General sane defaults. +syntax enable +colorscheme sorbet +nnoremap q: +set relativenumber +set nohlsearch +set smartcase +set ignorecase +set incsearch +set nowrap +set nobackup +set noswapfile +set autoread +set wildmenu +set autoindent +set noesckeys +set encoding=utf8 +set backspace=2 +set scrolloff=4 +set spelllang=en_us + +nnoremap :silent :bp +nnoremap :silent :bn + +" Commenting blocks of code. +augroup commenting_blocks_of_code + autocmd! + autocmd FileType c,cpp,go,scala let b:comment_leader = '// ' + autocmd FileType sh,ruby,python let b:comment_leader = '# ' + autocmd FileType conf,fstab let b:comment_leader = '# ' + autocmd FileType lua let b:comment_leader = '-- ' + autocmd FileType vim let b:comment_leader = '" ' +augroup END +noremap gcc :silent s/^/=escape(b:comment_leader,'\/')/:nohlsearch +noremap gcu :silent s/^\V=escape(b:comment_leader,'\/')//e:nohlsearch + +" Language specific indentation. +filetype plugin indent on +autocmd Filetype make,go,sh setlocal noexpandtab tabstop=4 shiftwidth=4 +autocmd Filetype c,cpp,html,javascript,css,python setlocal expandtab tabstop=2 shiftwidth=2 + +" Status Line enhancements. +" set laststatus=2 +" set statusline=%f%m%=%y\ %{strlen(&fenc)?&fenc:'none'}\ %l:%c\ %L\ %P +" hi StatusLine cterm=NONE ctermbg=black ctermfg=brown +" hi StatusLineNC cterm=NONE ctermbg=black ctermfg=darkgray + +" Throwaway config. +au BufReadPost *.twig set syntax=html + -- cgit v1.2.3