mirror of
https://git.disroot.org/FollieHiyuki/dotfiles.git
synced 2024-11-25 00:38:23 -05:00
neovim: configure packer.nvim + add iswap.nvim
This commit is contained in:
parent
a8e3fb728b
commit
dfcfbd004a
@ -1,2 +1,3 @@
|
||||
setlocal spell
|
||||
setlocal wrap
|
||||
" setlocal nonumber norelativenumber
|
||||
|
@ -1,2 +1,3 @@
|
||||
setlocal spell
|
||||
setlocal wrap
|
||||
" setlocal nonumber norelativenumber
|
||||
|
@ -2,7 +2,7 @@ local async
|
||||
async = vim.loop.new_async(vim.schedule_wrap(function()
|
||||
require('plugins')
|
||||
require('mappings')
|
||||
require('events').load_autocmds()
|
||||
require('autocmd')
|
||||
async:close()
|
||||
end))
|
||||
|
||||
|
49
home/.config/nvim/lua/autocmd.lua
Normal file
49
home/.config/nvim/lua/autocmd.lua
Normal file
@ -0,0 +1,49 @@
|
||||
local definitions = {
|
||||
-- ':h hex-editing'
|
||||
binary = {
|
||||
{'BufReadPre' , '*.bin,*.exe', 'let &bin=1'},
|
||||
{'BufReadPost' , '*.bin,*.exe', 'if &bin | %!xxd'},
|
||||
{'BufReadPost' , '*.bin,*.exe', 'set ft=xxd | endif'},
|
||||
{'BufWritePre' , '*.bin,*.exe', 'if &bin | %!xxd -r'},
|
||||
{'BufWritePre' , '*.bin,*.exe', 'endif'},
|
||||
{'BufWritePost', '*.bin,*.exe', 'if &bin | %!xxd'},
|
||||
{'BufWritePost', '*.bin,*.exe', 'set nomod | endif'}
|
||||
},
|
||||
|
||||
-- Auto-hide UI elements in specific buffers
|
||||
buf = {
|
||||
{'BufEnter', 'term://*', 'setlocal norelativenumber nonumber'},
|
||||
-- {'BufEnter,BufWinEnter,WinEnter,CmdwinEnter', '*', [[if bufname('%') == 'NvimTree' | set laststatus=0 | else | set laststatus=2 | endif]]}
|
||||
},
|
||||
|
||||
wins = {
|
||||
-- Equalize window dimensions when resizing vim window
|
||||
{'VimResized', '*', 'tabdo wincmd ='},
|
||||
-- Force writing shada on leaving nvim
|
||||
{'VimLeave', '*', [[if has('nvim') | wshada! | else | wviminfo! | endif]]},
|
||||
-- Check if file changed when its window is focus, more eager than 'autoread'
|
||||
{'FocusGained', '* checktime'}
|
||||
},
|
||||
|
||||
ft = {
|
||||
{'BufNewFile,BufRead', '*.md,*.mkd', 'setfiletype markdown'},
|
||||
{'BufNewFile,BufRead', '*.toml', 'setfiletype toml'},
|
||||
{'BufNewFile,BufRead', '*.rasi', 'setfiletype css'},
|
||||
{'BufNewFile,BufRead', 'vifmrc,*.vifm', 'setfiletype vim'},
|
||||
{'BufNewFile,BufRead', '*.log,*_log,*.LO,G*_LOG', 'setfiletype log'}
|
||||
},
|
||||
|
||||
yank = {
|
||||
{'TextYankPost', [[* silent! lua vim.highlight.on_yank({higroup='IncSearch', timeout=300})]]}
|
||||
}
|
||||
}
|
||||
|
||||
for group_name, definition in pairs(definitions) do
|
||||
vim.api.nvim_command('augroup ' .. group_name)
|
||||
vim.api.nvim_command('autocmd!')
|
||||
for _, def in ipairs(definition) do
|
||||
local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
|
||||
vim.api.nvim_command(command)
|
||||
end
|
||||
vim.api.nvim_command('augroup END')
|
||||
end
|
@ -297,22 +297,15 @@ local function highlight_plugins()
|
||||
hi('rainbowcol6', c.blue, '', 'bold', '')
|
||||
hi('rainbowcol7', c.purple, '', 'bold', '')
|
||||
|
||||
-- todo-comments
|
||||
hi('TodoDefault', c.fg, '', 'bold', '')
|
||||
hi('TodoError', c.red, '', 'bold', '')
|
||||
hi('TodoWarn', c.yellow, '', 'bold', '')
|
||||
hi('TodoInfo', c.blue, '', 'bold', '')
|
||||
hi('TodoHint', c.cyan, '', 'bold', '')
|
||||
|
||||
-- hop.nvim
|
||||
hi('HopNextKey', c.red, '', 'bold', '')
|
||||
hi('HopNextKey1', c.cyan, '', 'bold', '')
|
||||
hi('HopNextKey2', c.dark_blue, '', '', '')
|
||||
hi('HopUnmatched', c.grey3, '', '', '')
|
||||
vim.api.nvim_command('hi! link HopUnmatched LineNr')
|
||||
|
||||
-- vim-eft
|
||||
hi('EftChar' , c.orange, '', 'bold,underline', '')
|
||||
hi('EftSubChar', c.grey3, '', 'bold,underline', '')
|
||||
hi('EftChar', c.orange, '', 'bold,underline', '')
|
||||
vim.api.nvim_command('hi! link EftSubChar LineNr')
|
||||
|
||||
-- dashboard-nvim / alpha-nvim
|
||||
hi('DashboardHeader' , c.blue , '', 'bold' , '')
|
||||
|
@ -1,86 +0,0 @@
|
||||
local plug_dir = vim.fn.stdpath('config') .. '/lua'
|
||||
local M = {}
|
||||
|
||||
function M.packer_compile()
|
||||
local file = vim.fn.expand('%:p')
|
||||
if file:match(plug_dir) then
|
||||
vim.api.nvim_command('source <afile> | PackerCompile')
|
||||
end
|
||||
end
|
||||
|
||||
function M.nvim_create_augroups(definitions)
|
||||
for group_name, definition in pairs(definitions) do
|
||||
vim.api.nvim_command('augroup ' .. group_name)
|
||||
vim.api.nvim_command('autocmd!')
|
||||
for _, def in ipairs(definition) do
|
||||
local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
|
||||
vim.api.nvim_command(command)
|
||||
end
|
||||
vim.api.nvim_command('augroup END')
|
||||
end
|
||||
end
|
||||
|
||||
function M.load_autocmds()
|
||||
local definitions = {
|
||||
plugins = {
|
||||
-- Wrap lines in preview window
|
||||
-- {"User TelescopePreviewerLoaded", [[setlocal wrap]]},
|
||||
|
||||
-- Re-compile packer on config changed
|
||||
{"BufWritePost", "*.lua", "lua require('events').packer_compile()"},
|
||||
|
||||
-- Register binding for ToggleTerm inside term mode
|
||||
{"TermEnter", "term://*toggleterm#*", "tnoremap <silent><C-\\> <C-\\><C-n>:ToggleTerm<CR>"}
|
||||
},
|
||||
|
||||
-- Edit binary files in hex with xxd (:%!xxd and :%!xxd -r)
|
||||
-- or using nvim -b to edit files using xxd-format
|
||||
binary = {
|
||||
{"BufReadPre" , "*.bin,*.exe", "let &bin=1"},
|
||||
{"BufReadPost" , "*.bin,*.exe", "if &bin | %!xxd"},
|
||||
{"BufReadPost" , "*.bin,*.exe", "set ft=xxd | endif"},
|
||||
{"BufWritePre" , "*.bin,*.exe", "if &bin | %!xxd -r"},
|
||||
{"BufWritePre" , "*.bin,*.exe", "endif"},
|
||||
{"BufWritePost", "*.bin,*.exe", "if &bin | %!xxd"},
|
||||
{"BufWritePost", "*.bin,*.exe", "set nomod | endif"}
|
||||
},
|
||||
|
||||
buf = {
|
||||
-- Auto-spelling in doc files
|
||||
{"BufNewFile,BufRead", "*.md,*.mkd", "setlocal spell"},
|
||||
{"BufNewFile,BufRead", "*.tex", "setlocal spell"},
|
||||
|
||||
-- Auto-hide numbers, statusline in specific buffers
|
||||
-- {"BufEnter", "term://*", "setlocal norelativenumber nonumber"},
|
||||
-- {"BufEnter", "term://*", "set laststatus=0"},
|
||||
-- {"BufEnter,BufWinEnter,WinEnter,CmdwinEnter", "*", [[if bufname('%') == "NvimTree" | set laststatus=0 | else | set laststatus=2 | endif]]}
|
||||
},
|
||||
|
||||
wins = {
|
||||
-- Equalize window dimensions when resizing vim window
|
||||
{"VimResized", "*", [[tabdo wincmd =]]},
|
||||
|
||||
-- Force writing shada on leaving nvim
|
||||
{"VimLeave", "*", [[if has('nvim') | wshada! | else | wviminfo! | endif]]},
|
||||
|
||||
-- Check if file changed when its window is focus, more eager than 'autoread'
|
||||
{"FocusGained", "* checktime"}
|
||||
},
|
||||
|
||||
ft = {
|
||||
{"BufNewFile,BufRead", "*.md,*.mkd", "setfiletype markdown"},
|
||||
{"BufNewFile,BufRead", "*.toml", "setfiletype toml"},
|
||||
{"BufNewFile,BufRead", "*.rasi", "setfiletype css"},
|
||||
{"BufNewFile,BufRead", "vifmrc,*.vifm", "setfiletype vim"},
|
||||
{"BufNewFile,BufRead", "*.log,*_log,*.LO,G*_LOG", "setfiletype log"}
|
||||
},
|
||||
|
||||
yank = {
|
||||
{"TextYankPost", [[* silent! lua vim.highlight.on_yank({higroup="IncSearch", timeout=300})]]}
|
||||
}
|
||||
}
|
||||
|
||||
M.nvim_create_augroups(definitions)
|
||||
end
|
||||
|
||||
return M
|
@ -52,10 +52,10 @@ wk.register({
|
||||
L = {'$', 'End of the line'},
|
||||
|
||||
-- Easier moving between windows
|
||||
['<C-h>'] = {'<C-w>h', 'Go to the left window'},
|
||||
['<C-l>'] = {'<C-w>l', 'Go to the right window'},
|
||||
['<C-j>'] = {'<C-w>j', 'Go to the down window'},
|
||||
['<C-k>'] = {'<C-w>k', 'Go to the up window'},
|
||||
-- ['<C-h>'] = {'<C-w>h', 'Go to the left window'},
|
||||
-- ['<C-l>'] = {'<C-w>l', 'Go to the right window'},
|
||||
-- ['<C-j>'] = {'<C-w>j', 'Go to the down window'},
|
||||
-- ['<C-k>'] = {'<C-w>k', 'Go to the up window'},
|
||||
['<C-q>'] = {'<C-w>q', 'Quit a window'},
|
||||
|
||||
-- Copy the whole buffer
|
||||
@ -133,7 +133,11 @@ wk.register({
|
||||
-- Normal mode (with leader key) --
|
||||
-----------------------------------
|
||||
wk.register({
|
||||
a = {':EasyAlign<CR>', 'Align'},
|
||||
a = {
|
||||
name = 'Action',
|
||||
a = {':EasyAlign<CR>', 'Align elements'},
|
||||
s = {':ISwapWith<CR>', 'Swap elements'}
|
||||
},
|
||||
|
||||
b = {
|
||||
name = 'Buffer/Tab',
|
||||
@ -315,7 +319,10 @@ wk.register({
|
||||
-- Visual mode (with leader key) --
|
||||
-----------------------------------
|
||||
wk.register({
|
||||
a = {':EasyAlign<CR>', 'Range align'},
|
||||
a = {
|
||||
name = 'Action',
|
||||
a = {':EasyAlign<CR>', 'Range align'}
|
||||
},
|
||||
|
||||
d = {
|
||||
name = 'DAP',
|
||||
|
@ -54,7 +54,7 @@ function M.cmp_conf()
|
||||
nvim_lsp = '[LSP]',
|
||||
-- cmp_tabnine = '[TN]',
|
||||
latex_symbols = '[TEX]',
|
||||
tmux = '[TMUX]',
|
||||
-- tmux = '[TMUX]',
|
||||
orgmode = '[ORG]'
|
||||
})[entry.source.name]
|
||||
|
||||
@ -121,7 +121,7 @@ function M.cmp_conf()
|
||||
-- {name = 'cmp_tabnine'},
|
||||
{name = 'conjure'},
|
||||
{name = 'latex_symbols'},
|
||||
{name = 'tmux'},
|
||||
-- {name = 'tmux'},
|
||||
{name = 'orgmode'}
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ function M.treesitter_conf()
|
||||
textobjects = {
|
||||
select = {
|
||||
enable = true,
|
||||
lookahead = true,
|
||||
keymaps = {
|
||||
['af'] = '@function.outer',
|
||||
['if'] = '@function.inner',
|
||||
@ -98,6 +99,34 @@ function M.treesitter_conf()
|
||||
}
|
||||
end
|
||||
|
||||
function M.iswap_conf()
|
||||
require('iswap').setup {
|
||||
-- The keys that will be used as a selection, in order
|
||||
-- ('asdfghjklqwertyuiopzxcvbnm' by default)
|
||||
-- keys = 'qwertyuiop',
|
||||
|
||||
-- Grey out the rest of the text when making a selection
|
||||
-- (enabled by default)
|
||||
-- grey = 'disable',
|
||||
|
||||
-- Highlight group for the sniping value (asdf etc.)
|
||||
-- default 'Search'
|
||||
-- hl_snipe = 'ErrorMsg',
|
||||
|
||||
-- Highlight group for the visual selection of terms
|
||||
-- default 'Visual'
|
||||
-- hl_selection = 'WarningMsg',
|
||||
|
||||
-- Highlight group for the greyed background
|
||||
-- default 'Comment'
|
||||
hl_grey = 'LineNr',
|
||||
|
||||
-- Automatically swap with only two arguments
|
||||
-- default nil
|
||||
autoswap = true
|
||||
}
|
||||
end
|
||||
|
||||
function M.rainbow_conf()
|
||||
require('nvim-treesitter.configs').setup {
|
||||
rainbow = {
|
||||
|
@ -228,11 +228,11 @@ end
|
||||
-- exclude = {'org'}, -- list of file types to exclude highlighting
|
||||
-- },
|
||||
-- colors = {
|
||||
-- error = {'TodoError', 'Red'},
|
||||
-- warning = {'TodoWarn', 'Yellow'},
|
||||
-- info = {'TodoInfo', 'Blue'},
|
||||
-- hint = {'TodoHint', 'Cyan'},
|
||||
-- default = {'TodoDefault', 'White'}
|
||||
-- error = {'LspDiagnosticsDefaultError', 'Red'},
|
||||
-- warning = {'LspDiagnosticsDefaultWarning', 'Yellow'},
|
||||
-- info = {'LspDiagnosticsDefaultInformation', 'Blue'},
|
||||
-- hint = {'LspDiagnosticsDefaultHint', 'Cyan'},
|
||||
-- default = {'Normal', 'White'}
|
||||
-- },
|
||||
-- search = {
|
||||
-- command = 'rg',
|
||||
|
65
home/.config/nvim/lua/modules/pack.lua
Normal file
65
home/.config/nvim/lua/modules/pack.lua
Normal file
@ -0,0 +1,65 @@
|
||||
local fn, api = vim.fn, vim.api
|
||||
|
||||
-- Require since we use 'packer' as opt
|
||||
api.nvim_command('packadd packer.nvim')
|
||||
local present, packer = pcall(require, 'packer')
|
||||
|
||||
if not present then
|
||||
local packer_dir = fn.stdpath('data') .. '/site/pack/packer/opt/packer.nvim'
|
||||
|
||||
print('Cloning packer ...')
|
||||
-- remove packer_dir before cloning
|
||||
fn.delete(packer_dir, 'rf')
|
||||
fn.system {'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_dir}
|
||||
api.nvim_command('packadd packer.nvim')
|
||||
present, packer = pcall(require, 'packer')
|
||||
|
||||
if present then
|
||||
print('Pakcer cloned successfully.')
|
||||
else
|
||||
error('Git clone error for packer!')
|
||||
end
|
||||
end
|
||||
|
||||
local util = require('packer.util')
|
||||
|
||||
packer.init {
|
||||
compile_path = util.join_paths(fn.stdpath('data'), 'site', 'plugin', 'packer_compiled.lua'),
|
||||
auto_clean = true,
|
||||
compile_on_sync = true,
|
||||
auto_reload_compiled = true,
|
||||
git = {
|
||||
-- default_url_format = 'https://github.com/%s',
|
||||
clone_timeout = 120
|
||||
},
|
||||
display = {
|
||||
-- open_fn = function()
|
||||
-- return util.float {border = 'single'}
|
||||
-- end,
|
||||
open_cmd = '60vnew \\[packer\\]',
|
||||
working_sym = '⟳',
|
||||
error_sym = '✗',
|
||||
done_sym = '✓',
|
||||
removed_sym = '-',
|
||||
moved_sym = '→',
|
||||
header_sym = '━',
|
||||
show_all_info = true,
|
||||
prompt_boder = 'single'
|
||||
},
|
||||
-- profile = {enable = true, threshold = 1},
|
||||
luarocks = {python_cmd = 'python3'}
|
||||
}
|
||||
|
||||
-- Re-compile packer on config changed
|
||||
_G.packer_compile_on_save = function()
|
||||
local file = fn.expand('%:p')
|
||||
local filename = fn.expand('%:p:t')
|
||||
local config_dir = fn.stdpath('config') .. '/lua'
|
||||
|
||||
if file:match(config_dir) and filename ~= 'pack.lua' then
|
||||
vim.api.nvim_command('source <afile> | PackerCompile')
|
||||
end
|
||||
end
|
||||
api.nvim_command('autocmd BufWritePost *.lua lua packer_compile_on_save()')
|
||||
|
||||
return packer
|
@ -46,6 +46,9 @@ function M.telescope_conf()
|
||||
require('telescope').load_extension('projects')
|
||||
require('telescope').load_extension('project')
|
||||
require('telescope').load_extension('fzf')
|
||||
|
||||
-- wrap lines inside preview pane
|
||||
vim.api.nvim_command('autocmd User TelescopePreviewerLoaded setlocal wrap')
|
||||
end
|
||||
|
||||
function M.octo_conf()
|
||||
|
@ -1,16 +1,9 @@
|
||||
local fn,api = vim.fn,vim.api
|
||||
local packer_dir = fn.stdpath('data') .. '/site/pack/packer/opt/packer.nvim'
|
||||
local packer = require('modules.pack')
|
||||
|
||||
if fn.empty(fn.glob(packer_dir)) > 0 then
|
||||
fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', packer_dir})
|
||||
api.nvim_command('packadd packer.nvim')
|
||||
end
|
||||
-- This is recommended when using `luafile <afile>` a lot
|
||||
-- packer.reset()
|
||||
|
||||
-- Require since we use 'packer' as opt
|
||||
api.nvim_command [[packadd packer.nvim]]
|
||||
|
||||
return require('packer').startup(
|
||||
function(use)
|
||||
return packer.startup(function(use)
|
||||
use {'wbthomason/packer.nvim', opt = true}
|
||||
|
||||
---------------------------------
|
||||
@ -112,6 +105,12 @@ return require('packer').startup(
|
||||
'nvim-treesitter/nvim-treesitter-textobjects',
|
||||
after = 'nvim-treesitter'
|
||||
}
|
||||
use {
|
||||
'mizlan/iswap.nvim',
|
||||
cmd = {'ISwapWith', 'ISwap'},
|
||||
wants = 'nvim-treesitter',
|
||||
config = editor.iswap_conf
|
||||
}
|
||||
use {
|
||||
'andymass/vim-matchup',
|
||||
after = 'nvim-treesitter',
|
||||
@ -234,7 +233,7 @@ return require('packer').startup(
|
||||
-- config = completion.tabnine_conf
|
||||
-- }
|
||||
use {'kdheepak/cmp-latex-symbols', after = {'nvim-cmp', 'vimtex'}}
|
||||
use {'andersevenrud/compe-tmux', after = 'nvim-cmp', branch = 'cmp'}
|
||||
-- use {'andersevenrud/compe-tmux', after = 'nvim-cmp', branch = 'cmp'}
|
||||
use {'PaterJason/cmp-conjure', after = {'conjure', 'nvim-cmp'}}
|
||||
use {
|
||||
'windwp/nvim-autopairs',
|
||||
@ -395,9 +394,11 @@ return require('packer').startup(
|
||||
event = 'BufEnter',
|
||||
config = tools.session_conf
|
||||
}
|
||||
-- use {'dstein64/vim-startuptime', cmd = 'StartupTime'} -- Just for benchmarking
|
||||
use {'dstein64/vim-startuptime', cmd = 'StartupTime'} -- Just for benchmarking
|
||||
|
||||
-- TODO: dial.nvim, rust-tools.nvim, crates.nvim, go.nvim, clojure-vim/*,
|
||||
-- nvim-bqf, nvim-comment-frame, nvim-revJ.lua
|
||||
end
|
||||
)
|
||||
|
||||
-- Install plugins if missing
|
||||
packer.install()
|
||||
end)
|
||||
|
104
home/.local/bin/doasedit
Executable file
104
home/.local/bin/doasedit
Executable file
@ -0,0 +1,104 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# doasedit
|
||||
# Link: git.io/doasedit
|
||||
|
||||
# Dependencies: opendoas <https://github.com/Duncaen/OpenDoas> or doas <https://cvsweb.openbsd.org/src/usr.bin/doas/>
|
||||
|
||||
# Author: Stanislav <git.io/monesonn>
|
||||
# Description: doas equivalent to sudoedit.
|
||||
# Licence: ISC
|
||||
# Contribution: If you have some ideas, how to improve this script, feel free to make pull request or write an issue.
|
||||
|
||||
# Tips: Use this script with enabled persistence in doas.conf file, like:
|
||||
#
|
||||
# `permit persist :wheel`
|
||||
#
|
||||
# Also make sure that your doas.conf is owned by root with read-only permissions, like:
|
||||
#
|
||||
# # chown -c root:root /path/to/doas.conf && chmod 0400 path/to/doas.conf
|
||||
#
|
||||
|
||||
# Throw error message.
|
||||
err() {
|
||||
printf "%s%s\n" "doasedit: " "${1}" >&2
|
||||
exit "${2}"
|
||||
}
|
||||
|
||||
# Catch arguments.
|
||||
if [ -n "${2}" ]; then
|
||||
err "expected only one argument" 1
|
||||
elif [ -z "${1}" ]; then
|
||||
err "no file path provided" 2
|
||||
elif [ "$(id -u)" -eq 0 ]; then
|
||||
err "doasedit: cannot be run as root" 3
|
||||
elif [ -d "${1}" ]; then
|
||||
err "${1} is a directory" 4
|
||||
fi
|
||||
|
||||
# Safe shell options.
|
||||
set -eu
|
||||
|
||||
# Reset doas password promt. If you want, feel free to comment this.
|
||||
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
|
||||
linux) doas -L ;;
|
||||
esac
|
||||
|
||||
# Absolute path to the source file (file for editing).
|
||||
src="$(doas readlink -f "${1}")"
|
||||
|
||||
# Filename for the source file.
|
||||
filename="${src##*/}"
|
||||
|
||||
# If filename have suffix then also use it for a temporary file.
|
||||
# It's kinda useful for editors, that have plugins or something else for certain file extensions.
|
||||
[ "$filename" = "${filename##*.}" ] && filename_ext="" || filename_ext=".${filename##*.}"
|
||||
|
||||
# Be sure /tmp as tmp directory by setting TMPDIR env.
|
||||
export TMPDIR=/tmp
|
||||
|
||||
# Create a temporary directory.
|
||||
tmp_d=$(mktemp -d)
|
||||
|
||||
# Create a temporary file for the source file in a temporary directory.
|
||||
tmp_f="${tmp_d}/${filename}$(xxd -l4 -ps /dev/urandom)${filename_ext}"
|
||||
|
||||
# File writeability condition.
|
||||
if [ -w "$src" ]; then
|
||||
err "$filename: editing files in a writable directory is not permitted" 5
|
||||
fi
|
||||
|
||||
# Other conditions: if file exist, readable, etc.
|
||||
if [ -f "${src}" ] && [ ! -r "${src}" ]; then
|
||||
doas cat "${src}" > "${tmp_f}" || err "the file is not readable" 6
|
||||
elif [ -r "${src}" ]; then
|
||||
cat "${src}" > "${tmp_f}" || err "cannot transfer to content of the file to temporary one" 7
|
||||
elif [ ! -f "${src}" ]; then
|
||||
# Grant .rw-r--r-- permission for newly created files by default owned by root.
|
||||
:> "${tmp_f}" && doas chmod -R 0644 "${tmp_f}" || err "cannot create new file" 8
|
||||
else
|
||||
err "unexpected script behaviour" 9
|
||||
fi
|
||||
|
||||
# Create copy of the temporary file.
|
||||
tmp_cf="${tmp_d}/${filename}$(xxd -l4 -ps /dev/urandom).copy"
|
||||
|
||||
# Hooks for recursive removing of a temporary directory.
|
||||
trap 'rm -rf ${tmp_d}' EXIT HUP QUIT TERM INT ABRT
|
||||
|
||||
# Move the contents of a temporary file to its copy for later comparison.
|
||||
cat "${tmp_f}" > "${tmp_cf}"
|
||||
|
||||
# Editing the file by the user using the default editor, if not specified, the vi is used.
|
||||
${EDITOR:-vi} "${tmp_f}"
|
||||
|
||||
# Compare the temporary file and the temporary copy.
|
||||
if cmp -s "${tmp_f}" "${tmp_cf}"; then
|
||||
printf "%s\n" "doasedit: $filename unchanged"
|
||||
exit 0
|
||||
else
|
||||
# Replace the source file with temporary, repeats three times if it fails.
|
||||
for doas_tries in $(seq 1 3); do doas cp -f "${tmp_f}" "${src}" && break; done
|
||||
printf "%s\n" "doasedit: $filename changes are accepted"
|
||||
exit 0
|
||||
fi
|
@ -1,20 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "$1" = "-h" ]; then
|
||||
echo "Usage: pancomp [input_format] [input_file] [output_format] [output_file]"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ $# -ne 4 ]; then
|
||||
echo "Bruh, I need 4 arguments."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pandoc \
|
||||
--pdf-engine=xelatex \
|
||||
-V 'mainfont:Iosevka Etoile' \
|
||||
-V 'sansfont:Iosevka Aile' \
|
||||
-V 'monofont:Iosevka' \
|
||||
-V 'geometry:margin=1in' \
|
||||
-f "$1" -t "$3" \
|
||||
-o "$4" "$2"
|
Loading…
Reference in New Issue
Block a user