diff --git a/ansible/tasks/link_files.yml b/ansible/tasks/link_files.yml index 208c7a54..f02572c9 100644 --- a/ansible/tasks/link_files.yml +++ b/ansible/tasks/link_files.yml @@ -18,7 +18,7 @@ - { src: "fish/fish_plugins", dest: ".config/fish/fish_plugins" } - { src: "fish/completions/fish_gh_completion.fish", - dest: ".config/fish/fish_gh_completion", + dest: ".config/fish/completions/fish_gh_completion.fish", } - { src: "atuin/config.toml", dest: ".config/atuin/config.toml" } - { src: "lazygit/config.yml", dest: ".config/lazygit/config.yml" } @@ -28,7 +28,6 @@ # Scripts for working with data - { src: "parquet/csv_to_parquet.py", dest: ".bin/csv_to_parquet" } - { src: "parquet/parquet_to_csv.py", dest: ".bin/parquet_to_csv" } - - { src: "yml/format_yml.py", dest: ".bin/format_yml" } # Misc. scripts and config - { src: "zettel/today.sh", dest: ".bin/today" } diff --git a/ansible/tasks/neovim.yml b/ansible/tasks/neovim.yml index d663f399..76f91ae3 100644 --- a/ansible/tasks/neovim.yml +++ b/ansible/tasks/neovim.yml @@ -13,7 +13,6 @@ - pynvim - pyright - ruff - - ruff-lsp - yamllint - name: Remove existing ftplugin directory if it exists (to allow symlinking) diff --git a/bash/bashrc b/bash/bashrc index 135f70d1..2da82bac 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -88,50 +88,52 @@ export GIT_COMMITTER_EMAIL=$EMAIL export PAGER='less' export LESS='-R -M --shift 5' -export JAVA_HOME=$(/usr/libexec/java_home -v 18) +# Java home (only set if java_home exists and returns a valid path) +if [ -x /usr/libexec/java_home ]; then + _java_home=$(/usr/libexec/java_home 2>/dev/null) + if [ -n "$_java_home" ]; then + export JAVA_HOME="$_java_home" + fi + unset _java_home +fi # language export LC_ALL='en_GB.UTF-8' export LANG='en_GB.UTF-8' -export LC_CTYPE=C -export DISPLAY=:0 ################################################################### # -# Shell history improvements +# Bash-specific settings (skipped when sourced from zsh) # ################################################################### -export HISTSIZE=50000 -export HISTFILESIZE=100000 -export HISTCONTROL=ignoredups:erasedups -export HISTTIMEFORMAT="[%F %T] " -shopt -s histappend # Append to history, don't overwrite - -################################################################### -# -# Modern shell tool initialization -# -################################################################### - -# Initialize starship prompt -if command -v starship &>/dev/null; then - eval "$(starship init bash)" -fi - -# Initialize zoxide for smart directory navigation -if command -v zoxide &>/dev/null; then - eval "$(zoxide init bash)" -fi - -# Initialize atuin for enhanced shell history -if command -v atuin &>/dev/null; then - eval "$(atuin init bash)" -fi - -# Initialize mise for runtime version management -if command -v mise &>/dev/null; then - eval "$(mise activate bash)" +if [ -n "$BASH_VERSION" ]; then + # Shell history improvements + export HISTSIZE=50000 + export HISTFILESIZE=100000 + export HISTCONTROL=ignoredups:erasedups + export HISTTIMEFORMAT="[%F %T] " + shopt -s histappend # Append to history, don't overwrite + + # Initialize starship prompt + if command -v starship &>/dev/null; then + eval "$(starship init bash)" + fi + + # Initialize zoxide for smart directory navigation + if command -v zoxide &>/dev/null; then + eval "$(zoxide init bash)" + fi + + # Initialize atuin for enhanced shell history + if command -v atuin &>/dev/null; then + eval "$(atuin init bash)" + fi + + # Initialize mise for runtime version management + if command -v mise &>/dev/null; then + eval "$(mise activate bash)" + fi fi @@ -145,27 +147,26 @@ fi # For full GNU environment, add to PATH instead: # export PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH" -if command -v brew >/dev/null 2>&1; then - brew_prefix=$(brew --prefix) - +# Check for coreutils by looking for a binary instead of running brew --prefix +if [ -x /opt/homebrew/bin/gcat ]; then + brew_prefix=/opt/homebrew + # Core file operations alias cp="$brew_prefix/bin/gcp" alias mv="$brew_prefix/bin/gmv" alias rm="$brew_prefix/bin/grm" - + # Text processing alias sed="$brew_prefix/bin/gsed" alias awk="$brew_prefix/bin/gawk" alias grep="$brew_prefix/bin/ggrep" - + # Date/time alias date="$brew_prefix/bin/gdate" - + # System info alias stat="$brew_prefix/bin/gstat" alias readlink="$brew_prefix/bin/greadlink" - - # Note: ls/cat/find are overridden with modern alternatives (eza/bat/fd) in aliases section above fi # Source local overrides if they exist diff --git a/fish/config.fish b/fish/config.fish index 83e0ed7e..e30e007a 100644 --- a/fish/config.fish +++ b/fish/config.fish @@ -1,5 +1,3 @@ -#!/usr/local/bin/fish - # --- XDG Base Directory Specification --- set -x XDG_CONFIG_HOME $HOME/.config set -x XDG_DATA_HOME $HOME/.local/share @@ -88,6 +86,7 @@ fish_add_path $HOMEBREW_BIN fish_add_path $DOTFILES_BIN fish_add_path $USER_BIN fish_add_path $LOCAL_BIN +fish_add_path $PYTHON_BIN # FZF configuration with better preview set -x FZF_DEFAULT_COMMAND 'fd --type f --hidden --follow --exclude .git' @@ -110,16 +109,17 @@ set -x GIT_COMMITTER_EMAIL $EMAIL set -x PAGER less set -x LESS '-R -M --shift 5' -# Java home - commented out as it adds startup delay -# if test -x /usr/libexec/java_home -# set -x JAVA_HOME (/usr/libexec/java_home -v 18 2>/dev/null) -# end +# Java home (only set if java_home exists and returns a valid path) +if test -x /usr/libexec/java_home + set -l java_home (/usr/libexec/java_home 2>/dev/null) + if test -n "$java_home" + set -gx JAVA_HOME $java_home + end +end # Language settings set -x LC_ALL 'en_GB.UTF-8' set -x LANG 'en_GB.UTF-8' -set -x LC_CTYPE C -set -x DISPLAY :0 ################################################################### # @@ -151,9 +151,9 @@ end # ################################################################### -# Improve the ssh function to use mosh only when appropriate +# Use mosh when connecting to a simple hostname with no extra arguments function ssh - if test (count $argv) -gt 0; and string match -qr '^[a-zA-Z0-9._-]+$' -- $argv[1] + if test (count $argv) -eq 1; and string match -qr '^[a-zA-Z0-9._-]+$' -- $argv[1] mosh $argv else command ssh $argv @@ -166,7 +166,7 @@ end # Cat the contents of a file into the clipboard function pbcat - cat $argv[1] | pbcopy + command cat $argv[1] | pbcopy end # Use ctrl+s to fzf search the current directory @@ -182,21 +182,19 @@ bind \cg wiki_file # Search for all files *containing* text function wt - set dir (pwd) - cd ~/Dropbox/wiki/zettel/; and rg $argv[1] --files-with-matches \ - | fzf --preview 'bat --style=numbers --color=always {}' --preview-window="right:65%" --height="70%" \ - | xargs -I {} -o nvim ~/Dropbox/wiki/zettel/{} - cd $dir + rg $argv[1] --files-with-matches ~/Dropbox/wiki/zettel/ \ + | fzf --preview "bat --style=numbers --color=always {}" --preview-window="right:65%" --height="70%" \ + | xargs -I {} -o nvim {} end # LESS colors for man pages -set -Ux LESS_TERMCAP_us \e\[1\;32m -set -Ux LESS_TERMCAP_md \e\[1\;31m -set -Ux LESS_TERMCAP_mb \e\[01\;31m -set -Ux LESS_TERMCAP_me \e\[0m -set -Ux LESS_TERMCAP_se \e\[0m -set -Ux LESS_TERMCAP_so \e\[01\;44\;33m -set -Ux LESS_TERMCAP_ue \e\[0m +set -gx LESS_TERMCAP_us \e\[1\;32m +set -gx LESS_TERMCAP_md \e\[1\;31m +set -gx LESS_TERMCAP_mb \e\[01\;31m +set -gx LESS_TERMCAP_me \e\[0m +set -gx LESS_TERMCAP_se \e\[0m +set -gx LESS_TERMCAP_so \e\[01\;44\;33m +set -gx LESS_TERMCAP_ue \e\[0m # Source local environment variables if they exist if test -f ~/.local/environment.fish diff --git a/git/clean_branches.sh b/git/clean_branches.sh index 7232c4ec..0fa1d717 100755 --- a/git/clean_branches.sh +++ b/git/clean_branches.sh @@ -1,48 +1,48 @@ #!/bin/bash # -# Remove any local branches that don't exist on the origin +# Remove local branches that have been merged and no longer exist on the remote. +# Protects main, master, and the currently checked-out branch. # +# Usage: clean_branches.sh [-f] +# -f Force delete unmerged branches that no longer exist on remote set -o errexit +set -o nounset -#!/bin/bash - -# Check if Git is installed -if ! git --version >/dev/null 2>&1; then - echo "Error: Git is not installed. Please install Git and try again." - exit 1 -fi - -# Check if the current directory is a Git repository if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then - echo "Error: The current directory is not a Git repository. Please navigate to a Git repository and try again." + echo "Error: not inside a git repository." exit 1 fi -# Check for the -f flag force_delete=false -if [[ "$1" == "-f" ]]; then +if [[ "${1:-}" == "-f" ]]; then force_delete=true fi -# Fetch the latest changes from the remote repository and prune deleted branches +# Fetch and prune remote tracking branches git fetch --prune -# Get a list of merged branches and filter out the branches that no longer exist on the origin -merged_branches=$(git branch --merged | grep -v "\*" | grep -v "^\s*master" | grep -v "^\s*main" | xargs -n 1 git branch -r --contains | sed 's/origin\///' | uniq) +current_branch=$(git symbolic-ref --short HEAD) -# Iterate through each local branch and check if it exists in the list of merged branches -for branch in $(git for-each-ref --format='%(refname:short)' refs/heads); do - if ! echo "$merged_branches" | grep -q "^$branch$"; then - if [ "$force_delete" = true ]; then - echo "Force deleting branch '$branch' as it either doesn't exist on the origin or isn't merged." - git branch -D "$branch" 2>/dev/null || echo "Error: Could not delete branch '$branch'." - else - echo "Skipping branch '$branch' as it either doesn't exist on the origin or isn't merged." - fi - else - echo "Deleting branch '$branch' as it is merged and doesn't exist on the origin." - git branch -d "$branch" 2>/dev/null || echo "Error: Could not delete branch '$branch'." +# Delete local branches that have been merged into the current branch +git branch --merged | while read -r branch; do + branch=$(echo "$branch" | tr -d '* ') + # Skip protected branches + if [[ "$branch" == "main" || "$branch" == "master" || "$branch" == "$current_branch" ]]; then + continue fi + echo "Deleting merged branch '$branch'" + git branch -d "$branch" 2>/dev/null || echo " Could not delete '$branch'" done +# Optionally force-delete branches whose remote tracking branch is gone +if [ "$force_delete" = true ]; then + git branch -vv | grep ': gone]' | while read -r line; do + branch=$(echo "$line" | awk '{print $1}') + if [[ "$branch" == "main" || "$branch" == "master" || "$branch" == "$current_branch" ]]; then + continue + fi + echo "Force deleting gone branch '$branch'" + git branch -D "$branch" 2>/dev/null || echo " Could not delete '$branch'" + done +fi diff --git a/git/gitconfig b/git/gitconfig index f562442a..508f0e02 100644 --- a/git/gitconfig +++ b/git/gitconfig @@ -47,9 +47,9 @@ lst = diff HEAD^..HEAD # Show changes in the last commit # Branch operations - sw = checkout # Switch branches - swb = checkout -b # Create and switch to a branch - pd = checkout - # Jump to previous branch + sw = switch # Switch branches + swb = switch -c # Create and switch to a branch + pd = switch - # Jump to previous branch b = branch # List branches bd = branch -d # Delete branch @@ -90,6 +90,7 @@ excludesfile = ~/.gitignore autocrlf = input whitespace = trailing-space,space-before-tab + pager = delta [branch] autosetupmerge = true sort = -committerdate @@ -122,11 +123,6 @@ [push] default = current autoSetupRemote = true -[ghi] - token = !security find-internet-password -a michaelbarton -s github.com -l 'ghi token' -w - -[core] - pager = delta [interactive] diffFilter = delta --color-only diff --git a/gitignore b/gitignore index 468b5bd0..83275666 100644 --- a/gitignore +++ b/gitignore @@ -89,7 +89,6 @@ htmlcov/ # Rust target/ -Cargo.lock # Go *.test @@ -103,7 +102,6 @@ Cargo.lock node_modules/ .npm/ .yarn/ -package-lock.json # Optional: remove if you want to track this # Python .venv/ diff --git a/lein/profiles.clj b/lein/profiles.clj deleted file mode 100644 index db8e8237..00000000 --- a/lein/profiles.clj +++ /dev/null @@ -1,15 +0,0 @@ -{:user - {:plugins [[cider/cider-nrepl "0.8.2"] - [com.jakemccrary/lein-test-refresh "0.11.0"] - [jonase/eastwood "0.2.3"] - [lein-ancient "0.6.8"]] - - :dependencies [[clj-stacktrace "0.2.8"] - [spyscope "0.1.5"]] - - :injections [(let [orig (ns-resolve (doto 'clojure.stacktrace require) - 'print-cause-trace) - new (ns-resolve (doto 'clj-stacktrace.repl require) - 'pst)] - (alter-var-root orig (constantly (deref new)))) - (require 'spyscope.core)]}} diff --git a/markdown/md2docx.sh b/markdown/md2docx.sh index 51901084..bcb9b4a1 100755 --- a/markdown/md2docx.sh +++ b/markdown/md2docx.sh @@ -9,4 +9,4 @@ IN_FILE=$1 FILENAME=$(basename -- "$IN_FILE") FILENAME_NOEXT="${FILENAME%.*}" -pandoc -o ${FILENAME_NOEXT}.docx -f markdown -t docx $IN_FILE +pandoc -o "${FILENAME_NOEXT}.docx" -f markdown -t docx "$IN_FILE" diff --git a/markdown/md2pdf.sh b/markdown/md2pdf.sh index 89afb0e2..6956744a 100755 --- a/markdown/md2pdf.sh +++ b/markdown/md2pdf.sh @@ -9,4 +9,4 @@ IN_FILE=$1 FILENAME=$(basename -- "$IN_FILE") FILENAME_NOEXT="${FILENAME%.*}" -pandoc -o ${FILENAME_NOEXT}.pdf -f markdown -t pdf $IN_FILE +pandoc -o "${FILENAME_NOEXT}.pdf" -f markdown -t pdf "$IN_FILE" diff --git a/mutt/muttrc b/mutt/muttrc index 74c3c5d0..e3f8d978 100644 --- a/mutt/muttrc +++ b/mutt/muttrc @@ -5,7 +5,7 @@ set mbox_type = Maildir my_hdr X-URL: http://www.michaelbarton.me.uk -set editor = "vim -f" +set editor = "nvim" set mail_check = 60 set timeout = 60 set header_cache=~/.mutt/cache/headers diff --git a/nvim/.neoconf.json b/nvim/.neoconf.json index 7c480874..1d4389e6 100644 --- a/nvim/.neoconf.json +++ b/nvim/.neoconf.json @@ -1,10 +1,4 @@ { - "neodev": { - "library": { - "enabled": true, - "plugins": true - } - }, "neoconf": { "plugins": { "lua_ls": { diff --git a/nvim/lua/config/lazy.lua b/nvim/lua/config/lazy.lua index beeed76b..d4fcb0e2 100644 --- a/nvim/lua/config/lazy.lua +++ b/nvim/lua/config/lazy.lua @@ -38,6 +38,7 @@ require("lazy").setup({ -- Import LazyVim extras - Editor utilities { import = "lazyvim.plugins.extras.editor.telescope" }, + { import = "lazyvim.plugins.extras.editor.mini-move" }, { import = "lazyvim.plugins.extras.util.project" }, -- import/override with your plugins diff --git a/nvim/lua/plugins/todo-comments.lua b/nvim/lua/plugins/todo-comments.lua deleted file mode 100644 index f93cdb26..00000000 --- a/nvim/lua/plugins/todo-comments.lua +++ /dev/null @@ -1,22 +0,0 @@ --- Todo comments highlighting -return { - "folke/todo-comments.nvim", - dependencies = { "nvim-lua/plenary.nvim" }, - event = "VeryLazy", - opts = { - signs = true, - keywords = { - FIX = { icon = " ", color = "error", alt = { "FIXME", "BUG", "FIXIT", "ISSUE" } }, - TODO = { icon = " ", color = "info" }, - HACK = { icon = " ", color = "warning" }, - WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX" } }, - PERF = { icon = " ", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } }, - NOTE = { icon = " ", color = "hint", alt = { "INFO" } }, - }, - }, - keys = { - { "xt", "TodoTrouble", desc = "Todo (Trouble)" }, - { "xT", "TodoTrouble keywords=TODO,FIX,FIXME", desc = "Todo/Fix/Fixme (Trouble)" }, - { "st", "TodoTelescope", desc = "Todo" }, - }, -} \ No newline at end of file diff --git a/nvim/lua/plugins/trouble.lua b/nvim/lua/plugins/trouble.lua index 7979b760..2ac7c182 100644 --- a/nvim/lua/plugins/trouble.lua +++ b/nvim/lua/plugins/trouble.lua @@ -1,14 +1,14 @@ --- Trouble - better diagnostics list +-- Trouble - better diagnostics list (v3 API) return { "folke/trouble.nvim", - cmd = { "TroubleToggle", "Trouble" }, + cmd = { "Trouble" }, opts = { use_diagnostic_signs = true, }, keys = { - { "xx", "TroubleToggle document_diagnostics", desc = "Document Diagnostics (Trouble)" }, - { "xX", "TroubleToggle workspace_diagnostics", desc = "Workspace Diagnostics (Trouble)" }, - { "xL", "TroubleToggle loclist", desc = "Location List (Trouble)" }, - { "xQ", "TroubleToggle quickfix", desc = "Quickfix List (Trouble)" }, + { "xx", "Trouble diagnostics toggle filter.buf=0", desc = "Document Diagnostics (Trouble)" }, + { "xX", "Trouble diagnostics toggle", desc = "Workspace Diagnostics (Trouble)" }, + { "xL", "Trouble loclist toggle", desc = "Location List (Trouble)" }, + { "xQ", "Trouble qflist toggle", desc = "Quickfix List (Trouble)" }, }, -} \ No newline at end of file +} diff --git a/offlineimap/offlineimap.py b/offlineimap/offlineimap.py index 6bc39ea5..4e8b4201 100644 --- a/offlineimap/offlineimap.py +++ b/offlineimap/offlineimap.py @@ -1,6 +1,4 @@ import subprocess -import re -import sys def get_keychain_pass(account): @@ -8,7 +6,9 @@ def get_keychain_pass(account): process = subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE) process.wait() if process.returncode != 0: - raise RuntimeError("Error running command: \n".format(process.stderr.read().decode())) + raise RuntimeError( + "Error running command: {}".format(process.stderr.read().decode()) + ) password_block = process.stdout.read().decode().strip() if password_block: @@ -19,5 +19,5 @@ def get_keychain_pass(account): def get_keyring_pass(key, value): - command = "secret-tool lookup {} {}".format(key, value) - return commands.getoutput(command).strip() + command = ["secret-tool", "lookup", key, value] + return subprocess.check_output(command).decode().strip() diff --git a/parquet/csv_to_parquet.py b/parquet/csv_to_parquet.py index 2d2302de..152607f9 100755 --- a/parquet/csv_to_parquet.py +++ b/parquet/csv_to_parquet.py @@ -12,11 +12,11 @@ import pandas import sys -IN_FILE, OUT_FILE = sys.argv[1], sys.argv[2] - -if not OUT_FILE: - print("Output file argument required.") +if len(sys.argv) != 3: + print("Usage: csv_to_parquet ") exit(1) +IN_FILE, OUT_FILE = sys.argv[1], sys.argv[2] + data = pandas.read_csv(IN_FILE) data.to_parquet(OUT_FILE, index=False) diff --git a/wgetrc b/wgetrc index 22ba51ad..20840bce 100644 --- a/wgetrc +++ b/wgetrc @@ -1 +1 @@ -header = Contact: Michael Barton +header = Contact: Michael Barton