multiple updates

vim/nvim functions/keys
shell aliases
waybar config
password-store submodule
This commit is contained in:
Ben Vincent 2024-03-09 11:47:06 +11:00
parent d935c04dad
commit 14159884fa
10 changed files with 164 additions and 13 deletions

View File

@ -4,7 +4,10 @@
vim.cmd [[ vim.cmd [[
augroup lang_all augroup lang_all
autocmd! 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/tabline.lua
autocmd FileType * luafile ~/.config/nvim/lua/func/popterm.lua
autocmd FileType * luafile ~/.config/nvim/lua/func/sessions.lua
augroup END augroup END
]] ]]
@ -12,7 +15,10 @@ vim.cmd [[
vim.cmd [[ vim.cmd [[
augroup lang_puppet augroup lang_puppet
autocmd! autocmd!
autocmd FileType puppet nnoremap <buffer> <Leader>g :call OpenPuppetClassOrTemplate()<CR> autocmd FileType puppet nnoremap <buffer> <Leader>gg :call OpenPuppetClassOrTemplate(tab)<CR>
autocmd FileType puppet nnoremap <buffer> <Leader>gt :call OpenPuppetClassOrTemplate(tab)<CR>
autocmd FileType puppet nnoremap <buffer> <Leader>gh :call OpenPuppetClassOrTemplate(horizontal)<CR>
autocmd FileType puppet nnoremap <buffer> <Leader>gv :call OpenPuppetClassOrTemplate(vertical)<CR>
autocmd FileType puppet nnoremap <buffer> <Leader>t :call OpenPuppetTestMode()<CR> autocmd FileType puppet nnoremap <buffer> <Leader>t :call OpenPuppetTestMode()<CR>
autocmd BufNewFile site/roles/manifests/**.pp call ApplyPuppetTemplate() autocmd BufNewFile site/roles/manifests/**.pp call ApplyPuppetTemplate()
autocmd BufNewFile site/profiles/manifests/**.pp call ApplyPuppetTemplate() autocmd BufNewFile site/profiles/manifests/**.pp call ApplyPuppetTemplate()

View File

@ -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<CR>
autocmd TermOpen * setlocal winhighlight=Normal:Terminal
endif
]])

View File

@ -10,7 +10,7 @@ function! OpenPuppetTestMode()
echo " v - puppet-validate" echo " v - puppet-validate"
echo " l - puppet-lint" echo " l - puppet-lint"
echo " q - quit test mode" echo " q - quit test mode"
" Keybinding to run tests on the current buffer " Keybinding to run tests on the current buffer
nnoremap <buffer> v :!/usr/local/bin/puppet-validate %<CR> nnoremap <buffer> v :!/usr/local/bin/puppet-validate %<CR>
nnoremap <buffer> l :!/usr/local/bin/puppet-lint %<CR> nnoremap <buffer> l :!/usr/local/bin/puppet-lint %<CR>
@ -35,7 +35,7 @@ endfunction
-- follow links to classes -- follow links to classes
vim.cmd([[ vim.cmd([[
function! OpenPuppetProfileOrRole() function! OpenPuppetProfileOrRole(layout)
" Get the line under the cursor " Get the line under the cursor
let line = getline(".") let line = getline(".")
@ -65,14 +65,21 @@ function! OpenPuppetProfileOrRole()
let fullpath = dirpath . filepath . ".pp" let fullpath = dirpath . filepath . ".pp"
" Open the file in a new tab " 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 endfunction
]]) ]])
-- follow links to templates -- follow links to templates
vim.cmd([[ vim.cmd([[
function! OpenPuppetTemplate() function! OpenPuppetTemplate(layout)
" Get the line under the cursor " Get the line under the cursor
let line = getline(".") let line = getline(".")
@ -95,8 +102,15 @@ function! OpenPuppetTemplate()
let fullpath = newpath let fullpath = newpath
" Open the file in a new tab " 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 endfunction
]]) ]])

View File

@ -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 <silent> <Leader>ss :SaveSession<CR>
nnoremap <silent> <Leader>sl :LoadSession<CR>
]])

View File

@ -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
]])

View File

@ -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
]])

View File

@ -45,4 +45,9 @@ map('', '<C-n>', ':NvimTreeToggle<CR>', {})
map('n', 'l', ':IndentLinesToggle<CR>', {}) map('n', 'l', ':IndentLinesToggle<CR>', {})
map('n', 't', ':TagbarToggle<CR>', {}) map('n', 't', ':TagbarToggle<CR>', {})
map('n', 'ff', [[:Telescope find_files]], {}) map('n', 'ff', [[:Telescope find_files]], {})
map('n', 'T', ':lua require("FTerm").toggle()<CR>', {}) -- map('n', 'T', ':lua require("FTerm").toggle()<CR>', {})
-- Open a file in a vertical split, horizontal split and move a split to a new tab
map('n', '<Leader>sv', ':vsplit ', {noremap = true, silent = false})
map('n', '<Leader>sh', ':split ', {noremap = true, silent = false})
map('n', '<Leader>mt', ':tabedit %<CR>', {noremap = true, silent = true})

@ -1 +1 @@
Subproject commit ffde3d6a5fa4ec163abf5923c1aba6c28ac6d47b Subproject commit 8bafa7394bfcb8cfbafc43190be64cee6e70aa7c

View File

@ -59,6 +59,7 @@ alias sshconfig="$EDITOR ~/.ssh/config"
alias edithosts="sudoedit /etc/hosts" alias edithosts="sudoedit /etc/hosts"
alias vimrc="(cd ~/.config/nvim/; $EDITOR)" alias vimrc="(cd ~/.config/nvim/; $EDITOR)"
alias tigrc="$EDITOR $HOME/.config/tig/config" alias tigrc="$EDITOR $HOME/.config/tig/config"
alias swayrc="$EDITOR ~/.config/sway/config"
# yadm # yadm
alias yap="yadm add -p" alias yap="yadm add -p"
@ -81,8 +82,16 @@ alias lvcreate='sudo lvcreate'
alias lvresize='sudo lvresize' alias lvresize='sudo lvresize'
# BTRFS # BTRFS
alias snapshot_home="sudo btrfs subvol snapshot /mnt/btrfsroot/home /.snaps/home@$(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_%H-%M-%S')" 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 # youtube-dl
alias soundcloud-dl='youtube-dlc --extract-audio --audio-format vorbis --audio-quality 2' alias soundcloud-dl='youtube-dlc --extract-audio --audio-format vorbis --audio-quality 2'

View File

@ -68,7 +68,7 @@
"tooltip": false "tooltip": false
}, },
"clock#3": { "clock#3": {
"format": "{:%m-%d}", "format": "{:%Y-%m-%d}",
"tooltip": false "tooltip": false
}, },