diff --git a/.github/shellcheck-matcher.json b/.github/shellcheck-matcher.json new file mode 100644 index 0000000..4c97a36 --- /dev/null +++ b/.github/shellcheck-matcher.json @@ -0,0 +1,18 @@ +{ + "problemMatcher": [ + { + "owner": "shellcheck", + "severity": "warning", + "pattern": [ + { + "regexp": "^(.+):(\\d+):(\\d+):\\s+(note|style|warning|error):\\s+(.+)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + ] + } + ] +} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..23116ec --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,16 @@ +name: lint + +on: + push: + branches: [main] + pull_request: + +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 + - name: Run shellcheck + run: | + echo "::add-matcher::.github/shellcheck-matcher.json" + find . -name "*.sh" -exec shellcheck --format=gcc --severity=error {} + diff --git a/nvim/dein.toml b/nvim/dein.toml index 2d13fde..d6d8798 100644 --- a/nvim/dein.toml +++ b/nvim/dein.toml @@ -100,28 +100,6 @@ lua_source = ''' require('rc.hlchunk') ''' -[[plugins]] -repo = 'https://github.com/MeanderingProgrammer/render-markdown.nvim' -depends = [ 'nvim-treesitter' ] -on_ft = [ 'markdown', "markdown.mdx", "codecompanion" ] -lua_source = ''' -require('render-markdown').setup({ - file_types = { "markdown", "Avante", "codecompanion" }, -}) -''' - -# [[plugins]] -# repo = 'Shougo/deol.nvim' -# hook_source = ''' -# " Should set g:deol#prompt_pattern. -# let g:deol#prompt_pattern = has('win32') ? '\f\+>' : '\w*% \?' -# if !has('win32') -# let g:deol#external_history_path = '~/.zsh_history' -# endif -# -# nnoremap s 'Deol -edit' -# ''' - # --- General Rich Text Editing --- [[plugins]] repo = 'https://github.com/simeji/winresizer' @@ -305,7 +283,7 @@ require('nvim-ts-autotag').setup() [[plugins]] repo = 'https://github.com/nvim-treesitter/nvim-treesitter' -on_event = ['BufRead', 'CursorHold'] +rev = 'main' merged = 0 hook_post_update = 'TSUpdate' lua_source = ''' @@ -314,7 +292,27 @@ require('rc.treesitter') [[plugins]] repo = 'https://github.com/nvim-treesitter/nvim-treesitter-textobjects' +rev = 'main' depends = ['nvim-treesitter'] +lua_source = ''' +require("nvim-treesitter-textobjects").setup({ select = { lookahead = true } }) +local select = require("nvim-treesitter-textobjects.select") +local keymaps = { + ab = { "@block.outer", "Select outer part of a block region" }, + ib = { "@block.inner", "Select inner part of a block region" }, + ai = { "@conditional.outer", "Select outer part of a conditional" }, + ii = { "@conditional.inner", "Select inner part of a conditional" }, + al = { "@loop.outer", "Select outer part of a loop" }, + il = { "@loop.inner", "Select inner part of a loop" }, + af = { "@function.outer", "Select outer part of a method/function definition" }, + ["if"] = { "@function.inner", "Select inner part of a method/function definition" }, +} +for key, v in pairs(keymaps) do + vim.keymap.set({ "x", "o" }, key, function() + select.select_textobject(v[1], "textobjects") + end, { desc = v[2] }) +end +''' # --- Git --- [[plugins]] diff --git a/nvim/lua/rc/lsp/keymap.lua b/nvim/lua/rc/lsp/keymap.lua index 0a51dde..4c3f666 100644 --- a/nvim/lua/rc/lsp/keymap.lua +++ b/nvim/lua/rc/lsp/keymap.lua @@ -1,38 +1,36 @@ return function() --- See `:help vim.diagnostic.*` for documentation on any of the below functions -vim.keymap.set("n", "df", "lua vim.diagnostic.open_float()", { noremap = true, silent = true }) -vim.keymap.set("n", "[e", function() vim.diagnostic.jump({ count = -1 }) end, { noremap = true, silent = true }) -vim.keymap.set("n", "]e", function() vim.diagnostic.jump({ count = 1 }) end, { noremap = true, silent = true }) -vim.keymap.set("n", "q", "lua vim.diagnostic.setloclist()", { noremap = true, silent = true }) -vim.keymap.set("n", "f", - function() require("my.utils").keep_cursor(vim.lsp.buf.format) end, - { noremap = true, silent = true }) + -- diagnostics (LSP 不要なのでグローバル設定) + local opts = { noremap = true, silent = true } + vim.keymap.set("n", "gs", vim.diagnostic.open_float, opts) + vim.keymap.set("n", "[e", function() + vim.diagnostic.jump({ count = -1 }) + end, opts) + vim.keymap.set("n", "]e", function() + vim.diagnostic.jump({ count = 1 }) + end, opts) + vim.keymap.set("n", "q", vim.diagnostic.setloclist, opts) + -- LSP keymaps (LspAttach でバッファローカルに設定) + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local bufopts = { noremap = true, silent = true, buffer = args.buf } - local bufopts = { noremap = true, silent = true, buffer = bufnr } - -- code reading - -- show information at cursor - --- 定義情報などを表示する - vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts) - --- 関数の引数の内容とかを表示する - vim.keymap.set("n", "", vim.lsp.buf.signature_help, bufopts) - --- カーソル行のエラーを表示 - vim.keymap.set("n", "gs", vim.diagnostic.open_float, bufopts) + -- code reading + --- 定義情報などを表示する + vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts) + --- 関数の引数の内容とかを表示する + vim.keymap.set("n", "", vim.lsp.buf.signature_help, bufopts) - -- code walking - --- 前のエラーに移動 - vim.keymap.set("n", "g[", function() vim.diagnostic.jump({ count = -1 }) end, bufopts) - --- 次のエラーに移動 - vim.keymap.set("n", "g]", function() vim.diagnostic.jump({ count = 1 }) end, bufopts) + -- code edit + --- 関数名や変数名をリネーム + vim.keymap.set("n", "r", vim.lsp.buf.rename, bufopts) + vim.keymap.set("n", "f", function() + require("my.utils").keep_cursor(vim.lsp.buf.format) + end, bufopts) - -- code edit - --- 関数名や変数名をリネーム - vim.keymap.set("n", "r", vim.lsp.buf.rename, bufopts) - - -- workspace - --- ワークスペース一覧を表示 - -- vim.keymap.set("n", "wl", "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))") - --- ワークスペースにフォルダを追加する - vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder) - vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder) + -- workspace + vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, bufopts) + vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, bufopts) + end, + }) end diff --git a/nvim/lua/rc/treesitter.lua b/nvim/lua/rc/treesitter.lua index 11d5294..3c2d189 100644 --- a/nvim/lua/rc/treesitter.lua +++ b/nvim/lua/rc/treesitter.lua @@ -1,91 +1,22 @@ -require 'nvim-treesitter.configs'.setup { - ensure_installed = { - "go", - "gotmpl", - "tsx", "css", - "lua", - "perl", - "markdown", "toml", "yaml", "json", - }, - auto_install = false, - sync_install = false, -- install languages synchronously (only applied to `ensure_installed`) - highlight = { - enable = true, -- false will disable the whole extension - disable = { "vim" }, -- list of language that will be disabled - additional_vim_regex_highlighting = false, - }, - indent = { - enable = true, - }, - context_commentstring = { - enable_autocmd = false, - }, - incremental_selection = { - enable = true, - keymaps = { - init_selection = "", - node_incremental = "", - node_decremental = "", - }, - }, - textobjects = { - select = { - enable = true, - -- Automatically jump forward to textobj, similar to targets.vim - lookahead = true, - keymaps = { - ["ab"] = { - query = "@block.outer", - desc = "Select outer part of a block region" - }, - ["ib"] = { - query = "@block.inner", - desc = "Select inner part of a block region" - }, - - ["ai"] = { - query = "@conditional.outer", - desc = "Select outer part of a conditional" - }, - ["ii"] = { - query = "@conditional.inner", - desc = "Select inner part of a conditional" - }, - - ["al"] = { - query = "@loop.outer", - desc = "Select outer part of a loop" - }, - ["il"] = { - query = "@loop.inner", - desc = "Select inner part of a loop" - }, +-- Parser installation (new API; replaces ensure_installed) +local installed = require('nvim-treesitter.config').get_installed() +local parsers = { "go", "gotmpl", "tsx", "css", "lua", "perl", "markdown", "toml", "yaml", "json" } +local to_install = vim.iter(parsers) + :filter(function(p) return not vim.tbl_contains(installed, p) end) + :totable() +if #to_install > 0 then + require('nvim-treesitter').install(to_install) +end - ["af"] = { - query = "@function.outer", - desc = "Select outer part of a method/function definition", - }, - ["if"] = { - query = "@function.inner", - desc = "Select inner part of a method/function definition", - }, - - }, - }, - }, -} - --- go template engine --- local parser_config = require 'nvim-treesitter.parsers'.get_parser_configs() --- parser_config.gotmpl = { --- install_info = { --- url = "https://github.com/ngalaiko/tree-sitter-go-template", --- files = { "src/parser.c" } --- }, --- filetype = "gotmpl", --- used_by = { "gohtmltmpl", "gotexttmpl", "gotmpl", "yaml" } --- } +-- Highlighting and indentation via Neovim built-in treesitter (0.12+) +vim.api.nvim_create_autocmd('FileType', { + callback = function() + pcall(vim.treesitter.start) + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end, +}) +-- Filetype detection vim.filetype.add({ extension = { gotmpl = 'gotmpl', @@ -100,6 +31,6 @@ vim.filetype.add({ vim.api.nvim_create_autocmd({ "BufNewFile", "BufRead" }, { pattern = { "*.tmpl" }, callback = function() - vim.bo.filetype = "gotmpl" + vim.bo.filetype = "gotmpl" end, }) diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..e71b655 --- /dev/null +++ b/renovate.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": ["config:recommended"], + "minimumReleaseAge": "3 days", + "packageRules": [ + { + matchDepTypes: ["action"], + excludePackagePrefixes: ["actions/"], + pinDigests: true, + }, + ], +} diff --git a/shlib/bash/bash-completion.sh b/shlib/bash/bash-completion.sh index 00b229b..d7ab4a4 100644 --- a/shlib/bash/bash-completion.sh +++ b/shlib/bash/bash-completion.sh @@ -1,10 +1,12 @@ +# shellcheck shell=bash # memo command completion function _go_memo(){ + # shellcheck disable=SC2034 # _get_comp_words_by_ref が参照渡しで設定する local prev cur cword # get the input informations (ref: /usr/share/bash-completion/bash_completion ) _get_comp_words_by_ref -n : cur prev cword opts="new list edit cat delete grep config serve" - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + mapfile -t COMPREPLY < <(compgen -W "${opts}" -- "${cur}") } && complete -F _go_memo memo diff --git a/shlib/bash/check-true-color.sh b/shlib/bash/check-true-color.sh index 42e7941..b869d2e 100644 --- a/shlib/bash/check-true-color.sh +++ b/shlib/bash/check-true-color.sh @@ -1,3 +1,4 @@ +#!/bin/sh # https://blog.nakanishy.com/truecolor-vim.html # なめらかな虹色が表示されればOK diff --git a/shlib/bash/fzf-wrapper.sh b/shlib/bash/fzf-wrapper.sh index c14de5c..ca21823 100644 --- a/shlib/bash/fzf-wrapper.sh +++ b/shlib/bash/fzf-wrapper.sh @@ -1,4 +1,4 @@ -#! /bin/sh - +#!/usr/bin/env bash # Usage: # fd depth base-directory diff --git a/shlib/bash/git-ch-id.sh b/shlib/bash/git-ch-id.sh index 85b9332..7903033 100644 --- a/shlib/bash/git-ch-id.sh +++ b/shlib/bash/git-ch-id.sh @@ -8,5 +8,5 @@ ch-git-name() opt="s/${oldID}/${newID}/" - git remote set-url origin `git config --get remote.origin.url | sed "${opt}"` + git remote set-url origin "$(git config --get remote.origin.url | sed "${opt}")" } diff --git a/shlib/bash/pathfind.sh b/shlib/bash/pathfind.sh index cc6d4fe..9b53ba1 100644 --- a/shlib/bash/pathfind.sh +++ b/shlib/bash/pathfind.sh @@ -22,6 +22,7 @@ IFS=' ' # 信頼できる場所からのみプログラムを呼び出すようにする。 +# shellcheck disable=SC2034 # eval経由で参照される OLDPATH="$PATH" PATH=/bin:/usr/bin export PATH diff --git a/shlib/bash/run-with-color.sh b/shlib/bash/run-with-color.sh index 0e2d29b..0b5a1b4 100644 --- a/shlib/bash/run-with-color.sh +++ b/shlib/bash/run-with-color.sh @@ -19,7 +19,7 @@ cyan=36 colored() { color=$1 shift - echo -e "\033[1;${color}m$@\033[0m" + echo -e "\033[1;${color}m$*\033[0m" } run() { @@ -27,9 +27,9 @@ run() { result=$? if [ $result -ne 0 ]; then - echo -n $(colored $red "Faild: ") - echo -n $(colored $cyan "$0") - echo $(colored $yellow " [$PWD]") + echo -n "$(colored $red "Faild: ")" + echo -n "$(colored $cyan "$0")" + echo "$(colored $yellow " [$PWD]")" exit $result fi return 0 diff --git a/shlib/bash/sample.sh b/shlib/bash/sample.sh index cdc924e..bb26187 100644 --- a/shlib/bash/sample.sh +++ b/shlib/bash/sample.sh @@ -11,7 +11,9 @@ fi # passwordの入力等で必ず人出で入力してほしいデータを読み込む場合などに便利なファイル printf "New Password" stty -echo # 入力された文字が表示されるのを防ぐ +# shellcheck disable=SC2034 read pass < /dev/tty # パスワードを読み込みます printf "Confirm Password" +# shellcheck disable=SC2034 read pass2 < /dev/tty # もう一度パスワードを読み込みます stty echo # 画面表示をもとに戻します。 diff --git a/shlib/common/git-alias.sh b/shlib/common/git-alias.sh index 63d7c82..df66c96 100644 --- a/shlib/common/git-alias.sh +++ b/shlib/common/git-alias.sh @@ -1,3 +1,4 @@ +#!/bin/sh git config --global alias.s status git config --global alias.d diff git config --global alias.b branch diff --git a/tmux-session.sh b/tmux-session.sh index 5a5d83f..d4ae3f9 100755 --- a/tmux-session.sh +++ b/tmux-session.sh @@ -4,7 +4,6 @@ set -euo pipefail # ─────────────────────────────── # 設定 # ─────────────────────────────── -GHQ_ROOT=$(ghq root) TMP_FILE=$(mktemp) # ───────────────────────────────