From 14159884fa4613038700a64a52a753f8ca6da2e8 Mon Sep 17 00:00:00 2001 From: Ben Vincent Date: Sat, 9 Mar 2024 11:47:06 +1100 Subject: [PATCH] multiple updates vim/nvim functions/keys shell aliases waybar config password-store submodule --- .config/nvim/lua/func.lua | 8 +++++- .config/nvim/lua/func/popterm.lua | 38 ++++++++++++++++++++++++++ .config/nvim/lua/func/puppet.lua | 28 ++++++++++++++----- .config/nvim/lua/func/sessions.lua | 22 +++++++++++++++ .config/nvim/lua/func/tabline.lua | 43 ++++++++++++++++++++++++++++++ .config/nvim/lua/func/utils.lua | 14 ++++++++++ .config/nvim/lua/keys.lua | 7 ++++- .config/password-store | 2 +- .config/shell/aliases | 13 +++++++-- .config/waybar/config | 2 +- 10 files changed, 164 insertions(+), 13 deletions(-) create mode 100644 .config/nvim/lua/func/popterm.lua create mode 100644 .config/nvim/lua/func/sessions.lua create mode 100644 .config/nvim/lua/func/tabline.lua create mode 100644 .config/nvim/lua/func/utils.lua diff --git a/.config/nvim/lua/func.lua b/.config/nvim/lua/func.lua index cd133f6..c1dc278 100644 --- a/.config/nvim/lua/func.lua +++ b/.config/nvim/lua/func.lua @@ -4,7 +4,10 @@ vim.cmd [[ augroup lang_all autocmd! + autocmd FileType * luafile ~/.config/nvim/lua/func/utils.lua autocmd FileType * luafile ~/.config/nvim/lua/func/tabline.lua + autocmd FileType * luafile ~/.config/nvim/lua/func/popterm.lua + autocmd FileType * luafile ~/.config/nvim/lua/func/sessions.lua augroup END ]] @@ -12,7 +15,10 @@ vim.cmd [[ vim.cmd [[ augroup lang_puppet autocmd! - autocmd FileType puppet nnoremap g :call OpenPuppetClassOrTemplate() + autocmd FileType puppet nnoremap gg :call OpenPuppetClassOrTemplate(tab) + autocmd FileType puppet nnoremap gt :call OpenPuppetClassOrTemplate(tab) + autocmd FileType puppet nnoremap gh :call OpenPuppetClassOrTemplate(horizontal) + autocmd FileType puppet nnoremap gv :call OpenPuppetClassOrTemplate(vertical) autocmd FileType puppet nnoremap t :call OpenPuppetTestMode() autocmd BufNewFile site/roles/manifests/**.pp call ApplyPuppetTemplate() autocmd BufNewFile site/profiles/manifests/**.pp call ApplyPuppetTemplate() diff --git a/.config/nvim/lua/func/popterm.lua b/.config/nvim/lua/func/popterm.lua new file mode 100644 index 0000000..e40239a --- /dev/null +++ b/.config/nvim/lua/func/popterm.lua @@ -0,0 +1,38 @@ +-- enter testmode +vim.cmd([[ + " nvim-only config + if has('nvim') + + function! OpenCenteredTerminal() + " Calculate the desired width and height as 80% of the current window size + let height = float2nr((&lines * 0.8) / 1) + let width = float2nr((&columns * 0.8) / 1) + + " Calculate the top and left positions to center the terminal + let top = float2nr((&lines - height) / 2) + let left = float2nr((&columns - width) / 2) + + " Define options for the floating window, including its size and position + let opts = {'relative': 'editor', 'row': top, 'col': left, 'width': width, 'height': height, 'style': 'minimal'} + + " Create a new buffer for the terminal, set it to not listed and with no swapfile + let buf = nvim_create_buf(v:false, v:true) + + " Open a new window with the terminal buffer, applying the specified options + call nvim_open_win(buf, v:true, opts) + + " Run the default shell in the terminal + call termopen($SHELL) + + " Adjust the focus to the newly opened terminal window + startinsert + endfunction + + " Define the :Popterm command to open the centered terminal + command! Popterm call OpenCenteredTerminal() + highlight Terminal guibg=#000000 guifg=none + nnoremap T :Popterm + autocmd TermOpen * setlocal winhighlight=Normal:Terminal + + endif +]]) diff --git a/.config/nvim/lua/func/puppet.lua b/.config/nvim/lua/func/puppet.lua index 6a5aa2a..3983ffd 100644 --- a/.config/nvim/lua/func/puppet.lua +++ b/.config/nvim/lua/func/puppet.lua @@ -10,7 +10,7 @@ function! OpenPuppetTestMode() echo " v - puppet-validate" echo " l - puppet-lint" echo " q - quit test mode" - + " Keybinding to run tests on the current buffer nnoremap v :!/usr/local/bin/puppet-validate % nnoremap l :!/usr/local/bin/puppet-lint % @@ -35,7 +35,7 @@ endfunction -- follow links to classes vim.cmd([[ -function! OpenPuppetProfileOrRole() +function! OpenPuppetProfileOrRole(layout) " Get the line under the cursor let line = getline(".") @@ -65,14 +65,21 @@ function! OpenPuppetProfileOrRole() let fullpath = dirpath . filepath . ".pp" " Open the file in a new tab - execute "tabedit " . fullpath - + if a:layout == 'horizontal' + execute 'split ' . fullpath + elseif a:layout == 'vertical' + execute 'vsplit ' . fullpath + elseif a:layout == 'tab' + execute 'tabedit ' . fullpath + else + echo "Invalid layout specified." + endif endfunction ]]) -- follow links to templates vim.cmd([[ -function! OpenPuppetTemplate() +function! OpenPuppetTemplate(layout) " Get the line under the cursor let line = getline(".") @@ -95,8 +102,15 @@ function! OpenPuppetTemplate() let fullpath = newpath " Open the file in a new tab - execute "tabedit " . fullpath - + if a:layout == 'horizontal' + execute 'split ' . fullpath + elseif a:layout == 'vertical' + execute 'vsplit ' . fullpath + elseif a:layout == 'tab' + execute 'tabedit ' . fullpath + else + echo "Invalid layout specified." + endif endfunction ]]) diff --git a/.config/nvim/lua/func/sessions.lua b/.config/nvim/lua/func/sessions.lua new file mode 100644 index 0000000..a51dc08 --- /dev/null +++ b/.config/nvim/lua/func/sessions.lua @@ -0,0 +1,22 @@ +vim.cmd([[ +command! SaveSession call SaveSession() +function! SaveSession() + let session_file = g:session_dir . GetRepositoryName() . '_' . GetCurrentGitBranch() . '.vim' + execute 'mksession! ' . session_file + echo "Session saved to " . session_file +endfunction + +command! LoadSession call LoadSession() +function! LoadSession() + let session_file = g:session_dir . GetRepositoryName() . '_' . GetCurrentGitBranch() . '.vim' + if filereadable(session_file) + execute 'source ' . session_file + echo "Session loaded from " . session_file + else + echo "No session found for the current Git branch in the repository" + endif +endfunction + +nnoremap ss :SaveSession +nnoremap sl :LoadSession +]]) diff --git a/.config/nvim/lua/func/tabline.lua b/.config/nvim/lua/func/tabline.lua new file mode 100644 index 0000000..12f44a4 --- /dev/null +++ b/.config/nvim/lua/func/tabline.lua @@ -0,0 +1,43 @@ +vim.cmd([[ +set showtabline=2 +set tabline=%!TabLineNumbered() + +function! TabLineNumbered() + let s = '' + let wn = '' + let t = tabpagenr() + let i = 1 + while i <= tabpagenr('$') + let buflist = tabpagebuflist(i) + let buf = buflist[tabpagewinnr(i) - 1] + let file = fnamemodify(bufname(buf), ':t') + if i == t + let s .= '%' . i . 'T' + let s .= '%#TabLineSel#' + let wn .= '%' . i . 'T' + let wn .= '%#TabLineSel#' + else + let s .= '%' . i . 'T' + let s .= '%#TabLine#' + let wn .= '%' . i . 'T' + let wn .= '%#TabLine#' + endif + + let s .= ' ' . i . ' ' + let wn .= ' ' . i . ' ' + + " Truncate the file name if it's too long + if len(file) > 20 + let file = strpart(file, 0, 20) . '..' + endif + let s .= file . ' ' + let wn .= file . ' ' + let s .= '%T' + let wn .= '%T' + let s .= '%#TabLine#|' + let wn .= '%#TabLine#|' + let i += 1 + endwhile + return s +endfunction +]]) diff --git a/.config/nvim/lua/func/utils.lua b/.config/nvim/lua/func/utils.lua new file mode 100644 index 0000000..1f43566 --- /dev/null +++ b/.config/nvim/lua/func/utils.lua @@ -0,0 +1,14 @@ +vim.cmd([[ +function! GetRepositoryName() + let repo_path = system("git -C " . getcwd() . " rev-parse --show-toplevel") + let repo_name = fnamemodify(trim(repo_path), ':t') + let repo_name_clean = substitute(repo_name, '[\/\-\s]', '_', 'g') + return repo_name_clean +endfunction + +function! GetCurrentGitBranch() + let l:branch = system("git -C " . getcwd() . " branch --show-current") + let l:branch_clean = substitute(trim(l:branch), '[\/\-\s]', '_', 'g') + return l:branch_clean +endfunction +]]) diff --git a/.config/nvim/lua/keys.lua b/.config/nvim/lua/keys.lua index 6746e84..77b5c33 100644 --- a/.config/nvim/lua/keys.lua +++ b/.config/nvim/lua/keys.lua @@ -45,4 +45,9 @@ map('', '', ':NvimTreeToggle', {}) map('n', 'l', ':IndentLinesToggle', {}) map('n', 't', ':TagbarToggle', {}) map('n', 'ff', [[:Telescope find_files]], {}) -map('n', 'T', ':lua require("FTerm").toggle()', {}) +-- map('n', 'T', ':lua require("FTerm").toggle()', {}) + +-- Open a file in a vertical split, horizontal split and move a split to a new tab +map('n', 'sv', ':vsplit ', {noremap = true, silent = false}) +map('n', 'sh', ':split ', {noremap = true, silent = false}) +map('n', 'mt', ':tabedit %', {noremap = true, silent = true}) diff --git a/.config/password-store b/.config/password-store index ffde3d6..8bafa73 160000 --- a/.config/password-store +++ b/.config/password-store @@ -1 +1 @@ -Subproject commit ffde3d6a5fa4ec163abf5923c1aba6c28ac6d47b +Subproject commit 8bafa7394bfcb8cfbafc43190be64cee6e70aa7c diff --git a/.config/shell/aliases b/.config/shell/aliases index 56a61ab..42119bf 100644 --- a/.config/shell/aliases +++ b/.config/shell/aliases @@ -59,6 +59,7 @@ alias sshconfig="$EDITOR ~/.ssh/config" alias edithosts="sudoedit /etc/hosts" alias vimrc="(cd ~/.config/nvim/; $EDITOR)" alias tigrc="$EDITOR $HOME/.config/tig/config" +alias swayrc="$EDITOR ~/.config/sway/config" # yadm alias yap="yadm add -p" @@ -81,8 +82,16 @@ alias lvcreate='sudo lvcreate' alias lvresize='sudo lvresize' # BTRFS -alias snapshot_home="sudo btrfs subvol snapshot /mnt/btrfsroot/home /.snaps/home@$(date '+%Y-%m-%d_%H-%M-%S')" -alias snapshot_rootfs="sudo btrfs subvol snapshot /mnt/btrfsroot/rootfs /.snaps/rootfs@$(date '+%Y-%m-%d_%H-%M-%S')" +alias snapshot_home="sudo btrfs subvol snapshot /mnt/btrfsroot/@home /.snaps/home@$(date +'%Y%m%d')" +alias snapshot_rootfs="sudo btrfs subvol snapshot /mnt/btrfsroot/@rootfs /.snaps/rootfs@$(date +'%Y%m%d')" + +# sudo rm /mnt/btrfsroot/@snaps/home-latest +# sudo btrfs subvolume snapshot -r /mnt/btrfsroot/@home /mnt/btrfsroot/@snaps/home-$(shdate) +# sudo ln -s /mnt/btrfsroot/@snaps/home-$(shdate) /mnt/btrfsroot/@snaps/home-latest + +# sudo rm /mnt/btrfsroot/@snaps/rootfs-latest +# sudo btrfs subvolume snapshot -r /mnt/btrfsroot/@rootfs /mnt/btrfsroot/@snaps/rootfs-$(shdate) +# sudo ln -s /mnt/btrfsroot/@snaps/rootfs-$(shdate) /mnt/btrfsroot/@snaps/rootfs-latest # youtube-dl alias soundcloud-dl='youtube-dlc --extract-audio --audio-format vorbis --audio-quality 2' diff --git a/.config/waybar/config b/.config/waybar/config index 8acf9ed..a087af3 100644 --- a/.config/waybar/config +++ b/.config/waybar/config @@ -68,7 +68,7 @@ "tooltip": false }, "clock#3": { - "format": "{:%m-%d}", + "format": "{:%Y-%m-%d}", "tooltip": false },