From 284b8adee87bebe3a2b1c260bf12800072c55a75 Mon Sep 17 00:00:00 2001 From: Christoffer Martinsson Date: Thu, 15 May 2025 10:54:48 +0200 Subject: [PATCH] Updated scripts --- bashrc | 2 + clang-format | 225 ------------------------------------------- config/nvim/init.lua | 113 +++++----------------- update_arch.sh | 1 - update_ubuntu.sh | 32 +++++- 5 files changed, 54 insertions(+), 319 deletions(-) delete mode 100644 clang-format diff --git a/bashrc b/bashrc index 971e8c3..a94b287 100644 --- a/bashrc +++ b/bashrc @@ -50,6 +50,8 @@ alias ls="eza -1 -l --icons=auto --git-repos --git -h -g -o --no-permissions" alias lsa="eza -1 -l --icons=auto --git-repos --git -h -g -o --no-permissions -a" alias lss="eza -1 -l --icons=auto --git-repos --git -h -g --total-size -o --no-permissions -a" +eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + if [[ ! $TERM =~ linux ]]; then if [[ $TERM =~ tmux ]]; then source ~/.fzf.bash diff --git a/clang-format b/clang-format deleted file mode 100644 index 136b821..0000000 --- a/clang-format +++ /dev/null @@ -1,225 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: LLVM -AccessModifierOffset: -2 -AlignAfterOpenBracket: Align -AlignArrayOfStructures: None -AlignConsecutiveAssignments: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: true -AlignConsecutiveBitFields: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: false -AlignConsecutiveDeclarations: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: false -AlignConsecutiveMacros: - Enabled: false - AcrossEmptyLines: false - AcrossComments: false - AlignCompound: false - PadOperators: false -AlignEscapedNewlines: Right -AlignOperands: Align -AlignTrailingComments: - Kind: Always - OverEmptyLines: 0 -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: Never -AllowShortCaseLabelsOnASingleLine: false -AllowShortEnumsOnASingleLine: true -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: WithoutElse -AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: MultiLine -AttributeMacros: - - __capability -BinPackArguments: true -BinPackParameters: true -BitFieldColonSpacing: Both -BraceWrapping: - AfterCaseLabel: false - AfterClass: false - AfterControlStatement: Never - AfterEnum: false - AfterExternBlock: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: true - SplitEmptyRecord: true - SplitEmptyNamespace: true -BreakAfterAttributes: Never -BreakAfterJavaFieldAnnotations: false -BreakArrays: true -BreakBeforeBinaryOperators: None -BreakBeforeConceptDeclarations: Always -BreakBeforeBraces: Attach -BreakBeforeInlineASMColon: OnlyMultiline -BreakBeforeTernaryOperators: true -BreakConstructorInitializers: BeforeColon -BreakInheritanceList: BeforeColon -BreakStringLiterals: true -ColumnLimit: 140 -CommentPragmas: '^ IWYU pragma:' -CompactNamespaces: false -ConstructorInitializerIndentWidth: 4 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: LogicalBlock -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: - - foreach - - Q_FOREACH - - BOOST_FOREACH -IfMacros: - - KJ_IF_MAYBE -IncludeBlocks: Preserve -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - SortPriority: 0 - CaseSensitive: false - - Regex: '^(<|"(gtest|gmock|isl|json)/)' - Priority: 3 - SortPriority: 0 - CaseSensitive: false - - Regex: '.*' - Priority: 1 - SortPriority: 0 - CaseSensitive: false -IncludeIsMainRegex: '(Test)?$' -IncludeIsMainSourceRegex: '' -IndentAccessModifiers: false -IndentCaseBlocks: false -IndentCaseLabels: false -IndentExternBlock: AfterExternBlock -IndentGotoLabels: true -IndentPPDirectives: None -IndentRequiresClause: true -IndentWidth: 4 -IndentWrappedFunctionNames: false -InsertBraces: false -InsertNewlineAtEOF: false -InsertTrailingCommas: None -IntegerLiteralSeparator: - Binary: 0 - BinaryMinDigits: 0 - Decimal: 0 - DecimalMinDigits: 0 - Hex: 0 - HexMinDigits: 0 -JavaScriptQuotes: Leave -JavaScriptWrapImports: true -KeepEmptyLinesAtTheStartOfBlocks: true -LambdaBodyIndentation: Signature -LineEnding: DeriveLF -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBinPackProtocolList: Auto -ObjCBlockIndentWidth: 2 -ObjCBreakBeforeNestedBlockParam: true -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PackConstructorInitializers: BinPack -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakOpenParenthesis: 0 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 10 -PenaltyExcessCharacter: 1000000 -PenaltyIndentedWhitespace: 0 -PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Right -PPIndentWidth: -1 -QualifierAlignment: Leave -ReferenceAlignment: Pointer -ReflowComments: true -RemoveBracesLLVM: false -RemoveSemicolon: false -RequiresClausePosition: OwnLine -RequiresExpressionIndentation: OuterScope -SeparateDefinitionBlocks: Leave -ShortNamespaceLines: 1 -SortIncludes: CaseSensitive -SortJavaStaticImport: Before -SortUsingDeclarations: LexicographicNumeric -SpaceAfterCStyleCast: false -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: true -SpaceAroundPointerQualifiers: Default -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: ControlStatements -SpaceBeforeParensOptions: - AfterControlStatements: true - AfterForeachMacros: true - AfterFunctionDefinitionName: false - AfterFunctionDeclarationName: false - AfterIfMacros: true - AfterOverloadedOperator: false - AfterRequiresInClause: false - AfterRequiresInExpression: false - BeforeNonEmptyParentheses: false -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBlock: false -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: Never -SpacesInConditionalStatement: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Latest -StatementAttributeLikeMacros: - - Q_EMIT -StatementMacros: - - Q_UNUSED - - QT_REQUIRE_VERSION -TabWidth: 8 -UseTab: Never -WhitespaceSensitiveMacros: - - BOOST_PP_STRINGIZE - - CF_SWIFT_NAME - - NS_SWIFT_NAME - - PP_STRINGIZE - - STRINGIZE -... - diff --git a/config/nvim/init.lua b/config/nvim/init.lua index 09f1822..8deac60 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -1,85 +1,45 @@ +------------------------------------------------------------------- +-- Settings +------------------------------------------------------------------- vim.g.mapleader = " " vim.g.maplocalleader = " " --- vim.g.loaded_netrw = 1 --- vim.g.loaded_netrwPlugin = 1 - --- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = true - --- Set highlight on search vim.o.hlsearch = false - --- Make line numbers default vim.wo.number = true - --- Enable mouse mode vim.o.mouse = "a" - --- Enable break indent vim.o.breakindent = true - --- Save undo history vim.o.undofile = true - --- Case insensitive searching UNLESS /C or capital in search vim.o.ignorecase = true vim.o.smartcase = true - --- Keep signcolumn on by default vim.wo.signcolumn = "yes" - --- Set completeopt to have a better completion experience --- vim.o.completeopt = "menuone,noselect,noinsert" - --- Use terminal colors vim.o.termguicolors = true - --- Tabs vim.o.shiftwidth = 4 vim.o.smarttab = true vim.o.tabstop = 4 vim.o.expandtab = true vim.o.softtabstop = 4 - --- Preview substitutions live, as you type! vim.o.inccommand = "split" - --- Show cursor line vim.o.cursorline = true - vim.o.showmatch = true - --- Decrease update time vim.o.updatetime = 250 - --- Decrease mapped sequence wait time vim.o.timeoutlen = 300 - vim.o.pumheight = 10 vim.o.relativenumber = true vim.o.scrolloff = 8 - --- Don't show the mode, since it's already in the status line vim.o.showmode = false - vim.o.showtabline = 0 - vim.o.wrap = true - vim.o.foldmethod = "expr" vim.o.foldexpr = "nvim_treesitter#foldexpr()" vim.o.foldlevelstart = 99 +vim.o.autoread = true vim.schedule(function() vim.o.clipboard = "unnamedplus" end) -vim.o.autoread = true - ------------------------------------------------------------------- -- Autocommands ------------------------------------------------------------------- - -- Autoset current working directory based on closest git repo vim.api.nvim_create_autocmd("BufEnter", { callback = function() @@ -90,7 +50,6 @@ vim.api.nvim_create_autocmd("BufEnter", { end end, }) - -- show cursor line only in active window local cursorLineGrp = vim.api.nvim_create_augroup("CursorLine", { clear = true }) vim.api.nvim_create_autocmd( @@ -109,7 +68,6 @@ vim.api.nvim_create_autocmd( { "InsertEnter", "FocusLost" }, { pattern = "*", command = "set nocursorline", group = cursorLineGrp } ) - -- Auto update on file changes vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "CursorHoldI", "FocusGained" }, { command = "if mode() != 'c' | checktime | endif", @@ -177,48 +135,22 @@ require("lazy").setup({ vim.api.nvim_create_autocmd("LspAttach", { group = vim.api.nvim_create_augroup("kickstart-lsp-attach", { clear = true }), callback = function(event) - -- In this case, we create a function that lets us more easily define mappings specific - -- for LSP related items. It sets the mode, buffer and description for us each time. local map = function(keys, func, desc, mode) mode = mode or "n" vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = "LSP: " .. desc }) end - -- Rename the variable under your cursor. - -- Most Language Servers support renaming across files, etc. map("grn", vim.lsp.buf.rename, "[R]e[n]ame") - - -- Execute a code action, usually your cursor needs to be on top of an error - -- or a suggestion from your LSP for this to activate. map("gra", vim.lsp.buf.code_action, "[G]oto Code [A]ction", { "n", "x" }) - - -- Find references for the word under your cursor. map("grr", require("fzf-lua").lsp_references, "[G]oto [R]eferences") - - -- Jump to the implementation of the word under your cursor. - -- Useful when your language has ways of declaring types without an actual implementation. map("gri", require("fzf-lua").lsp_implementations, "[G]oto [I]mplementation") - - -- Jump to the definition of the word under your cursor. - -- This is where a variable was first declared, or where a function is defined, etc. - -- To jump back, press . map("grd", require("fzf-lua").lsp_definitions, "[G]oto [D]efinition") -- WARN: This is not Goto Definition, this is Goto Declaration. -- For example, in C this would take you to the header. map("grD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") - - -- Fuzzy find all the symbols in your current document. - -- Symbols are things like variables, functions, types, etc. map("gO", require("fzf-lua").lsp_document_symbols, "Open Document Symbols") - - -- Fuzzy find all the symbols in your current workspace. - -- Similar to document symbols, except searches over your entire project. map("gW", require("fzf-lua").lsp_live_workspace_symbols, "Open Workspace Symbols") - - -- Jump to the type of the word under your cursor. - -- Useful when you're not sure what type a variable is and you want to see - -- the definition of its *type*, not where it was *defined*. map("grt", require("fzf-lua").lsp_typedefs, "[G]oto [T]ype Definition") -- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10) @@ -349,15 +281,29 @@ require("lazy").setup({ opts = { formatters_by_ft = { lua = { "stylua" }, - -- Conform will run multiple formatters sequentially - python = { "black" }, - -- You can customize some of the format options for the filetype (:help conform.format) + python = { "isort", "black", timeout_ms = 3000 }, rust = { "rustfmt", lsp_format = "fallback" }, - -- Conform will run the first available formatter - javascript = { "prettier", stop_after_first = true }, + c = { "clang_format" }, + cpp = { "clang_format" }, + javascript = { "prettier" }, + typescript = { "prettier" }, + javascriptreact = { "prettier" }, + typescriptreact = { "prettier" }, + css = { "prettier" }, + html = { "prettier" }, + json = { "prettier" }, + yaml = { "prettier" }, + markdown = { "prettier" }, + }, + formatters = { + clang_format = { + prepend_args = { "--style={BasedOnStyle: LLVM, IndentWidth: 4, TabWidth: 4, UseTab: Never}" }, + }, + shfmt = { + prepend_args = { "-i", "4" }, + }, }, format_on_save = { - -- These options will be passed to conform.format() timeout_ms = 500, lsp_format = "fallback", }, @@ -374,9 +320,6 @@ require("lazy").setup({ "L3MON4D3/LuaSnip", version = "2.*", build = (function() - -- Build Step is needed for regex support in snippets. - -- This step is not supported in many windows environments. - -- Remove the below condition to re-enable on windows. if vim.fn.has("win32") == 1 or vim.fn.executable("make") == 0 then return end @@ -399,8 +342,6 @@ require("lazy").setup({ }, completion = { - -- By default, you may press `` to show the documentation. - -- Optionally, set `auto_show = true` to show the documentation after a delay. documentation = { auto_show = false, auto_show_delay_ms = 500 }, }, @@ -412,10 +353,7 @@ require("lazy").setup({ }, snippets = { preset = "luasnip" }, - fuzzy = { implementation = "prefer_rust_with_warning" }, - - -- Shows a signature help window while you type arguments for a function signature = { enabled = true }, }, }, @@ -443,9 +381,6 @@ require("lazy").setup({ auto_install = true, highlight = { enable = true, - -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules. - -- If you are experiencing weird indenting issues, add the language to - -- the list of additional_vim_regex_highlighting and disabled languages for indent. additional_vim_regex_highlighting = { "ruby" }, }, indent = { enable = true, disable = { "ruby" } }, diff --git a/update_arch.sh b/update_arch.sh index ae333fd..214d22c 100755 --- a/update_arch.sh +++ b/update_arch.sh @@ -252,7 +252,6 @@ if [ "${ROLES[TERMINAL]}" == "yes" ]; then mkdir -p ~/.local/bin ln -sf ~/linuxbox/tmux.conf ~/.tmux.conf - ln -sf ~/linuxbox/clang-format ~/.clang-format ln -sf ~/linuxbox/luacheckrc ~/.luacheckrc ln -sf ~/linuxbox/config/starship.toml ~/.config/starship.toml ln -sf ~/linuxbox/config/nvim/init.lua ~/.config/nvim/init.lua diff --git a/update_ubuntu.sh b/update_ubuntu.sh index bc74d4b..d28f853 100755 --- a/update_ubuntu.sh +++ b/update_ubuntu.sh @@ -1,5 +1,6 @@ #!/bin/bash set -e +sudo -v if [ -f /etc/os-release ]; then . /etc/os-release @@ -73,6 +74,21 @@ fi printf -- '\033[33m Installing system packages\n\033[37m' sudo apt install -y gawk imagemagick gpg ninja-build gettext cmake unzip curl build-essential libssl-dev libffi-dev file tmux libudev-dev pkg-config locales btop ncdu ranger +# Install brew +printf -- '\033[33m Installing Homebrew\n\033[37m' +sudo apt-get install -y -qq build-essential curl file git + +export NONINTERACTIVE=1 +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" +BREW_PREFIX="/home/linuxbrew/.linuxbrew" +if [ -d "$BREW_PREFIX" ]; then + eval "$("$BREW_PREFIX"/bin/brew shellenv)" +else + echo "[!] Homebrew install failed or brew not found at expected location." + exit 1 +fi +brew --version >/dev/null && echo "[✓] Homebrew installed successfully." + # Setup locals printf -- '\033[33m Setup locals\n\033[37m' sudo locale-gen "en_US.UTF-8" @@ -271,6 +287,18 @@ cargo install zoxide --locked printf -- '\033[33m Installing starship\n\033[37m' cargo install starship --locked +# Install LSP servers +printf -- '\033[33m Installing LSP servers\n\033[37m' +rustup component add rust-analyzer clippy rustfmt +sudo npm i -g bash-language-server pyright +sudo npm install --save-dev prettier +sudo apt install -y shfmt clangd clang-format +pipx install black +pipx install isort +pipx install mdformat +brew install lua-language-server marksman +cargo install stylua + # *** Desktop applications *** if [ "$WSL" == "no" ]; then printf -- '\033[32m *** Desktop applications ***\n\033[37m' @@ -378,10 +406,6 @@ fi printf -- '\033[33m Symlinking tmux config\n\033[37m' ln -sf ~/linuxbox/tmux.conf ~/.tmux.conf -# Symlink clang-format config -printf -- '\033[33m Symlinking clang-format config\n\033[37m' -ln -sf ~/linuxbox/clang-format ~/.clang-format - # Symlink lazygit config printf -- '\033[33m Symlinking lazygit config\n\033[37m' mkdir -p ~/.config/lazygit