diff --git a/.config/X11/runonce b/.config/X11/runonce index da1241b..d707607 100755 --- a/.config/X11/runonce +++ b/.config/X11/runonce @@ -1,3 +1,4 @@ +clipmenud & flameshot & # vim: ft=sh diff --git a/.config/clangd/config.yaml b/.config/clangd/config.yaml index 572ad75..b928d58 100644 --- a/.config/clangd/config.yaml +++ b/.config/clangd/config.yaml @@ -7,4 +7,4 @@ CompileFlags: If: PathMatch: '.*\.(cpp|hpp)' CompileFlags: - Add: [ -std=c++23 ] + Add: [ -std=c++20 ] diff --git a/.config/nvim/.gitignore b/.config/nvim/.gitignore deleted file mode 100644 index 9bbbeea..0000000 --- a/.config/nvim/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.luarc.json diff --git a/.config/nvim/.luarc.json b/.config/nvim/.luarc.json new file mode 100644 index 0000000..0059061 --- /dev/null +++ b/.config/nvim/.luarc.json @@ -0,0 +1,41 @@ +{ + "workspace.library": [ + "/home/wzray/.local/share/nvim/lazy/neodev.nvim/types/stable", + "/usr/share/nvim/runtime/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-surround/lua", + "/home/wzray/.local/share/nvim/lazy/telescope-fzf-native.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-tree.lua/lua", + "/home/wzray/.local/share/nvim/lazy/cmp-nvim-lsp/lua", + "/home/wzray/.local/share/nvim/lazy/cmp-buffer/lua", + "/home/wzray/.local/share/nvim/lazy/lspkind.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/lualine.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-web-devicons/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-treesitter-textobjects/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-treesitter-context/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-treesitter/lua", + "/home/wzray/.local/share/nvim/lazy/indent-blankline.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-notify/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-colorizer.lua/lua", + "/home/wzray/.local/share/nvim/lazy/mason.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/lazy.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/LuaSnip/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-lastplace/lua", + "/home/wzray/.local/share/nvim/lazy/telescope.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/Navigator.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/trouble.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/bufferline.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/Comment.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-lspconfig/lua", + "/home/wzray/.local/share/nvim/lazy/neodev.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/onedark.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/plenary.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/fidget.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-autopairs/lua", + "/home/wzray/.local/share/nvim/lazy/todo-comments.nvim/lua", + "/home/wzray/.local/share/nvim/lazy/nvim-cmp/lua", + "/home/wzray/.local/share/nvim/lazy/telescope-emoji.nvim/lua", + "/usr/share/nvim/runtime", + "/home/wzray/.dotfiles/.config/nvim/lua", + "${3rd}/luv/library" + ] +} \ No newline at end of file diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index d80f1e0..c20ee07 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -1,55 +1,43 @@ { "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" }, - "LuaSnip": { "branch": "master", "commit": "3732756842a2f7e0e76a7b0487e9692072857277" }, + "LuaSnip": { "branch": "master", "commit": "c1851d5c519611dfc451b6582961b2602e0af89b" }, "Navigator.nvim": { "branch": "master", "commit": "91d86506ac2a039504d5205d32a1d4bc7aa57072" }, "bufferline.nvim": { "branch": "main", "commit": "655133c3b4c3e5e05ec549b9f8cc2894ac6f51b3" }, "cmp-buffer": { "branch": "main", "commit": "b74fab3656eea9de20a9b8116afa3cfc4ec09657" }, - "cmp-nvim-lsp": { "branch": "main", "commit": "bd5a7d6db125d4654b50eeae9f5217f24bb22fd3" }, - "fidget.nvim": { "branch": "main", "commit": "e32b672d8fd343f9d6a76944fedb8c61d7d8111a" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "a8912b88ce488f411177fc8aed358b04dc246d7b" }, + "fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" }, "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, "iptables": { "branch": "master", "commit": "0d18b1e468f547dd7e2c494d42bc134a1e0eac7e" }, - "lazy.nvim": { "branch": "main", "commit": "85c7ff3711b730b4030d03144f6db6375044ae82" }, - "lspkind.nvim": { "branch": "master", "commit": "3ddd1b4edefa425fda5a9f95a4f25578727c0bb3" }, - "lua-async-await": { "branch": "main", "commit": "652d94df34e97abe2d4a689edbc4270e7ead1a98" }, - "lualine.nvim": { "branch": "master", "commit": "3946f0122255bc377d14a59b27b609fb3ab25768" }, - "mason.nvim": { "branch": "main", "commit": "ad7146aa61dcaeb54fa900144d768f040090bff0" }, - "multilayout.nvim": { "branch": "main", "commit": "105f22f6329f19a1824f58774d1899f2a69a5e77" }, + "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, + "lspkind.nvim": { "branch": "master", "commit": "d79a1c3299ad0ef94e255d045bed9fa26025dab6" }, + "lualine.nvim": { "branch": "master", "commit": "15884cee63a8c205334ab13ab1c891cd4d27101a" }, + "mason.nvim": { "branch": "main", "commit": "7c7318e8bae7e3536ef6b9e86b9e38e74f2e125e" }, + "multilayout.nvim": { "branch": "main", "commit": "613ec4ace9097a4464a558777aaf6a15b3d8bd78" }, "neodev.nvim": { "branch": "main", "commit": "46aa467dca16cf3dfe27098042402066d2ae242d" }, - "nui.nvim": { "branch": "main", "commit": "de740991c12411b663994b2860f1a4fd0937c130" }, - "nvim-autopairs": { "branch": "master", "commit": "7a2c97cccd60abc559344042fefb1d5a85b3e33b" }, - "nvim-cmp": { "branch": "main", "commit": "106c4bcc053a5da783bf4a9d907b6f22485c2ea0" }, + "nvim-autopairs": { "branch": "master", "commit": "4d74e75913832866aa7de35e4202463ddf6efd1b" }, + "nvim-cmp": { "branch": "main", "commit": "b5311ab3ed9c846b585c0c15b7559be131ec4be9" }, "nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" }, - "nvim-dap": { "branch": "master", "commit": "4c0e3a98465fac963dfde898cc8b878094153a43" }, - "nvim-java": { "branch": "main", "commit": "3d56b7461facb42f135e25b2636bf220a7f0ed42" }, - "nvim-java-core": { "branch": "main", "commit": "229ebcdfa33c75cf746f97c46c2893b2de3626e5" }, - "nvim-java-dap": { "branch": "main", "commit": "55f239532f7a3789d21ea68d1e795abc77484974" }, - "nvim-java-refactor": { "branch": "main", "commit": "b51a57d862338999059e1d1717df3bc80a3a15c0" }, - "nvim-java-test": { "branch": "main", "commit": "7f0f40e9c5b7eab5096d8bec6ac04251c6e81468" }, "nvim-lastplace": { "branch": "main", "commit": "0bb6103c506315044872e0f84b1f736c4172bb20" }, - "nvim-lspconfig": { "branch": "master", "commit": "2010fc6ec03e2da552b4886fceb2f7bc0fc2e9c0" }, - "nvim-notify": { "branch": "master", "commit": "8701bece920b38ea289b457f902e2ad184131a5d" }, - "nvim-surround": { "branch": "main", "commit": "fcfa7e02323d57bfacc3a141f8a74498e1522064" }, - "nvim-tree.lua": { "branch": "master", "commit": "68c67adfabfd1ce923839570507ef2e81ab8a408" }, - "nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, - "nvim-treesitter-context": { "branch": "master", "commit": "660861b1849256398f70450afdf93908d28dc945" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "5ca4aaa6efdcc59be46b95a3e876300cfead05ef" }, - "nvim-ufo": { "branch": "main", "commit": "72d54c31079d38d8dfc5456131b1d0fb5c0264b0" }, - "nvim-web-devicons": { "branch": "master", "commit": "8dcb311b0c92d460fac00eac706abd43d94d68af" }, - "onedark.nvim": { "branch": "master", "commit": "918e89e6993b2901eea47b9f4eb666d53c2542a6" }, - "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, - "promise-async": { "branch": "main", "commit": "119e8961014c9bfaf1487bf3c2a393d254f337e2" }, + "nvim-lspconfig": { "branch": "master", "commit": "61e5109c8cf24807e4ae29813a3a82b31821dd45" }, + "nvim-notify": { "branch": "master", "commit": "b5825cf9ee881dd8e43309c93374ed5b87b7a896" }, + "nvim-surround": { "branch": "main", "commit": "0e62500b98f4513feaaf7425c135472457ea5b7d" }, + "nvim-tree.lua": { "branch": "master", "commit": "e7d1b7dadc62fe2eccc17d814354b0a5688621ce" }, + "nvim-treesitter": { "branch": "master", "commit": "28d480e0624b259095e56f353ec911f9f2a0f404" }, + "nvim-treesitter-context": { "branch": "master", "commit": "5c48b8ba1b0b7b25feb6e34e7eb293ea893aedc4" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "0e3be38005e9673d044e994b1e4b123adb040179" }, + "nvim-web-devicons": { "branch": "master", "commit": "f1420728f59843eb2ef084406b3d0201a0a0932d" }, + "onedark.nvim": { "branch": "master", "commit": "11de4da47f3e69cb70c3ae9816bd8af166cbe121" }, + "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, "quickfix-reflector.vim": { "branch": "master", "commit": "6a6a9e28e1713b9e9db99eec1e6672e5666c01b9" }, - "spring-boot.nvim": { "branch": "main", "commit": "218c0c26c14d99feca778e4d13f5ec3e8b1b60f0" }, "telescope-emoji.nvim": { "branch": "master", "commit": "86248d97be84a1ce83f0541500ef9edc99ea2aa1" }, - "telescope-fzf-native.nvim": { "branch": "main", "commit": "6fea601bd2b694c6f2ae08a6c6fab14930c60e2c" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, - "todo-comments.nvim": { "branch": "main", "commit": "31e3c38ce9b29781e4422fc0322eb0a21f4e8668" }, - "trouble.nvim": { "branch": "main", "commit": "bd67efe408d4816e25e8491cc5ad4088e708a69a" }, + "todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" }, + "trouble.nvim": { "branch": "main", "commit": "85bedb7eb7fa331a2ccbecb9202d8abba64d37b3" }, "vim-bbcode": { "branch": "master", "commit": "6fb28c6deae5844ee2bf0b97ef2fea04bd3d4eac" }, - "vim-caddyfile": { "branch": "master", "commit": "6d60d5af0d73f20b88ec388a9d70188d55ed8223" }, - "vim-fugitive": { "branch": "master", "commit": "61b51c09b7c9ce04e821f6cf76ea4f6f903e3cf4" }, + "vim-caddyfile": { "branch": "master", "commit": "24fe0720551883e407cb70ae1d7c03f162d1d5a0" }, + "vim-fugitive": { "branch": "master", "commit": "4a745ea72fa93bb15dd077109afbb3d1809383f2" }, "vim-nftables": { "branch": "master", "commit": "26f8a506c6f3e41f1e4a8d6aa94c9a79a666bbff" }, - "vim-peekaboo": { "branch": "master", "commit": "2a8a3187ba6b15201b2563a3f0331fcdf49da36c" }, - "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" }, - "vim-wakatime": { "branch": "master", "commit": "d7973b157a632d1edeff01818f18d67e584eeaff" } + "vim-peekaboo": { "branch": "master", "commit": "cc4469c204099c73dd7534531fa8ba271f704831" }, + "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" } } diff --git a/.config/nvim/lua/config/filetypes.lua b/.config/nvim/lua/config/filetypes.lua deleted file mode 100644 index 87bddaa..0000000 --- a/.config/nvim/lua/config/filetypes.lua +++ /dev/null @@ -1,36 +0,0 @@ -local function has_ansible_root(path, recursive) - if not recursive then - return vim.uv.fs_stat( - vim.fs.joinpath(vim.fs.dirname(path), 'ansible.cfg') - ) - end - - return vim.fs.find('ansible.cfg', { - path = vim.fs.dirname(path), - upward = true, - limit = 1 - })[1] -end - -local function yaml_filetype(recursive, p2) - return function (path) - print(p2) - if has_ansible_root(path, recursive) then - return "yaml.ansible" - else - return "yaml" - end - end -end - -vim.filetype.add({ - extension = { - ['yaml'] = yaml_filetype(false), - ['yml'] = yaml_filetype(false), - }, - pattern = { - [".*/roles/.*/tasks/.*%.ya?ml"] = yaml_filetype(true), - [".*/roles/.*/handlers/.*%.ya?ml"] = yaml_filetype(true), - [".*/playbooks/.*%.ya?ml"] = yaml_filetype(true), - }, -}) diff --git a/.config/nvim/lua/config/init.lua b/.config/nvim/lua/config/init.lua index 5468c1c..b8af3fe 100644 --- a/.config/nvim/lua/config/init.lua +++ b/.config/nvim/lua/config/init.lua @@ -1,4 +1,3 @@ -require("config.options") require("config.mappings") +require("config.options") require("config.autocmd") -require("config.filetypes") diff --git a/.config/nvim/lua/config/mappings.lua b/.config/nvim/lua/config/mappings.lua index 55d4263..5fc4a31 100644 --- a/.config/nvim/lua/config/mappings.lua +++ b/.config/nvim/lua/config/mappings.lua @@ -23,7 +23,7 @@ map({ 'n', 'v' }, 'j', 'v:count == 0 ? "gj" : "j"', { expr = true, silent = true -- Copy and paste from clipboard map({ 'n', 'v' }, 'y', '"+y') -map({ 'n', 'v' }, 'Y', '"+y$') +map({ 'n', 'v' }, 'Y', '"+Y') map({ 'n', 'v' }, 'p', '"+p') map({ 'n', 'v' }, 'P', '"+P') @@ -49,8 +49,3 @@ map('i', '', '') -- Move lines quickly map('n', '', ':m-2', { silent = true }) map('n', '', ':m+1', { silent = true }) - -map('n', 'dt', ':diffthis', { silent = true }) -map('n', 'do', ':diffoff', { silent = true }) - -map('n', 'lr', ':LspR') diff --git a/.config/nvim/lua/lsp/init.lua b/.config/nvim/lua/lsp/init.lua index 6249249..14b0793 100644 --- a/.config/nvim/lua/lsp/init.lua +++ b/.config/nvim/lua/lsp/init.lua @@ -19,7 +19,7 @@ local servers = { yamlls = require('lsp.yamlls'), } --- vim.lsp.set_log_level('info') +vim.lsp.set_log_level('info') local on_attach = function(_, bufnr) local nmap = function(keys, func) @@ -33,10 +33,6 @@ local on_attach = function(_, bufnr) nmap('gr', require('telescope.builtin').lsp_references) nmap('gt', require('telescope.builtin').lsp_type_definitions) - -- nmap('gd', vim.lsp.buf.definition) - -- nmap('gr', vim.lsp.buf.references) - -- nmap('gt', vim.lsp.buf.type_definition) - nmap('sd', require('telescope.builtin').diagnostics) nmap('ds', require('telescope.builtin').lsp_document_symbols) nmap('as', require('telescope.builtin').lsp_dynamic_workspace_symbols) @@ -46,22 +42,17 @@ local on_attach = function(_, bufnr) nmap('', vim.lsp.buf.signature_help) nmap('gI', require('telescope.builtin').lsp_implementations) - -- nmap('gI', vim.lsp.buf.implementation) nmap('gD', vim.lsp.buf.declaration) nmap('F', vim.lsp.buf.format) end local capabilities = require('cmp_nvim_lsp').default_capabilities() -capabilities.textDocument.foldingRange = { - dynamicRegistration = false, - lineFoldingOnly = true -} +local lspconfig = require('lspconfig') for server_name, config in pairs(servers) do - vim.lsp.config(server_name, vim.tbl_deep_extend('keep', { + lspconfig[server_name].setup(vim.tbl_deep_extend('keep', { capabilities = capabilities, on_attach = on_attach, }, config)) - vim.lsp.enable(server_name) end diff --git a/.config/nvim/lua/plugins/init.lua b/.config/nvim/lua/plugins/init.lua index 39dd18a..7e406c7 100644 --- a/.config/nvim/lua/plugins/init.lua +++ b/.config/nvim/lua/plugins/init.lua @@ -1,11 +1,10 @@ return { - 'Winseven4lyf/vim-bbcode', 'isobit/vim-caddyfile', - 'junegunn/vim-peekaboo', - 'nfnty/vim-nftables', 'rcarriga/nvim-notify', 'stefandtw/quickfix-reflector.vim', + 'nfnty/vim-nftables', 'tpope/vim-fugitive', + 'junegunn/vim-peekaboo', 'tpope/vim-sleuth', 'vim-scripts/iptables', { 'akinsho/bufferline.nvim', opts = {}, dependencies = { 'navarasu/onedark.nvim' } }, @@ -14,7 +13,36 @@ return { { 'kylechui/nvim-surround', version = '*', event = 'VeryLazy', opts = {} }, { 'lukas-reineke/indent-blankline.nvim', main = 'ibl', opts = {} }, { 'norcalli/nvim-colorizer.lua', opts={ '*' }, dependencies = { 'navarasu/onedark.nvim' } }, - { 'wakatime/vim-wakatime', event = 'VeryLazy' }, + -- { 'wakatime/vim-wakatime', event = 'VeryLazy' }, { 'williamboman/mason.nvim', opts = {} }, - { dir = '~/.local/share/nvim/preseed/' }, -- 'https://git.netizen.se/vim-preseed', + 'Winseven4lyf/vim-bbcode', + + + { 'mrsobakin/multilayout.nvim' , opts = { + layouts = { + ru = { + -- Names of this layout, as `libukb` reports. + names = { "Russian" }, + from = [[ёйцукенгшщзхъфывапролджэячсмитьбю.Ё"№;:?ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,]], + to = [[`qwertyuiop[]asdfghjkl;'zxcvbnm,./~@#$^&QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?]], + } + }, + aliases = { + -- Maximum length of default commands aliases. + -- Increasing this value leads to longer startup times. + max_length = 2, + -- Extra commands that you want to alias. + -- They are aliased regardless of `max_length`. + extra = { "sort" }, + }, + -- Whether to use `libukb`. If this is set to false, `langmap` + -- won't automatically switch when your layout does. + use_libukb = true, + -- Path to the `libukb.so`. If `nil`, ukb will be automatically + -- downloaded, builded and installed in the neovim data directory. + libukb_path = nil, + -- Function of type `callback(layout: string)`. Called whenever + -- current keyboard layout changes. + callback = nil, + }} } diff --git a/.config/nvim/lua/plugins/multilayout.lua b/.config/nvim/lua/plugins/multilayout.lua deleted file mode 100644 index 6220119..0000000 --- a/.config/nvim/lua/plugins/multilayout.lua +++ /dev/null @@ -1,30 +0,0 @@ -return { - 'mrsobakin/multilayout.nvim', - opts = { - layouts = { - ru = { - -- Names of this layout, as `libukb` reports. - names = { "Russian" }, - from = [[ёйцукенгшщзхъфывапролджэячсмитьбю.Ё"№;:?ЙЦУКЕНГШЩЗХЪ/ФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,]], - to = [[`qwertyuiop[]asdfghjkl;'zxcvbnm,./~@#$^&QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?]], - } - }, - aliases = { - -- Maximum length of default commands aliases. - -- Increasing this value leads to longer startup times. - max_length = 2, - -- Extra commands that you want to alias. - -- They are aliased regardless of `max_length`. - extra = { "sort" }, - }, - -- Whether to use `libukb`. If this is set to false, `langmap` - -- won't automatically switch when your layout does. - use_libukb = true, - -- Path to the `libukb.so`. If `nil`, ukb will be automatically - -- downloaded, builded and installed in the neovim data directory. - libukb_path = nil, - -- Function of type `callback(layout: string)`. Called whenever - -- current keyboard layout changes. - callback = nil, - } -} diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua index d1acea9..724ece8 100644 --- a/.config/nvim/lua/plugins/telescope.lua +++ b/.config/nvim/lua/plugins/telescope.lua @@ -10,7 +10,6 @@ return { config = function() local actions = require('telescope.actions') - require('telescope').setup { defaults = { mappings = { @@ -19,12 +18,8 @@ return { [''] = false, [""] = actions.move_selection_next, [""] = actions.move_selection_previous, - -- [""] = actions.smart_send_to_qflist + actions.open_qflist, - [""] = require("trouble.sources.telescope").open + [""] = actions.smart_send_to_qflist + actions.open_qflist, }, - n = { - [""] = require("trouble.sources.telescope").open - } }, }, } @@ -39,17 +34,11 @@ return { }) end) - vim.keymap.set('n', '?', require('telescope.builtin').live_grep) - vim.keymap.set('n', 'wf', require('telescope.builtin').grep_string) + vim.keymap.set('n', '?', require('telescope.builtin').live_grep) + vim.keymap.set('n', 'wf', require('telescope.builtin').grep_string) vim.keymap.set('n', 'of', require('telescope.builtin').oldfiles) vim.keymap.set('n', 'af', require('telescope.builtin').git_files) vim.keymap.set('n', 'sf', require('telescope.builtin').find_files) vim.keymap.set('n', '.', require('telescope').extensions.emoji.emoji) - - - -- Use this to add more results without clearing the trouble list - -- local add_to_trouble = require("trouble.sources.telescope").add - - local telescope = require("telescope") end } diff --git a/.config/nvim/lua/plugins/theme.lua b/.config/nvim/lua/plugins/theme.lua index e8b19e9..a6c2dee 100644 --- a/.config/nvim/lua/plugins/theme.lua +++ b/.config/nvim/lua/plugins/theme.lua @@ -38,6 +38,5 @@ return { } vim.o.termguicolors = true vim.cmd.colorscheme 'onedark' - vim.cmd.hi 'clear @spell' end, } diff --git a/.config/nvim/lua/plugins/ufo.lua b/.config/nvim/lua/plugins/ufo.lua index dc4dcef..8ab9530 100644 --- a/.config/nvim/lua/plugins/ufo.lua +++ b/.config/nvim/lua/plugins/ufo.lua @@ -1,23 +1,30 @@ return { - 'kevinhwang91/nvim-ufo', - dependencies = { - 'kevinhwang91/promise-async' - }, - config = function() - vim.defer_fn(function() - vim.o.foldcolumn = '0' - vim.o.foldlevel = 99 - vim.o.foldlevelstart = 99 - vim.o.foldenable = true - - vim.keymap.set('n', 'zR', require('ufo').openAllFolds) - vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) - - require('ufo').setup({ - provider_selector = function(bufnr, filetype, buftype) - return {'treesitter', 'indent'} - end - }) - end, 0) - end + -- 'kevinhwang91/nvim-ufo', + -- dependencies = { + -- 'kevinhwang91/promise-async' + -- }, + -- config = function() + -- vim.defer_fn(function() + -- vim.o.foldcolumn = '0' + -- vim.o.foldlevel = 99 + -- vim.o.foldlevelstart = 99 + -- vim.o.foldenable = true + -- + -- vim.keymap.set('n', 'zR', require('ufo').openAllFolds) + -- vim.keymap.set('n', 'zM', require('ufo').closeAllFolds) + -- + -- local capabilities = vim.lsp.protocol.make_client_capabilities() + -- capabilities.textDocument.foldingRange = { + -- dynamicRegistration = false, + -- lineFoldingOnly = true + -- } + -- local language_servers = vim.lsp.get_clients() + -- for _, ls in ipairs(language_servers) do + -- require('lspconfig')[ls].setup({ + -- capabilities = capabilities + -- }) + -- end + -- require('ufo').setup() + -- end, 0) + -- end } diff --git a/.config/tmux/keybinds.conf b/.config/tmux/keybinds.conf index 3cc1439..3c15dcc 100644 --- a/.config/tmux/keybinds.conf +++ b/.config/tmux/keybinds.conf @@ -32,8 +32,6 @@ unbind-key -T copy-mode-vi V unbind-key -T copy-mode-vi C-v unbind-key -T copy-mode-vi C-c unbind-key -T copy-mode-vi Escape -# unbind-key -T copy-mode-vi / -# unbind-key -T copy-mode-vi ? bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel bind-key -T copy-mode-vi v send-keys -X begin-selection @@ -42,7 +40,4 @@ bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle bind-key -T copy-mode-vi C-c send-keys -X cancel bind-key -T copy-mode-vi Escape send-keys -X clear-selection -bind-key -T copy-mode-vi ? command-prompt -T search -p "(search down)" { send-keys -X search-forward "%%" } -bind-key -T copy-mode-vi / command-prompt -T search -p "(search up)" { send-keys -X search-backward "%%" } - # vim: ft=tmux diff --git a/.config/zsh/.zshenv b/.config/zsh/.zshenv index 6b03206..505dfba 100644 --- a/.config/zsh/.zshenv +++ b/.config/zsh/.zshenv @@ -1,13 +1,8 @@ set -a -PATH="\ -$HOME/.local/share/go/bin:\ -$HOME/.local/share/dotnet:\ -$PATH" +PATH="$HOME/.local/share/go/bin:$PATH" PATH="${$(find -L ~/.local/bin ! -name '.*' -type d -printf %p:)%%:}:$PATH" -TIMEFMT=$'\ncmd\t%J\nreal\t%*E\nuser\t%U\nsys\t%S\ncpu\t%P' - # lc vars LANG="en_US.UTF-8" LANGUAGE="en_US.UTF-8" @@ -40,15 +35,14 @@ XDG_PICTURES_DIR="$HOME/" XDG_VIDEOS_DIR="$HOME/" # default configs -ANDROID_HOME="${HOME}/.local/share/android-home" +ANDROID_HOME="${HOME}/.local/share/android" ANDROID_USER_HOME="${HOME}/.local/share/android-home" -ANDROID_AVD_HOME="${ANDROID_HOME}/avd" BAT_THEME="TwoDark" EDITOR="/usr/bin/nvim" GNUPGHOME='~/.local/share/gnupg' GOPATH="${HOME}/.local/share/go" GPG_TTY="$(tty)" -JAVA_HOME="/usr/lib/jvm/java-21-openjdk" +JAVA_HOME="/usr/lib/jvm/java-23-openjdk" LESS="-x4 --wheel-lines 3 --mouse" MANPAGER="sh -c 'col -bx | bat -l man -p --theme Monokai\ Extended'" MANROFFOPT="-c" @@ -59,7 +53,5 @@ GRADLE_USER_HOME="${HOME}/.local/share/gradle" DOCKER_CONFIG="${HOME}/.local/share/docker" COMPOSE_BAKE=true GIT_DISCOVERY_ACROSS_FILESYSTEM=1 -DOTNET_CLI_TELEMETRY_OPTOUT=1 # clippy <3 -DOTNET_ROOT="${HOME}/.local/share/dotnet" set +a diff --git a/.config/zsh/.zshrc b/.config/zsh/.zshrc index 77228fc..7adba07 100644 --- a/.config/zsh/.zshrc +++ b/.config/zsh/.zshrc @@ -23,6 +23,7 @@ autoload -U select-word-style select-word-style b # options +setopt extendedglob setopt auto_pushd # keybinds @@ -57,10 +58,7 @@ alias lsd='/usr/bin/ls' alias l="ls -lh" alias la="ls -lah" alias ll="ls -lh" -alias ltr='ls -lt' alias lt="ls -ltr" -alias lss='ls -lS' -alias lsr='ls -lSr' # set bat as help pager alias -g -- --help='--help 2>&1 | bat --language=help --style=plain --theme Monokai\ Extended' @@ -86,12 +84,12 @@ alias sudo='sudo ' # allow aliases with sudo alias rz='exec zsh' alias venv='source src_venv' alias ex='source src_example' -alias pa='source src_add_path' +alias ap='source src_add_path' alias info='pinfo' alias bat='bat ' alias img='nsxiv' alias xclip='xclip -selection clipboard' -alias xcp='perl -pe "chomp if eof" | xclip -selection clipboard' +alias xxclip='head -c-1 | xclip -selection clipboard' alias rgf='rg --files | rg' alias wt='watch --color -d -cn 0.1 ' alias .e='set -a && source .env && set +a' @@ -99,37 +97,30 @@ alias vimu='vim -u /dev/null' alias reswap="sudo bash -c 'echo Working...; swapoff /swapfile && sudo swapon /swapfile'" alias make="make -j$(nproc)" alias py='python3' -alias q='qalc' alias neofetch='fastfetch' alias open='xdg-open' alias m.='if mount | grep -q "$(pwd)"; then umount -l .; cd .; else mount .; cd .; fi' alias rs='stow -R .' alias sst='ssh -t' -alias rdj='rmdir ./*' -alias qr='qrencode -t ansiutf8' # function aliases bl() { brightnessctl set "$1"% > /dev/null; } nosw() { alacritty --class 'noswallow' -e "$@"; }; compdef _command nosw +t() { taskell "${1:-${HOME}/.taskell.md}"; } vims() { filepath="$(type "$1" | rev | cut -d ' ' -f 1 | rev)"; [ $? -eq 0 ] && vim "${filepath}"; }; compdef _command vims tl() { tree -C "$@" | bat }; compdef _tree tl -diff() { /usr/bin/diff --color -u "$@" | delta; }; compdef _files di; +diff() { /usr/bin/diff --color -u "$@" | delta; }; compdef _files di # compdef compdef -a '_git; _git-commit' gdc # todo compdef '_files -g "*.md"' md - -# ansible -alias ap='ansible-playbook' -alias ag='ansible-galaxy' +compdef _ollama ollama # git aliases gl() { git log --decorate "$@" | bat }; compdef '_git; _git-log' gl -gus() { git branch --set-upstream-to="${1:?}/${2:?}" "${2:?}" }; compdef '_git; _git-push' gus -gpo() { git push --set-upstream origin "$(git rev-parse --abbrev-ref HEAD)" "$@" } -gru() { git remote get-url "${1-origin}" }; compdef '_gor' gru +gus() { git branch --set-upstream-to="${1:?}/${2:?}" "${2:?}"}; compdef '_git; _git-push' gus +gpo() { git push --set-upstream origin "$(git rev-parse --abbrev-ref HEAD)" "$@"} alias ga="git add" -alias ga.="git add ." # always fatfinger this alias gb="git branch" alias gc="git commit" alias gca="git commit --allow-empty-message --amend --no-edit" @@ -140,8 +131,7 @@ alias gcls="git clone --depth=1" alias gcm="git commit --allow-empty-message -m ''" alias gcd='git commit --no-gpg-sign' alias gcmd="git commit --allow-empty-message -m '' --no-gpg-sign" -alias gcn="git clean -nfd" -alias gcn!="git clean -fd" +alias gcn="git clean" alias gcp="git cherry-pick" alias gd="git diff" alias gds="gd --staged" @@ -158,12 +148,10 @@ alias grjs="git rebase --cancel" alias grm="git remote" alias grs="git restore --staged" alias grt="git reset" -alias grt!="git reset --hard" alias gsm='git submodule' alias grc='git rm --cached' alias gs="git status" -alias gs.='git status .' -alias gsc="git switch -C" +alias gsc="git switch -c" alias gsh="git show" alias gsj="git stash" alias gsp="git stash pop" @@ -171,10 +159,6 @@ alias gt="git tag" alias gus="git fetch --unshallow" alias gdj='DELTA_FEATURES="+side-by-side" gd' alias gdsj='DELTA_FEATURES="+side-by-side" gds' -alias gshj='DELTA_FEATURES="+side-by-side" gsh' -alias gcln='git clean -nxfd' -alias gcln!='git clean -xfd' -alias gct="gc -am 'Add files via upload :trollface:'" # docker aliases alias d='docker' @@ -182,22 +166,17 @@ alias dc='docker compose' alias d!='/usr/bin/docker' alias dc!='d! compose' -alias di='d image' alias dj='dc up -d --force-recreate' -alias djb='dj --build' -alias djbl='djb && dl' -alias djl='dj && dl' -alias dk='dc down' +alias djl='dc up -d --force-recreate && dl' alias dl='dc logs -f' -alias dr='d run --rm -it' -alias drs='dc restart' -alias drsl='dc restart && dl' +alias dk='dc down' alias dv='d volume' +alias di='d image' +alias dr='d run --rm -it' # tmux stuff tn() { tmux new-session -s "${1-"$(basename "$(pwd)")"}" } -alias ta='tmux a -t' -# ta() { tmux a -t "$1" }; compdef '_tmux; _tmux-attach-session' ta +alias ta="tmux a -t" # disable xon control chars stty -ixon diff --git a/.config/zsh/modes.sh b/.config/zsh/modes.sh index 793f812..e5c8188 100644 --- a/.config/zsh/modes.sh +++ b/.config/zsh/modes.sh @@ -1,5 +1,3 @@ -#!/usr/bin/zsh - mode::enable() { local mode_path="${HOME}/.config/zsh/modes/$1.sh" [ ! -f "$mode_path" ] && echo "Mode not found!" && return 1 @@ -13,18 +11,6 @@ mode::enable() { } -mode::get_functions() { - perl -ne '/^(?>function\s+)?([\x21-\x7e]+)\s*\(\)/ && print "$1\n"' < "$1" -} - -mode::get_variables() { - perl -ne '/^(?>declare\s+(?>--?\w+\s*)+\s*)?\s*([\x21-\x3c\x3e-\x7e]+)=.*$/ && print "$1\n"' < "$1" -} - -mode::get_aliases() { - perl -ne '/^(?:noglob\s+)?alias ([\x21-\x3c\x3e-\x7e]+)=/ && print "$1\n"' < "$1" -} - mode::disable() { export PS1="${MODE__OLD_PS1}" local mode_path="${HOME}/.config/zsh/modes/$MODE__ACTIVE_MODE.sh" @@ -32,78 +18,45 @@ mode::disable() { unset -v "MODE__OLD_PS1" unset -v "MODE__ACTIVE_MODE" - for mode_variable in $(mode::get_variables "$mode_path"); do + for mode_variable in $(perl -ne '/^(?>declare\s+(?>--?\w+\s*)+\s*)?\s*([\x21-\x3c\x3e-\x7e]+)=.*$/ && print "$1\n"' < "$mode_path"); do unset "$mode_variable" done - for mode_function in $(mode::get_functions "$mode_path"); do + for mode_function in $(perl -ne '/^(?>function\s+)?([\x21-\x7e]+)\s*\(\)/ && print "$1\n"' < "$mode_path"); do unset -f "$mode_function" done - for mode_alias in $(mode::get_aliases "$mode_path"); do + for mode_alias in $(perl -ne '/^alias ([\x21-\x3c\x3e-\x7e]+)=/ && print "$1\n"'< "$mode_path"); do unalias "$mode_alias" done } mode::help() { - echo "Usage:" + echo "USAGE" + echo " mode [-h]" echo " mode " + echo " mode" echo - echo "Available modes:" + echo "OPTIONS" + echo " -h for help lol" + echo + echo "AVAILABLE MODES" for mode in ~/.config/zsh/modes/*; do printf " %s\n" "$(basename "${mode%.sh}")" done } - m() { - [ -n "$MODE__ACTIVE_MODE" ] && { - mode::disable - [ -z "$1" ] && return - } + [ -n "$MODE__ACTIVE_MODE" ] && mode::disable && return + local cmd="${1:?}" - [ -z "$1" ] && { - echo 'Error: Missing mode name!' - mode::help - return 1 - } >&2 - - case "$1" in + case "$cmd" in "-h"|"--help") mode::help ;; *) - mode::enable "$1" || mode::help >&2 + mode::enable "$cmd" || mode::help >&2 ;; esac } - -mm() { - [ -z "$MODE__ACTIVE_MODE" ] && return 1 - - local mode_path="${HOME}/.config/zsh/modes/$MODE__ACTIVE_MODE.sh" - - echo "Active mode: $MODE__ACTIVE_MODE" - - echo - echo 'Aliases: ' - for mode_alias in $(mode::get_aliases "$mode_path"); do - printf ' ' - alias "$mode_alias" - done - - echo - echo 'Functions:' - for mode_function in $(mode::get_functions "$mode_path"); do - echo " $mode_function" - done - - echo - echo 'Variables:' - for mode_variable in $(mode::get_variables "$mode_path"); do - echo " $mode_variable" - done -} - -alias 'm?'=mm diff --git a/.config/zsh/modes/dt.sh b/.config/zsh/modes/dt.sh deleted file mode 100644 index dcd8b1f..0000000 --- a/.config/zsh/modes/dt.sh +++ /dev/null @@ -1,7 +0,0 @@ -alias db='dotnet build' -alias df='dotnet format' -alias dt='dotnet test' -alias dr='dotnet restore' -noglob alias df?='dotnet format --verify-no-changes' -alias dff='df; df; df?' -alias da='dff && db && dt' diff --git a/.gitconfig b/.gitconfig index 48892c7..d3389de 100644 --- a/.gitconfig +++ b/.gitconfig @@ -21,8 +21,3 @@ [safe] directory = /home/wzray/Services/cpu directory = /home/wzray/Services/cpu/* -[filter "lfs"] - clean = git-lfs clean -- %f - smudge = git-lfs smudge -- %f - process = git-lfs filter-process - required = true diff --git a/.local/bin/scripts/bin b/.local/bin/scripts/bin index 8fd0639..7ed7eac 100755 --- a/.local/bin/scripts/bin +++ b/.local/bin/scripts/bin @@ -6,19 +6,17 @@ declare -a files while [ "$#" -gt 0 ]; do case "$1" in - "-"*) SILENT=1;; + "-s") SILENT=1;; *) files+=("$1");; esac shift done -if [ "${#files}" -gt 0 ]; then - for file in "${files[@]}"; do - r="$(curl -X PUT --data-binary "@$file" "$URL" 2>/dev/null)" - ext="$(basename -- "$file")" - ext=".${ext##*.}" - [ "$ext" = ".$file" ] && ext= - done +if [ "$#" -gt 0 ]; then + r="$(curl -X PUT --data-binary "@$1" "$URL" 2>/dev/null)" + ext="$(basename -- "$1")" + ext=".${ext##*.}" + [ "$ext" = ".$1" ] && ext= else if [ "$SILENT" = 1 ]; then TMP_FILENAME="$(mktemp)" @@ -28,8 +26,9 @@ else else r="$(curl -X PUT --data-binary @- "$URL" 2>/dev/null)" fi - [ -n "$TMP_FILENAME" ] && rm "$TMP_FILENAME" fi -r="$(tr -d $'\n' <<< "$r$ext")" -xclip -selection clipboard <<< "$r" -echo "$r" + +r="$(tr -d $'\n' <<< "$r")" +xclip -selection clipboard <<< "$r$ext" +echo "$r$ext" +[ -n "$TMP_FILENAME" ] && rm "$TMP_FILENAME" diff --git a/.local/bin/scripts/cat-files b/.local/bin/scripts/cat-files deleted file mode 100755 index b73723d..0000000 --- a/.local/bin/scripts/cat-files +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -while IFS=$'\n' read -r file; do - echo "$file:" - cat "$file" - printf "\n\n" -done < <(find "${1?}" -type f) diff --git a/.local/bin/scripts/dunstctl-set-paused b/.local/bin/scripts/dunstctl-set-paused deleted file mode 100755 index f7288f3..0000000 --- a/.local/bin/scripts/dunstctl-set-paused +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -dunstctl set-paused "$1" -pkill -37 dwmblocks diff --git a/.local/bin/scripts/gor b/.local/bin/scripts/gor index be0eddd..2359cc3 100755 --- a/.local/bin/scripts/gor +++ b/.local/bin/scripts/gor @@ -3,11 +3,7 @@ url="$(git remote get-url "${1:-origin}")" if [[ "$url" =~ ^https?:\/\/ ]]; then - xdg-open "${url%.git}" -# elif [[ "$url" =~ ([a-zA-Z0-9_.-]+):(.*) ]]; then -# url="https://${BASH_REMATCH[1]}/${BASH_REMATCH[2]}" -# url="${url%.git}" -# xdg-open "$url" + xdg-open "$url" elif [[ "$url" =~ ^[a-zA-Z0-9_-]+@([a-zA-Z0-9_.-]+):(.*) ]]; then url="https://${BASH_REMATCH[1]}/${BASH_REMATCH[2]}" url="${url%.git}" diff --git a/.local/bin/scripts/md b/.local/bin/scripts/md index 9f22ac5..3659d03 100755 --- a/.local/bin/scripts/md +++ b/.local/bin/scripts/md @@ -34,8 +34,6 @@ main() { "--template=${HOME}/.local/share/default.html" "--variable=published_time=$(date -Iseconds -d"$(stat "$1" | grep 'Birth:' | sed 's/.*Birth:\s//')")" ) - - set -e pandoc "${pandoc_options[@]}" <(shift_header "$1") > "$FILENAME" && echo "$FILENAME" && firefox "$FILENAME" & disown diff --git a/.local/bin/scripts/my.itmo b/.local/bin/scripts/my.itmo new file mode 100755 index 0000000..bed5108 --- /dev/null +++ b/.local/bin/scripts/my.itmo @@ -0,0 +1,326 @@ +#!/bin/sh +# shellcheck disable=all +"exec" "${HOME}/.local/share/venv/statusbar/bin/python3" "-u" "$0" "$@" + +import datetime +import json +import os +import signal +import sys +import time +import traceback + +from collections.abc import Callable +from dataclasses import dataclass +from typing import Literal, Any, TypeVar +from urllib.parse import urlparse + +import requests +from bs4 import BeautifulSoup, Tag + +EMOJI_BY_STATUS = { + 0: '🟡', + 1: '🟢', + 2: '🔴', +} +TIMEOUT = 30 +CONFIG_FILE = f"{os.environ['HOME']}/.my.itmo" +CACHE_FILE = f"{os.environ['HOME']}/.cache/my_itmo.cache" +SECRET_FILE = f"{os.environ['HOME']}/.secrets/my_itmo.secret" +PIPE_FILE = f"{os.environ['XDG_RUNTIME_DIR']}/my.itmo.pipe" + +T = TypeVar('T') + + +def run_forever(fn: Callable, *args, **kwargs): + while True: + try: + fn(*args, **kwargs) + except Exception: + print(traceback.format_exc()) + + +def run_until_successful(fn: Callable[..., T], *args, **kwargs) -> T: + while True: + try: + return fn(*args, **kwargs) + except Exception: + pass + + +def send_message(chat_id: int, text: str, token: str): + requests.post(f"https://api.telegram.org/bot{token}/sendMessage", data={ + 'chat_id': chat_id, + 'parse_mode': 'HTML', + 'text': text + }) + + +@dataclass +class StatusObject: + id: int + name: str + notice: str + status: Literal[0, 1, 2] + status_name: str + updated_at: datetime.datetime + created_at: datetime.datetime + + @staticmethod + def from_dict(data: dict[str, Any]): + data['updated_at'] = datetime.datetime.strptime(data['updated_at'].replace("+03:00", ''), '%Y-%m-%dT%H:%M:%S') + data['created_at'] = datetime.datetime.strptime(data['created_at'].replace("+03:00", ''), '%Y-%m-%dT%H:%M:%S') + + return StatusObject(**data) + + +class ApiException(Exception): + status_code: int + body: str + + def __init__(self, status_code: int, body: str): + super().__init__(status_code, body) + self.status_code = status_code + self.body = body + + def __str__(self): + return f'Status code: {self.status_code}\nBody: {self.body}' + + +class Api: + _session: requests.Session + _username: str + _password: str + _access_token: str + _refresh_token: str + _expires_in: int + _refresh_expires_in: int + + def __init__(self, username: str, password: str, *, access_token: str | None = None, + refresh_token: str | None = None, expires_in: int | None = None, + refresh_expires_in: int | None = None, cookies: Any | None = None): + self._session = requests.Session() + self._username = username + self._password = password + self._refresh_token = refresh_token if refresh_token else '' + self._expires_in = expires_in if expires_in else 0 + self._refresh_expires_in = refresh_expires_in if refresh_expires_in else 0 + if cookies: self._session.cookies.update(cookies) + self._access_token = access_token if access_token else '' + if access_token: self._session.headers.update({'Authorization': f'Bearer {access_token}'}) + self._ensure_authorized() + + + def _first_auth(self): + self._session.headers.clear() + self._session.cookies.clear() + code_request = run_until_successful(self._session.get, 'https://id.itmo.ru/auth/realms/itmo/protocol/openid-connect/auth', params={ + 'protocol': 'oauth2', + 'response_type': 'code', + 'client_id': 'student-personal-cabinet', + 'redirect_uri': 'https://my.itmo.ru/login/callback', + 'scope': 'openid profile', + }, timeout=2) + soup = BeautifulSoup(code_request.text, features='html.parser') + form = soup.find('form') + if not isinstance(form, Tag): + raise ApiException(code_request.status_code, code_request.text) + + url = form.get_attribute_list('action')[0] + auth_request = run_until_successful(self._session.post, url, data={'username': self._username, 'password': self._password}) + if auth_request.status_code != 200: + raise ApiException(auth_request.status_code, auth_request.text) + + parsed_url_params = {a.split('=')[0]: a.split('=')[1] for a in urlparse(auth_request.url).query.split('&')} + + self._get_and_save_tokens({ + 'code' : parsed_url_params['code'], + 'client_id': 'student-personal-cabinet', + 'redirect_uri': 'https://my.itmo.ru/login/callback', + 'audience': '', + 'response_type': 'code', + 'grant_type': 'authorization_code', + 'code_verifier': '' + }) + + + def _renew(self): + self._session.headers.clear() + self._session.cookies.clear() + self._get_and_save_tokens({ + 'refresh_token': self._refresh_token, + 'scopes': 'openid profile', + 'client_id': 'student-personal-cabinet', + 'grant_type': 'refresh_token' + }) + + + def _get_and_save_tokens(self, data: Any): + tokens_request = run_until_successful(self._session.post, 'https://id.itmo.ru/auth/realms/itmo/protocol/openid-connect/token', data=data, timeout=2) + if tokens_request.status_code != 200: + raise ApiException(tokens_request.status_code, tokens_request.text) + tokens = tokens_request.json() + self._access_token = tokens['access_token'] + self._expires_in = int(time.time()) + tokens['expires_in'] - 10 + self._refresh_expires_in = int(time.time()) + tokens['refresh_expires_in'] - 10 + self._refresh_token = tokens['refresh_token'] + self._session.headers.update({"Authorization": f"Bearer {tokens_request.json()['access_token']}"}) + + + def _ensure_authorized(self): + current_time = int(time.time()) + + if self._access_token and self._expires_in > current_time: + return + elif self._refresh_token and self._refresh_expires_in > current_time: + self._renew() + else: + self._first_auth() + + + def _make_request(self, method: Literal["GET", "POST"], endpoint: str): + self._ensure_authorized() + r = run_until_successful(self._session.request, method, f'https://my.itmo.ru/api/{endpoint}', timeout=2) + + if r.status_code == 403: + self._first_auth() # do full reauth if 403 after self._ensure_authorized() + r = run_until_successful(self._session.request, method, f'https://my.itmo.ru/api/{endpoint}', timeout=2) + + if r.status_code != 200 or r.json()['error_code'] != 0: + raise ApiException(r.status_code, r.text) + + return r.json() + + + def get_status_list(self): + return [StatusObject.from_dict(obj) for obj in self._make_request('GET', 'requests/my')['result']] + + + def to_dict(self) -> Any: + return { + 'username': self._username, + 'password': self._password, + 'access_token': self._access_token, + 'refresh_token': self._refresh_token, + 'expires_in': self._expires_in, + 'refresh_expires_in': self._refresh_expires_in, + 'cookies': self._session.cookies.get_dict() + } + + + @staticmethod + def from_dict(data: Any): + return Api( + data['username'], + data['password'], + access_token = data['access_token'], + refresh_token = data['refresh_token'], + expires_in = data['expires_in'], + refresh_expires_in = data['refresh_expires_in'], + cookies = data['cookies'], + ) + + +def listen_for_messages(api: Api, timeout=TIMEOUT, filter_func: Callable[[StatusObject], bool] | None = None): + prev_msg = None + while True: + msg = list(filter(filter_func, api.get_status_list())) + + if not msg or msg == prev_msg: + time.sleep(timeout) + continue + + prev_msg = msg + yield msg + time.sleep(timeout) + + +format_status = lambda status: f"{EMOJI_BY_STATUS[status.status]} {status.notice.split('.')[0].strip()}" +format_message = lambda status: f"{EMOJI_BY_STATUS[status.status]} {status.name}\n\n{status.notice}" + + +class IDsFilter: + _ids: list[str] + _update_time: float + + def __init__(self): + self._ids = [] + self._update_dict() + + + def __call__(self, status: StatusObject) -> bool: + if self._update_time + TIMEOUT < time.time(): + self._update_dict() + + return str(status.id) in self._ids + + def _update_dict(self): + self._update_time = time.time() + try: + with open(CONFIG_FILE) as file: + self._ids = file.read().strip().replace(' ', '').split(',') + except Exception: + self._ids = [] + + +class LastUpdateFilter: + _update_time: datetime.datetime + + def __init__(self, ignore_now = False) -> None: + self._update_time = datetime.datetime.fromtimestamp(0) if not ignore_now else datetime.datetime.now() + + def __call__(self, status: StatusObject): + return status.updated_at >= self._update_time + + def update(self): + self._update_time = datetime.datetime.now() + + +def main(): + api = None + + if os.path.isfile(CACHE_FILE): + with open(CACHE_FILE) as file: + api = Api.from_dict(json.load(file)) + + if os.path.isfile(SECRET_FILE): + with open(SECRET_FILE) as secret_file: + data = json.load(secret_file) + + owner_id = data['owner_id'] + bot_token = data['bot_token'] + + if not api: + api = Api(data['username'], data['password']) + else: + print("Missing secret file!", file=sys.stderr) + exit(1) + + def die(*_): + with open(CACHE_FILE, 'w') as file: + json.dump(api.to_dict(), file) + if os.path.isfile(PIPE_FILE): + os.remove(PIPE_FILE) + exit(0) + + signal.signal(signal.SIGTERM, die) + signal.signal(signal.SIGINT, die) + + for message in listen_for_messages(api, filter_func=IDsFilter()): + with open(PIPE_FILE, 'w') as file: + print('\n'.join(map(format_status, message))) + file.write(' '.join(map(format_status, message))) + + update_filter = LastUpdateFilter(ignore_now=True) + for message in listen_for_messages(api, filter_func=update_filter): + formatted_messages = list(map(format_message, message)) + print('\n---\n'.join(formatted_messages)) + for message in formatted_messages: + send_message(owner_id, message, bot_token) + update_filter.update() + + +if __name__ == "__main__": + run_forever(main) + +# vim: ft=python diff --git a/.local/bin/scripts/ollama b/.local/bin/scripts/ollama index b5ede54..9d2ca8c 100755 --- a/.local/bin/scripts/ollama +++ b/.local/bin/scripts/ollama @@ -1,6 +1,9 @@ #!/bin/bash flags="-it" -{ [ ! -t 0 ] || [ ! -t 1 ]; } && flags= + +if [ ! -t 0 ] || [ ! -t 1 ]; then + flags= +fi docker --context=higpu exec $flags ollama-ollama-1 ollama "$@" diff --git a/.local/bin/scripts/tg b/.local/bin/scripts/tg index bba8021..a45444b 100755 --- a/.local/bin/scripts/tg +++ b/.local/bin/scripts/tg @@ -88,7 +88,7 @@ main() { fi [ -n "${print_response:+_}" ] && echo "$resp" - # [ "$(jq .ok <<<"$resp")" = "true" ] || jq <<< "$resp" >&2 + [ "$(jq .ok <<<"$resp")" = "true" ] || jq <<< "$resp" >&2 } main "$@" diff --git a/.local/bin/scripts/unplug b/.local/bin/scripts/unplug deleted file mode 100755 index 3fdf038..0000000 --- a/.local/bin/scripts/unplug +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh - -xr internal -systemctl suspend diff --git a/.local/bin/scripts/virt b/.local/bin/scripts/virt deleted file mode 100755 index aeb50f3..0000000 --- a/.local/bin/scripts/virt +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -sudo systemctl start libvirtd -sudo virsh net-start default diff --git a/.local/bin/scripts/vpn b/.local/bin/scripts/vpn index 9de23f1..dc9b88e 100755 --- a/.local/bin/scripts/vpn +++ b/.local/bin/scripts/vpn @@ -1,4 +1,10 @@ -#!/bin/bash -x +#!/bin/bash + +PIPE="/var/run/vpnd.sock" +send_cmd() { + [ -p $PIPE ] && echo "$@" > $PIPE && \ + cat < $PIPE +} send_router_cmd() { touch "${HOME}/.local/state/.vpn_loading" @@ -7,40 +13,51 @@ send_router_cmd() { rm "${HOME}/.local/state/.vpn_loading" } -awg-quick() { - PIPE="/var/run/vpnd.sock" - - [ -p $PIPE ] && - echo "$@" > $PIPE && - cat < $PIPE -} - DEFAULT_LINK="$(resolvectl status | grep 'Default Route: yes' -B10 | grep 'Link' | tail -1 | grep -Eo '\(.*\)' | tr -d '()')" if resolvectl domain "$DEFAULT_LINK" | grep -q 'wzray.com'; then IS_LOCAL=1 fi -IFNAME="awg_ext" +IFNAME="rix" while [ "$#" -gt 0 ]; do case "$1" in - i|int|internal) IFNAME='awg_int';; - *) echo "Wrong argument!" >&2; exit 1;; + 'm'|'msk') IFNAME='msk';; + '-v'|'--verbose') VERBOSE=1;; + *) echo "Wrong argument!"; exit 1;; esac shift done -UP_NAME="$(ip link | grep 'awg_' | cut -d ' ' -f 2 | sed 's,:,,')" - -if [ -n "$UP_NAME" ]; then - awg-quick down "$UP_NAME" -elif [ -n "$IS_LOCAL" ]; then - send_router_cmd toggle +if [ -z "${VERBOSE}" ]; then + exec &>/dev/null else - awg-quick up "${IFNAME}" + set -x fi +UP_NAME="$(send_cmd status)" + +if [ -n "$IS_LOCAL" ]; then + if [ -n "$UP_NAME" ]; then + send_cmd down + else + send_router_cmd toggle + fi +else + if [ -n "${UP_NAME}" ]; then + if [ "${UP_NAME}" != "${IFNAME}" ]; then + send_cmd down + send_cmd up "$IFNAME" + else + send_cmd down + fi + else + send_cmd up "$IFNAME" + fi +fi + + pkill -36 dwmblocks # vim: ft=bash diff --git a/.local/bin/scripts/vpnd b/.local/bin/scripts/vpnd index 22c042f..c529be0 100755 --- a/.local/bin/scripts/vpnd +++ b/.local/bin/scripts/vpnd @@ -1,49 +1,92 @@ #!/bin/bash # shellcheck disable=SC2034 +die() { + [ -n "$oc_pid" ] && kill -s TERM "$oc_pid" + echo "exitting..." + rm -f $PIPE + exit 0 +} + +trap 'die' SIGTERM SIGQUIT SIGINT + PIPE="/var/run/vpnd.sock" +oc_pid= +up_name= [ -p $PIPE ] && exit 1 [ "$(id -u)" != "0" ] && exit 1 -trap 'die' SIGTERM SIGQUIT SIGINT - declare -a CONFIGS -for config in /etc/amnezia/amneziawg/*; do - config="$(basename "$config")" - CONFIGS+=("${config%.conf}") +for config in /etc/openconnect/config_*; do + config="$(basename "$config")" + CONFIGS+=("${config#config_}") done -COMMANDS=("up" "down") +COMMANDS=("up" "down" "status") -die() { - rm $PIPE - exit 0 +is_really_up() { + [ -n "$oc_pid" ] && if ! kill -0 "$oc_pid"; then + oc_pid= + up_name= + fi } in_arr() { - declare -n arr="$2" + declare -n arr="$2" - for value in "${arr[@]}"; do - [ "$value" = "$1" ] && return 0 - done - return 1 + for value in "${arr[@]}"; do + [ "$value" = "$1" ] && return 0 + done + return 1 +} + +down() { + is_really_up + [ -z "$oc_pid" ] && return + kill -s TERM "$oc_pid" + wait "$oc_pid" + oc_pid= + up_name= +} + +up() { + is_really_up + [ -n "$oc_pid" ] && down + openconnect --config "/etc/openconnect/config_$1" & + oc_pid="$!" + up_name="$1" +} + +status() { + is_really_up + echo "$up_name" > $PIPE } main() { - mkfifo $PIPE -m666 + mkfifo $PIPE -m666 - while :; do - read -r cmd ifname < $PIPE + while :; do + read -r cmd ifname < $PIPE + if ! in_arr "$cmd" "COMMANDS"; then + echo "ERROR: Invalid command $cmd" > $PIPE + else + case "$cmd" in + "up") + if ! in_arr "$ifname" "CONFIGS"; then + echo "ERROR: Invalid interface $ifname" > $PIPE + else + up "$ifname" + echo "$ifname" > $PIPE + fi + ;; + "down") down; echo "down" > $PIPE;; + "status") status;; + esac - if ! in_arr "$ifname" "CONFIGS"; then - echo "ERROR: Invalid interface $ifname" > $PIPE - elif ! in_arr "$cmd" "COMMANDS"; then - echo "ERROR: Invalid command $cmd" > $PIPE - else - awg-quick "$cmd" "$ifname" > $PIPE 2>&1 - fi - done + fi + done } +echo "Running..." main diff --git a/.local/bin/scripts/wdate b/.local/bin/scripts/wdate deleted file mode 100755 index c9721a1..0000000 --- a/.local/bin/scripts/wdate +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -trap 'echo; exit' 'INT' - -while :; do - printf '\r' - date "$@" | tr -d '\n' - sleep 0.99 -done diff --git a/.local/bin/scripts/xr b/.local/bin/scripts/xr index e632aa8..583ecd6 100755 --- a/.local/bin/scripts/xr +++ b/.local/bin/scripts/xr @@ -1,5 +1,7 @@ #!/bin/bash +# supress stderr + change_dpi() { sed -i -E --follow-symlinks "s/Xft\.dpi: .*?/Xft\.dpi: $1/g" ~/.Xresources sed -i -E --follow-symlinks "s/Xcursor\.size: .*?/Xcursor\.size: $2/g" ~/.Xresources @@ -18,7 +20,7 @@ EXT_MON="$(xrandr | grep -ow "\(DP-[0-9]\) connected" | cut -d " " -f 1)" INT_MODELINE=$(cvt 1560 1040 90 | grep "Modeline" | cut -d " " -f 2- | tr -d '"') INT_RES="$(echo $INT_MODELINE | cut -d ' ' -f 1 | tr -d '\"')" -if [[ -z "${EXT_MON}" ]] || [ "$1" = "internal" ]; then +if [[ -z "${EXT_MON}" ]]; then xrandr --output eDP-1 --pos 0x0 --mode "3120x2080" --rate 90 --primary --output DP-1 --off --output DP-2 --off --output DP-3 --off --output DP-4 --off xrandr --delmode eDP-1 "${INT_RES}" xrandr --rmmode "${INT_RES}" @@ -27,13 +29,9 @@ else : xrandr --rmmode "${INT_RES}" # shellcheck disable=all - - # temp remove edp - # xrandr --newmode $(echo $INT_MODELINE) # this is a hack to make xrandr recognize the resolution - # xrandr --addmode eDP-1 "${INT_RES}" - # xrandr --output eDP-1 --pos 2560x400 --mode "${INT_RES}" --output "${EXT_MON}" --pos 0x0 --mode "2560x1440" --rate 144 --primary - - xrandr --output eDP-1 --off --output "${EXT_MON}" --pos 0x0 --mode "2560x1440" --rate 144 --primary + xrandr --newmode $(echo $INT_MODELINE) # this is a hack to make xrandr recognize the resolution + xrandr --addmode eDP-1 "${INT_RES}" + xrandr --output eDP-1 --pos 2560x400 --mode "${INT_RES}" --output "${EXT_MON}" --pos 0x0 --mode "2560x1440" --rate 144 --primary change_dpi 96 24 fi diff --git a/.local/bin/source/src_add_path b/.local/bin/source/src_add_path index 8b218a3..5431081 100644 --- a/.local/bin/source/src_add_path +++ b/.local/bin/source/src_add_path @@ -1,14 +1,15 @@ [ -z "$1" ] && { - echo 'Missing path parameter!' >&2 + echo "Missing path parameter!" >&2 return 1 } full_path="$(readlink -e "$1")" -[ -d "$full_path" ] || { + +[ ! -d "$full_path" ] && { echo "Path doesn't exist!" >&2 return 1 } -[[ ":$PATH:" == *":${full_path}:"* ]] || export PATH="$full_path:$PATH" +export PATH="$full_path:$PATH" # vim: ft=sh diff --git a/.local/bin/source/src_venv b/.local/bin/source/src_venv index 03795b6..2191ddf 100644 --- a/.local/bin/source/src_venv +++ b/.local/bin/source/src_venv @@ -19,18 +19,8 @@ help() { } -deactivate_or_unset() { - if command -v deactivate >/dev/null 2>&1; then - deactivate - else - unset VIRTUAL_ENV - unset VIRTUAL_ENV_PROMPT - fi -} - - remove() { - [ -n "${VIRTUAL_ENV}" ] && deactivate_or_unset + [ -n "${VIRTUAL_ENV}" ] && deactivate rm -rf "${VENV_FOLDER}" } @@ -63,9 +53,9 @@ VENV_FOLDER="${VENV_FOLDER_PATH}/${VENV_FOLDER_NAME}" # shellcheck disable=SC2015 case "${OPERATION}" in - c) [ -z "${VIRTUAL_ENV}" ] && create_or_activate || help >&2;; - d) [ -n "${VIRTUAL_ENV}" ] && deactivate_or_unset || help >&2;; - r) [ -d "${VENV_FOLDER}" ] && remove || help >&2;; + c) [ -z "${VIRTUAL_ENV}" ] && create_or_activate || help >&2;; + d) [ -n "${VIRTUAL_ENV}" ] && deactivate || help >&2;; + r) [ -d "${VENV_FOLDER}" ] && remove || help >&2;; esac # vim: ft=sh diff --git a/.local/bin/statusbar/sb-battery b/.local/bin/statusbar/sb-battery index 872d0a6..5b12415 100755 --- a/.local/bin/statusbar/sb-battery +++ b/.local/bin/statusbar/sb-battery @@ -42,7 +42,7 @@ for battery_path in /sys/class/power_supply/!(AC*); do status_symbol="${custom_icons["$device_name"]}" elif [ "$capacity" -eq 100 ]; then status_symbol=" " - elif [ "$status" = "Discharging" ] && [ "$capacity" -le 20 ]; then + elif [[ "$status" = "Discharging" && "$capacity" -le 20 ]]; then status_symbol="❗" [ -n "$sep" ] && sep="" || sep=" "; fi diff --git a/.local/bin/statusbar/sb-silent b/.local/bin/statusbar/sb-silent deleted file mode 100755 index 2708d79..0000000 --- a/.local/bin/statusbar/sb-silent +++ /dev/null @@ -1 +0,0 @@ -dunstctl is-paused -e && echo '' diff --git a/.local/bin/statusbar/sb-vpn b/.local/bin/statusbar/sb-vpn index fb9d2f3..276f398 100755 --- a/.local/bin/statusbar/sb-vpn +++ b/.local/bin/statusbar/sb-vpn @@ -5,33 +5,26 @@ exit 0 } +PIPE="/var/run/vpnd.sock" send_cmd() { - PIPE="/var/run/vpnd.sock" - [ -p $PIPE ] && echo "$@" > $PIPE && cat < $PIPE + [ -p $PIPE ] && echo "$@" > $PIPE && \ + cat < $PIPE } -router_status() { - ssh -i "$HOME"/.ssh/id_watcher router vpn status laptop 2>/dev/null -} +IFNAME="$(send_cmd status)" -case "$(ip link | grep 'awg_' | cut -d ' ' -f2 | tr -d ':' | sed 's,awg_,,')" in - "int") IFNAME="󰻌 Saint-Petersburg";; - "ext") IFNAME="󰦝 Riga";; +case "$IFNAME" in + "msk") IFNAME="Moscow";; + "rix") IFNAME="Riga";; esac -[ -n "$IFNAME" ] && { - echo "$IFNAME" +if [ -n "$IFNAME" ]; then + echo "󰦝 $IFNAME" exit 0 -} +fi -DEFAULT_LINK="$( - resolvectl status | \ - grep 'Default Route: yes' -B10 | \ - grep 'Link' | \ - tail -1 | \ - grep -Eo '\(.*\)' | \ - tr -d '()' -)" +DEFAULT_LINK="$(resolvectl status | grep 'Default Route: yes' -B10 | grep 'Link' | tail -1 | grep -Eo '\(.*\)' | tr -d '()')" -resolvectl domain "$DEFAULT_LINK" | grep -q 'wzray.com' && \ - [ "$(router_status)" = '1' ] && echo "󰦝" +if resolvectl domain "$DEFAULT_LINK" | grep -q 'wzray.com'; then + [ "$(ssh router vpn status laptop 2>/dev/null)" = '1' ] && echo "󰦝 Local" +fi diff --git a/.ssh/config b/.ssh/config index fb67fd0..6a993af 100644 --- a/.ssh/config +++ b/.ssh/config @@ -2,13 +2,6 @@ Host * AddKeysToAgent yes IdentityFile ~/.ssh/id_ed25519 -Host vm.zvray.ru - Port 22 - User root - StrictHostKeyChecking no - UpdateHostkeys no - UserKnownHostsFile /dev/null - Host *.zvray.ru mx*.wzray.com User root Port 8022 @@ -22,16 +15,11 @@ Host laptop laptop.*.wzray.com Host hicpu hicpu.spb.wzray.com User root -Host higpu-docker-storage - HostName higpu.spb.wzray.com - User root - Port 2201 - Host git.wzray.com User git Port 2201 -Host 192.168.1.1 10.161.0.1 10.161.0.2 10.162.0.1 openwrt router ap gateway router.*.wzray.com ap.*.wzray.com openwrt.*.wzray.com +Host 192.168.1.1 10.161.0.1 10.161.0.2 10.162.0.1 openwrt router ap gateway router.*.wzray.com ap.*.wzray.com openwrt.*.wzray.com gateway.*.wzray.com User root UserKnownHostsFile /dev/null IdentityFile /dev/null @@ -39,4 +27,3 @@ Host 192.168.1.1 10.161.0.1 10.161.0.2 10.162.0.1 openwrt router ap gateway rout UpdateHostkeys no PubkeyAcceptedAlgorithms +ssh-rsa HostkeyAlgorithms +ssh-rsa - LogLevel ERROR