mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-01-27 23:45:31 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ad1f5c4d0 | |||
| ac0aa1fbc0 | |||
| e8c6794ff6 | |||
| 4de9a649f0 | |||
|
|
e7f115680e | ||
| f3b4551d0c | |||
| 64725c57dc | |||
| b32ee414e3 | |||
|
|
6ea7807718 | ||
| 6a776bd3dd | |||
| 6ffe581326 | |||
| 5d476e8eed | |||
|
|
bf84c67f08 | ||
| 9cb400dd3f | |||
| fce649619a | |||
| 8b0148e468 | |||
| 9cb27eb9dc | |||
| f1ed88a98e | |||
| ec35f1cb1e | |||
| dab8504cfd | |||
| 0f9a76e36f | |||
|
|
97244d5287 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -45,3 +45,6 @@ config/fish/completions/asdf.fish
|
||||
config/vim/.netrwhist
|
||||
config/vim/extra/*
|
||||
config/gh/hosts.yml
|
||||
dependency-check-report.html
|
||||
local/bin/yabai
|
||||
local/man/yabai.1
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -80,3 +80,6 @@
|
||||
shallow = true
|
||||
ignore = dirty
|
||||
|
||||
[submodule "tmux/tmux-resurrect"]
|
||||
path = config/tmux/plugins/tmux-resurrect
|
||||
url = https://github.com/tmux-plugins/tmux-resurrect.git
|
||||
|
||||
@@ -49,7 +49,7 @@ repos:
|
||||
- id: actionlint
|
||||
|
||||
- repo: https://github.com/renovatebot/pre-commit-hooks
|
||||
rev: 39.213.4
|
||||
rev: 39.240.1
|
||||
hooks:
|
||||
- id: renovate-config-validator
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
3.13.2
|
||||
3.13.3
|
||||
|
||||
@@ -26,6 +26,8 @@ git submodule add --name tmux/tmux-continuum \
|
||||
-f https://github.com/tmux-plugins/tmux-continuum config/tmux/plugins/tmux-continuum
|
||||
git submodule add --name tmux/tmux-mode-indicator \
|
||||
-f https://github.com/MunifTanjim/tmux-mode-indicator.git config/tmux/plugins/tmux-mode-indicator
|
||||
git submodule add --name tmux/tmux-resurrect \
|
||||
-f https://github.com/tmux-plugins/tmux-resurrect.git config/tmux/plugins/tmux-resurrect
|
||||
git submodule add --name tmux/tmux-sensible \
|
||||
-f https://github.com/tmux-plugins/tmux-sensible.git config/tmux/plugins/tmux-sensible
|
||||
git submodule add --name tmux/tmux-sessionist \
|
||||
@@ -55,7 +57,6 @@ folders=(
|
||||
"config/tmux/plugins/tpm"
|
||||
"config/tmux/plugins/tmux"
|
||||
"config/tmux/plugins/tmux-menus"
|
||||
"config/tmux/plugins/tmux-resurrect"
|
||||
"tools/dotbot-crontab"
|
||||
"tools/dotbot-snap"
|
||||
"config/nvim-kickstart"
|
||||
|
||||
235
config/fish/completions/docker.fish
Executable file
235
config/fish/completions/docker.fish
Executable file
@@ -0,0 +1,235 @@
|
||||
# fish completion for docker -*- shell-script -*-
|
||||
|
||||
function __docker_debug
|
||||
set -l file "$BASH_COMP_DEBUG_FILE"
|
||||
if test -n "$file"
|
||||
echo "$argv" >> $file
|
||||
end
|
||||
end
|
||||
|
||||
function __docker_perform_completion
|
||||
__docker_debug "Starting __docker_perform_completion"
|
||||
|
||||
# Extract all args except the last one
|
||||
set -l args (commandline -opc)
|
||||
# Extract the last arg and escape it in case it is a space
|
||||
set -l lastArg (string escape -- (commandline -ct))
|
||||
|
||||
__docker_debug "args: $args"
|
||||
__docker_debug "last arg: $lastArg"
|
||||
|
||||
# Disable ActiveHelp which is not supported for fish shell
|
||||
set -l requestComp "DOCKER_ACTIVE_HELP=0 $args[1] __complete $args[2..-1] $lastArg"
|
||||
|
||||
__docker_debug "Calling $requestComp"
|
||||
set -l results (eval $requestComp 2> /dev/null)
|
||||
|
||||
# Some programs may output extra empty lines after the directive.
|
||||
# Let's ignore them or else it will break completion.
|
||||
# Ref: https://github.com/spf13/cobra/issues/1279
|
||||
for line in $results[-1..1]
|
||||
if test (string trim -- $line) = ""
|
||||
# Found an empty line, remove it
|
||||
set results $results[1..-2]
|
||||
else
|
||||
# Found non-empty line, we have our proper output
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
set -l comps $results[1..-2]
|
||||
set -l directiveLine $results[-1]
|
||||
|
||||
# For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)
|
||||
# completions must be prefixed with the flag
|
||||
set -l flagPrefix (string match -r -- '-.*=' "$lastArg")
|
||||
|
||||
__docker_debug "Comps: $comps"
|
||||
__docker_debug "DirectiveLine: $directiveLine"
|
||||
__docker_debug "flagPrefix: $flagPrefix"
|
||||
|
||||
for comp in $comps
|
||||
printf "%s%s\n" "$flagPrefix" "$comp"
|
||||
end
|
||||
|
||||
printf "%s\n" "$directiveLine"
|
||||
end
|
||||
|
||||
# this function limits calls to __docker_perform_completion, by caching the result behind $__docker_perform_completion_once_result
|
||||
function __docker_perform_completion_once
|
||||
__docker_debug "Starting __docker_perform_completion_once"
|
||||
|
||||
if test -n "$__docker_perform_completion_once_result"
|
||||
__docker_debug "Seems like a valid result already exists, skipping __docker_perform_completion"
|
||||
return 0
|
||||
end
|
||||
|
||||
set --global __docker_perform_completion_once_result (__docker_perform_completion)
|
||||
if test -z "$__docker_perform_completion_once_result"
|
||||
__docker_debug "No completions, probably due to a failure"
|
||||
return 1
|
||||
end
|
||||
|
||||
__docker_debug "Performed completions and set __docker_perform_completion_once_result"
|
||||
return 0
|
||||
end
|
||||
|
||||
# this function is used to clear the $__docker_perform_completion_once_result variable after completions are run
|
||||
function __docker_clear_perform_completion_once_result
|
||||
__docker_debug ""
|
||||
__docker_debug "========= clearing previously set __docker_perform_completion_once_result variable =========="
|
||||
set --erase __docker_perform_completion_once_result
|
||||
__docker_debug "Successfully erased the variable __docker_perform_completion_once_result"
|
||||
end
|
||||
|
||||
function __docker_requires_order_preservation
|
||||
__docker_debug ""
|
||||
__docker_debug "========= checking if order preservation is required =========="
|
||||
|
||||
__docker_perform_completion_once
|
||||
if test -z "$__docker_perform_completion_once_result"
|
||||
__docker_debug "Error determining if order preservation is required"
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l directive (string sub --start 2 $__docker_perform_completion_once_result[-1])
|
||||
__docker_debug "Directive is: $directive"
|
||||
|
||||
set -l shellCompDirectiveKeepOrder 32
|
||||
set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2)
|
||||
__docker_debug "Keeporder is: $keeporder"
|
||||
|
||||
if test $keeporder -ne 0
|
||||
__docker_debug "This does require order preservation"
|
||||
return 0
|
||||
end
|
||||
|
||||
__docker_debug "This doesn't require order preservation"
|
||||
return 1
|
||||
end
|
||||
|
||||
|
||||
# This function does two things:
|
||||
# - Obtain the completions and store them in the global __docker_comp_results
|
||||
# - Return false if file completion should be performed
|
||||
function __docker_prepare_completions
|
||||
__docker_debug ""
|
||||
__docker_debug "========= starting completion logic =========="
|
||||
|
||||
# Start fresh
|
||||
set --erase __docker_comp_results
|
||||
|
||||
__docker_perform_completion_once
|
||||
__docker_debug "Completion results: $__docker_perform_completion_once_result"
|
||||
|
||||
if test -z "$__docker_perform_completion_once_result"
|
||||
__docker_debug "No completion, probably due to a failure"
|
||||
# Might as well do file completion, in case it helps
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l directive (string sub --start 2 $__docker_perform_completion_once_result[-1])
|
||||
set --global __docker_comp_results $__docker_perform_completion_once_result[1..-2]
|
||||
|
||||
__docker_debug "Completions are: $__docker_comp_results"
|
||||
__docker_debug "Directive is: $directive"
|
||||
|
||||
set -l shellCompDirectiveError 1
|
||||
set -l shellCompDirectiveNoSpace 2
|
||||
set -l shellCompDirectiveNoFileComp 4
|
||||
set -l shellCompDirectiveFilterFileExt 8
|
||||
set -l shellCompDirectiveFilterDirs 16
|
||||
|
||||
if test -z "$directive"
|
||||
set directive 0
|
||||
end
|
||||
|
||||
set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)
|
||||
if test $compErr -eq 1
|
||||
__docker_debug "Received error directive: aborting."
|
||||
# Might as well do file completion, in case it helps
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)
|
||||
set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)
|
||||
if test $filefilter -eq 1; or test $dirfilter -eq 1
|
||||
__docker_debug "File extension filtering or directory filtering not supported"
|
||||
# Do full file completion instead
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)
|
||||
set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)
|
||||
|
||||
__docker_debug "nospace: $nospace, nofiles: $nofiles"
|
||||
|
||||
# If we want to prevent a space, or if file completion is NOT disabled,
|
||||
# we need to count the number of valid completions.
|
||||
# To do so, we will filter on prefix as the completions we have received
|
||||
# may not already be filtered so as to allow fish to match on different
|
||||
# criteria than the prefix.
|
||||
if test $nospace -ne 0; or test $nofiles -eq 0
|
||||
set -l prefix (commandline -t | string escape --style=regex)
|
||||
__docker_debug "prefix: $prefix"
|
||||
|
||||
set -l completions (string match -r -- "^$prefix.*" $__docker_comp_results)
|
||||
set --global __docker_comp_results $completions
|
||||
__docker_debug "Filtered completions are: $__docker_comp_results"
|
||||
|
||||
# Important not to quote the variable for count to work
|
||||
set -l numComps (count $__docker_comp_results)
|
||||
__docker_debug "numComps: $numComps"
|
||||
|
||||
if test $numComps -eq 1; and test $nospace -ne 0
|
||||
# We must first split on \t to get rid of the descriptions to be
|
||||
# able to check what the actual completion will be.
|
||||
# We don't need descriptions anyway since there is only a single
|
||||
# real completion which the shell will expand immediately.
|
||||
set -l split (string split --max 1 \t $__docker_comp_results[1])
|
||||
|
||||
# Fish won't add a space if the completion ends with any
|
||||
# of the following characters: @=/:.,
|
||||
set -l lastChar (string sub -s -1 -- $split)
|
||||
if not string match -r -q "[@=/:.,]" -- "$lastChar"
|
||||
# In other cases, to support the "nospace" directive we trick the shell
|
||||
# by outputting an extra, longer completion.
|
||||
__docker_debug "Adding second completion to perform nospace directive"
|
||||
set --global __docker_comp_results $split[1] $split[1].
|
||||
__docker_debug "Completions are now: $__docker_comp_results"
|
||||
end
|
||||
end
|
||||
|
||||
if test $numComps -eq 0; and test $nofiles -eq 0
|
||||
# To be consistent with bash and zsh, we only trigger file
|
||||
# completion when there are no other completions
|
||||
__docker_debug "Requesting file completion"
|
||||
return 1
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves
|
||||
# so we can properly delete any completions provided by another script.
|
||||
# Only do this if the program can be found, or else fish may print some errors; besides,
|
||||
# the existing completions will only be loaded if the program can be found.
|
||||
if type -q "docker"
|
||||
# The space after the program name is essential to trigger completion for the program
|
||||
# and not completion of the program name itself.
|
||||
# Also, we use '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.
|
||||
complete --do-complete "docker " > /dev/null 2>&1
|
||||
end
|
||||
|
||||
# Remove any pre-existing completions for the program since we will be handling all of them.
|
||||
complete -c docker -e
|
||||
|
||||
# this will get called after the two calls below and clear the $__docker_perform_completion_once_result global
|
||||
complete -c docker -n '__docker_clear_perform_completion_once_result'
|
||||
# The call to __docker_prepare_completions will setup __docker_comp_results
|
||||
# which provides the program's completion choices.
|
||||
# If this doesn't require order preservation, we don't use the -k flag
|
||||
complete -c docker -n 'not __docker_requires_order_preservation && __docker_prepare_completions' -f -a '$__docker_comp_results'
|
||||
# otherwise we use the -k flag
|
||||
complete -k -c docker -n '__docker_requires_order_preservation && __docker_prepare_completions' -f -a '$__docker_comp_results'
|
||||
@@ -9,17 +9,21 @@ test -e "$HOME/.config/fish/exports.fish" &&
|
||||
source "$HOME/.config/fish/exports.fish"
|
||||
|
||||
if status is-interactive
|
||||
# Commands to run in interactive sessions can go here
|
||||
# Commands to run in interactive shell
|
||||
|
||||
# Start tmux if not already running and not in SSH
|
||||
open-tmux # defined in functions/open-tmux.fish
|
||||
# version manager initializers
|
||||
type -q rbenv; and source (rbenv init -|psub)
|
||||
type -q pyenv; and source (pyenv init -|psub)
|
||||
type -q pyenv; and source (pyenv virtualenv-init -)
|
||||
type -q goenv; and source (goenv init -|psub)
|
||||
# type -q fnm; and fnm env --use-on-cd --shell fish | source
|
||||
type -q load_nvm; and load_nvm > /dev/stderr
|
||||
|
||||
# Start tmux if not already running and not in SSH
|
||||
open-tmux # defined in functions/open-tmux.fish
|
||||
end
|
||||
|
||||
# Added by LM Studio CLI (lms)
|
||||
set -gx PATH $PATH $HOME/.lmstudio/bin
|
||||
|
||||
type -q rbenv; and source (rbenv init -|psub)
|
||||
type -q pyenv; and source (pyenv init -|psub)
|
||||
type -q goenv; and source (goenv init -|psub)
|
||||
type -q fnm; and fnm env --use-on-cd --shell fish | source
|
||||
|
||||
# vim: ft=fish ts=4 sw=4 et:
|
||||
|
||||
@@ -121,9 +121,6 @@ set -q OP_CACHE; or set -x OP_CACHE "$XDG_STATE_HOME/1password"
|
||||
set -q WORKON_HOME; or set -x WORKON_HOME "$XDG_DATA_HOME/virtualenvs"
|
||||
set -q PYENV_ROOT; or set -x PYENV_ROOT "$XDG_DATA_HOME/pyenv"
|
||||
fish_add_path "$PYENV_ROOT/bin"
|
||||
if x-have pyenv; and not functions -q pyenv
|
||||
status --is-interactive; and source (pyenv init - | psub)
|
||||
end
|
||||
|
||||
# Poetry configuration
|
||||
set -q POETRY_HOME; or set -x POETRY_HOME "$XDG_DATA_HOME/poetry"
|
||||
|
||||
16
config/fish/functions/load_nvm.fish
Normal file
16
config/fish/functions/load_nvm.fish
Normal file
@@ -0,0 +1,16 @@
|
||||
function load_nvm --on-variable="PWD"
|
||||
set -l default_node_version (nvm version default)
|
||||
set -l node_version (nvm version)
|
||||
set -l nvmrc_path (nvm_find_nvmrc)
|
||||
if test -n "$nvmrc_path"
|
||||
set -l nvmrc_node_version (nvm version (cat $nvmrc_path))
|
||||
if test "$nvmrc_node_version" = "N/A"
|
||||
nvm install (cat $nvmrc_path)
|
||||
else if test "$nvmrc_node_version" != "$node_version"
|
||||
nvm use $nvmrc_node_version
|
||||
end
|
||||
else if test "$node_version" != "$default_node_version"
|
||||
echo "Reverting to default Node version"
|
||||
nvm use default
|
||||
end
|
||||
end
|
||||
4
config/fish/functions/nvm.fish
Normal file
4
config/fish/functions/nvm.fish
Normal file
@@ -0,0 +1,4 @@
|
||||
function nvm
|
||||
bass source $NVM_DIR/nvm.sh --no-use ';' nvm $argv
|
||||
end
|
||||
|
||||
3
config/fish/functions/nvm_find_nvmrc.fish
Normal file
3
config/fish/functions/nvm_find_nvmrc.fish
Normal file
@@ -0,0 +1,3 @@
|
||||
function nvm_find_nvmrc
|
||||
bass source $NVM_DIR/nvm.sh --no-use ';' nvm_find_nvmrc
|
||||
end
|
||||
@@ -107,6 +107,10 @@ brew "choose-rust"
|
||||
brew "cmake"
|
||||
# Get a file from an HTTP, HTTPS or FTP server
|
||||
brew "curl"
|
||||
# OpenType text shaping engine
|
||||
brew "harfbuzz"
|
||||
# OWASP dependency-check
|
||||
brew "dependency-check"
|
||||
# Lightweight DNS forwarder and DHCP server
|
||||
brew "dnsmasq"
|
||||
# .NET Core
|
||||
@@ -121,8 +125,6 @@ brew "figlet"
|
||||
brew "fish"
|
||||
# Lock file during command
|
||||
brew "flock"
|
||||
# Fast and simple Node.js version manager
|
||||
brew "fnm"
|
||||
# Libraries to talk to Microsoft SQL Server and Sybase databases
|
||||
brew "freetds"
|
||||
# Monitor a directory for changes and run a shell command
|
||||
@@ -135,8 +137,6 @@ brew "gd"
|
||||
brew "gdu"
|
||||
# GitHub command-line tool
|
||||
brew "gh"
|
||||
# OpenType text shaping engine
|
||||
brew "harfbuzz"
|
||||
# Secure hashing function
|
||||
brew "libb2"
|
||||
# Framework for layout and rendering of i18n text
|
||||
@@ -193,6 +193,8 @@ brew "jq"
|
||||
brew "json-c"
|
||||
# Network authentication protocol
|
||||
brew "krb5"
|
||||
# Style and grammar checker
|
||||
brew "languagetool"
|
||||
# Tool to detect/remediate misconfig and security risks of GitHub/GitLab assets
|
||||
brew "legitify"
|
||||
# BSD-style licensed readline alternative
|
||||
@@ -230,7 +232,9 @@ brew "openldap"
|
||||
# ISO-C API and CLI for generating UUIDs
|
||||
brew "ossp-uuid"
|
||||
# General-purpose scripting language
|
||||
brew "php@8.2", link: true
|
||||
brew "php"
|
||||
# General-purpose scripting language
|
||||
brew "php@8.2"
|
||||
# General-purpose scripting language
|
||||
brew "php@8.3"
|
||||
# Pins GitHub Actions to full hashes and versions
|
||||
@@ -336,6 +340,8 @@ cask "jetbrains-toolbox"
|
||||
cask "keybase"
|
||||
# Kubernetes IDE
|
||||
cask "lens"
|
||||
# Neovim Client
|
||||
cask "neovide"
|
||||
# Reverse proxy, secure introspectable tunnels to localhost
|
||||
cask "ngrok"
|
||||
# Simple application that will prevent iTunes or Apple Music from launching
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"" Source your .vimrc
|
||||
source ~/.dotfiles/config/vim/vimrc
|
||||
source $HOME/.dotfiles/config/vim/vimrc
|
||||
|
||||
" https://github.com/ville6000/dotfiles/blob/main/vimrc
|
||||
" To get a list of Actions run `:actionlist `
|
||||
|
||||
@@ -26,6 +26,7 @@ g.loaded_java_provider = 0 -- Disable java provider
|
||||
-- Most of the good defaults are provided by `mini.basics`
|
||||
-- See: lua/plugins/mini.lua
|
||||
o.confirm = true -- Confirm before closing unsaved buffers
|
||||
o.dictionary = '/usr/share/dict/words' -- Add system dictionary
|
||||
o.ignorecase = true -- Ignore case in search patterns
|
||||
o.inccommand = 'split' -- Preview substitutions live, as you type!
|
||||
o.list = true -- Show invisible characters
|
||||
@@ -37,7 +38,7 @@ o.scrolloff = 8 -- Show context around cursor
|
||||
o.sidescrolloff = 8 -- Show context around cursor
|
||||
o.signcolumn = 'yes' -- Keep signcolumn on by default
|
||||
o.spell = true -- Enable spell checking
|
||||
o.spelllang = 'en_us' -- Set the spell checking language
|
||||
o.spelllang = 'en_gb,en_us' -- Set the spell checking language
|
||||
o.splitbelow = true -- split to the bottom
|
||||
o.splitright = true -- vsplit to the right
|
||||
o.termguicolors = true -- Enable GUI colors
|
||||
|
||||
@@ -5,8 +5,14 @@ return {
|
||||
'folke/snacks.nvim',
|
||||
priority = 1000,
|
||||
lazy = false,
|
||||
---@type snacks.Config
|
||||
opts = {
|
||||
bigfile = { enabled = true },
|
||||
input = { enabled = true },
|
||||
notifier = {
|
||||
enabled = true,
|
||||
timeout = 3000,
|
||||
},
|
||||
gitbrowse = { enabled = true },
|
||||
quickfile = { enabled = true },
|
||||
statuscolumn = {
|
||||
@@ -38,6 +44,11 @@ return {
|
||||
{
|
||||
'folke/noice.nvim',
|
||||
event = 'VeryLazy',
|
||||
dependencies = {
|
||||
-- if you lazy-load any plugin below, make sure to add proper `module="..."` entries
|
||||
'MunifTanjim/nui.nvim',
|
||||
'rcarriga/nvim-notify',
|
||||
},
|
||||
opts = {
|
||||
lsp = {
|
||||
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
|
||||
@@ -60,7 +71,10 @@ return {
|
||||
filter = {
|
||||
event = 'msg_show',
|
||||
kind = '',
|
||||
find = 'written',
|
||||
any = {
|
||||
{ find = 'written' },
|
||||
{ find = '%d of %d --%d%--' },
|
||||
},
|
||||
},
|
||||
opts = { skip = true },
|
||||
},
|
||||
@@ -101,14 +115,6 @@ return {
|
||||
},
|
||||
},
|
||||
},
|
||||
dependencies = {
|
||||
-- if you lazy-load any plugin below, make sure to add proper `module="..."` entries
|
||||
'MunifTanjim/nui.nvim',
|
||||
-- OPTIONAL:
|
||||
-- `nvim-notify` is only needed, if you want to use the notification view.
|
||||
-- If not available, we use `mini` as the fallback
|
||||
'rcarriga/nvim-notify',
|
||||
},
|
||||
},
|
||||
|
||||
-- A pretty diagnostics, references, telescope results,
|
||||
@@ -131,7 +137,7 @@ return {
|
||||
},
|
||||
modes = {
|
||||
diagnostics = {
|
||||
auto_open = true,
|
||||
auto_open = false,
|
||||
},
|
||||
test = {
|
||||
mode = 'diagnostics',
|
||||
@@ -139,7 +145,7 @@ return {
|
||||
type = 'split',
|
||||
relative = 'win',
|
||||
position = 'right',
|
||||
size = 0.3,
|
||||
size = 0.25,
|
||||
},
|
||||
},
|
||||
cascade = {
|
||||
@@ -158,13 +164,4 @@ return {
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- Navigate your code with search labels, enhanced
|
||||
-- character motions and Treesitter integration
|
||||
-- https://github.com/folke/flash.nvim
|
||||
{
|
||||
'folke/flash.nvim',
|
||||
event = 'VeryLazy',
|
||||
opts = {},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -108,17 +108,25 @@ local lsp_servers = {
|
||||
-- These are automatically configured by WhoIsSethDaniel/mason-tool-installer.nvim
|
||||
local mason_tools = {
|
||||
'actionlint',
|
||||
'ast-grep',
|
||||
'black',
|
||||
'editorconfig-checker',
|
||||
'goimports',
|
||||
'golangci-lint',
|
||||
'golines',
|
||||
'gopls',
|
||||
'gotests',
|
||||
'isort',
|
||||
'phpcbf',
|
||||
'phpmd',
|
||||
'phpstan',
|
||||
'pint',
|
||||
'prettierd',
|
||||
'revive',
|
||||
'semgrep',
|
||||
'shellcheck',
|
||||
'shfmt',
|
||||
'sonarlint-language-server',
|
||||
'staticcheck',
|
||||
'stylua',
|
||||
'trivy',
|
||||
@@ -323,7 +331,7 @@ return {
|
||||
|
||||
-- Disable autoformat for files in a certain paths
|
||||
local bufname = vim.api.nvim_buf_get_name(bufnr)
|
||||
if bufname:match '/node_modules|vendor/' then return end
|
||||
if bufname:match '/dist|node_modules|vendor/' then return end
|
||||
|
||||
return {
|
||||
timeout_ms = 500,
|
||||
|
||||
@@ -25,6 +25,14 @@ return {
|
||||
},
|
||||
}
|
||||
|
||||
-- Better Around/Inside textobjects
|
||||
--
|
||||
-- Examples:
|
||||
-- - va) - [V]isually select [A]round [)]paren
|
||||
-- - yinq - [Y]ank [I]nside [N]ext [Q]uote
|
||||
-- - ci' - [C]hange [I]nside [']quote
|
||||
require('mini.ai').setup { n_lines = 500 }
|
||||
|
||||
-- Animate common Neovim actions
|
||||
-- Replaced anuvyklack/windows.nvim
|
||||
require('mini.animate').setup()
|
||||
|
||||
@@ -41,7 +41,7 @@ return {
|
||||
'document_symbols',
|
||||
},
|
||||
source_selector = {
|
||||
winbar = true,
|
||||
winbar = false,
|
||||
statusline = false,
|
||||
separator = { left = '', right = '' },
|
||||
show_separator_on_edge = true,
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
return {
|
||||
-- https://github.com/preservim/vim-colors-pencil
|
||||
-- https://github.com/rmehri01/onenord.nvim
|
||||
{
|
||||
'preservim/vim-colors-pencil',
|
||||
'rmehri01/onenord.nvim',
|
||||
priority = 1000, -- Make sure to load this before all the other start plugins.
|
||||
config = function()
|
||||
-- set the theme
|
||||
vim.cmd 'colorscheme pencil'
|
||||
end,
|
||||
opts = {
|
||||
borders = true,
|
||||
fade_nc = true,
|
||||
disable = {
|
||||
float_background = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
-- Automatic dark mode
|
||||
|
||||
1
config/tmux/plugins/tmux-resurrect
Submodule
1
config/tmux/plugins/tmux-resurrect
Submodule
Submodule config/tmux/plugins/tmux-resurrect added at cff343cf9e
@@ -137,6 +137,9 @@ set -g @mode_indicator_sync_mode_style 'bg=default,fg=red'
|
||||
set -g @fzf-url-bind 'u'
|
||||
set -g @fzf-url-history-limit '2000'
|
||||
|
||||
# https://github.com/tmux-plugins/tmux-continuum
|
||||
set -g @continuum-restore 'on'
|
||||
|
||||
# ── Own scripts ───────────────────────────────────────────────────────
|
||||
|
||||
# If we started tmux with a session name, rename it.
|
||||
@@ -154,6 +157,7 @@ run-shell "$HOME/.dotfiles/config/tmux/plugins/tmux-window-name/tmux_window_name
|
||||
run-shell "$HOME/.dotfiles/config/tmux/plugins/tmux-mode-indicator/mode_indicator.tmux"
|
||||
run-shell "$HOME/.dotfiles/config/tmux/plugins/tmux-suspend/suspend.tmux"
|
||||
run-shell "$HOME/.dotfiles/config/tmux/plugins/tmux-continuum/continuum.tmux"
|
||||
run-shell "$HOME/.dotfiles/config/tmux/plugins/tmux-resurrect/resurrect.tmux"
|
||||
run-shell "$HOME/.dotfiles/config/tmux/plugins/tmux-sessionist/sessionist.tmux"
|
||||
run-shell "$HOME/.dotfiles/config/tmux/plugins/tmux-yank/yank.tmux"
|
||||
run-shell "$HOME/.dotfiles/config/tmux/plugins/tmux-current-pane-hostname/current_pane_hostname.tmux"
|
||||
|
||||
@@ -372,8 +372,10 @@ function! plug#end()
|
||||
|
||||
for [cmd, names] in items(lod.cmd)
|
||||
execute printf(
|
||||
\ 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)',
|
||||
\ cmd, string(cmd), string(names))
|
||||
\ has('patch-7.4.1898')
|
||||
\ ? 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, <q-mods> ,%s)'
|
||||
\ : 'command! -nargs=* -range -bang -complete=file %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)'
|
||||
\ , cmd, string(cmd), string(names))
|
||||
endfor
|
||||
|
||||
for [map, names] in items(lod.map)
|
||||
@@ -651,11 +653,19 @@ function! s:lod_ft(pat, names)
|
||||
call s:doautocmd('filetypeindent', 'FileType')
|
||||
endfunction
|
||||
|
||||
function! s:lod_cmd(cmd, bang, l1, l2, args, names)
|
||||
call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||
call s:dobufread(a:names)
|
||||
execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
|
||||
endfunction
|
||||
if has('patch-7.4.1898')
|
||||
function! s:lod_cmd(cmd, bang, l1, l2, args, mods, names)
|
||||
call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||
call s:dobufread(a:names)
|
||||
execute printf('%s %s%s%s %s', a:mods, (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
|
||||
endfunction
|
||||
else
|
||||
function! s:lod_cmd(cmd, bang, l1, l2, args, names)
|
||||
call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||
call s:dobufread(a:names)
|
||||
execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! s:lod_map(map, names, with_prefix, prefix)
|
||||
call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||
@@ -1075,12 +1085,16 @@ function! s:hash_match(a, b)
|
||||
return stridx(a:a, a:b) == 0 || stridx(a:b, a:a) == 0
|
||||
endfunction
|
||||
|
||||
function! s:disable_credential_helper()
|
||||
return s:git_version_requirement(2) && get(g:, 'plug_disable_credential_helper', 1)
|
||||
endfunction
|
||||
|
||||
function! s:checkout(spec)
|
||||
let sha = a:spec.commit
|
||||
let output = s:git_revision(a:spec.dir)
|
||||
let error = 0
|
||||
if !empty(output) && !s:hash_match(sha, s:lines(output)[0])
|
||||
let credential_helper = s:git_version_requirement(2) ? '-c credential.helper= ' : ''
|
||||
let credential_helper = s:disable_credential_helper() ? '-c credential.helper= ' : ''
|
||||
let output = s:system(
|
||||
\ 'git '.credential_helper.'fetch --depth 999999 && git checkout '.plug#shellescape(sha).' --', a:spec.dir)
|
||||
let error = v:shell_error
|
||||
@@ -1589,7 +1603,7 @@ while 1 " Without TCO, Vim stack is bound to explode
|
||||
let [error, _] = s:git_validate(spec, 0)
|
||||
if empty(error)
|
||||
if pull
|
||||
let cmd = s:git_version_requirement(2) ? ['git', '-c', 'credential.helper=', 'fetch'] : ['git', 'fetch']
|
||||
let cmd = s:disable_credential_helper() ? ['git', '-c', 'credential.helper=', 'fetch'] : ['git', 'fetch']
|
||||
if has_tag && !empty(globpath(spec.dir, '.git/shallow'))
|
||||
call extend(cmd, ['--depth', '99999999'])
|
||||
endif
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
local wezterm = require 'wezterm'
|
||||
local config = wezterm.config_builder()
|
||||
|
||||
config.set_environment_variables = {
|
||||
COLORTERM = 'truecolor',
|
||||
}
|
||||
|
||||
-- Font and font size
|
||||
config.font_size = 14.0
|
||||
config.font = wezterm.font_with_fallback {
|
||||
{
|
||||
family = 'Operator Mono',
|
||||
weight = 'Light',
|
||||
weight = 'Book',
|
||||
},
|
||||
'Operator Mono',
|
||||
'JetBrainsMonoNL NFM Light',
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
# yabai -m signal --add event=dock_did_restart action="sudo yabai --load-sa"
|
||||
|
||||
yabai -m config \
|
||||
active_window_border_color 0xff775759 \
|
||||
auto_balance on \
|
||||
layout bsp \
|
||||
top_padding 0 \
|
||||
|
||||
@@ -5,20 +5,14 @@
|
||||
"assistant": {
|
||||
"default_model": {
|
||||
"provider": "copilot_chat",
|
||||
"model": "claude-3-5-sonnet"
|
||||
"model": "claude-3-7-sonnet"
|
||||
},
|
||||
"version": "2"
|
||||
},
|
||||
"formatter": {
|
||||
"external": {
|
||||
"command": "prettier",
|
||||
"arguments": [
|
||||
"--stdin-filepath",
|
||||
"{buffer_path}"
|
||||
]
|
||||
}
|
||||
},
|
||||
"languages": {
|
||||
"Shell Script": {
|
||||
"enable_language_server": true
|
||||
},
|
||||
"JavaScript": {
|
||||
"enable_language_server": true,
|
||||
"code_actions_on_format": {
|
||||
|
||||
@@ -6,8 +6,15 @@ Some problematic code has been fixed per `shellcheck` suggestions.
|
||||
## Homegrown
|
||||
|
||||
- dfm
|
||||
- git-dirty (based on git-extra-tools)
|
||||
- git-fsck-dirs
|
||||
- git-update-dirs
|
||||
- php-switcher
|
||||
- x-backup-folder
|
||||
- x-backup-mysql-with-prefix
|
||||
- x-check-git-attributes
|
||||
- x-clean-vendordirs
|
||||
- x-env-list
|
||||
- x-open-ports
|
||||
|
||||
## Sourced
|
||||
@@ -25,9 +32,15 @@ Some problematic code has been fixed per `shellcheck` suggestions.
|
||||
| `x-when-up` | skx/sysadmin-util |
|
||||
|
||||
- Sources:
|
||||
- [skx/sysadmin-utils](https://github.com/skx/sysadmin-util/)
|
||||
- [skx/sysadmin-utils][skx]
|
||||
- Tools for Linux/Unix sysadmins.
|
||||
- [Licence](https://github.com/skx/sysadmin-util/blob/master/LICENSE)
|
||||
- [onnimonni](https://github.com/onnimonni)
|
||||
- [validate_sha256sum](https://gist.github.com/onnimonni/b49779ebc96216771a6be3de46449fa1)
|
||||
- [mvdan/dotfiles](https://github.com/mvdan/dotfiles)
|
||||
- [Licence][skx-license]
|
||||
- [onnimonni][onnimonni]
|
||||
- [validate_sha256sum][onnimonni-gist]
|
||||
- [mvdan/dotfiles][mvdan]
|
||||
|
||||
[onnimonni]: https://github.com/onnimonni
|
||||
[onnimonni-gist]: https://gist.github.com/onnimonni/b49779ebc96216771a6be3de46449fa1
|
||||
[skx]: https://github.com/skx/sysadmin-util
|
||||
[skx-license]: https://github.com/skx/sysadmin-util/blob/master/LICENSE
|
||||
[mvdan]: https://github.com/mvdan/dotfiles
|
||||
|
||||
443
local/bin/php-switcher
Executable file
443
local/bin/php-switcher
Executable file
@@ -0,0 +1,443 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Brew PHP Switcher
|
||||
#
|
||||
# Use to switch between PHP versions installed via Homebrew.
|
||||
#
|
||||
# Usage: php-switcher <version> [--help|--installed|--current|--auto]
|
||||
# Example: php-switcher 7.4
|
||||
# Example: php-switcher 8.0
|
||||
# Example: php-switcher latest
|
||||
# Example: php-switcher --auto
|
||||
#
|
||||
# Created by Ismo Vuorinen <https://github.com/ivuorinen> (2025)
|
||||
# Licensed under the MIT License (https://opensource.org/licenses/MIT)
|
||||
|
||||
set -euo pipefail # Add error handling
|
||||
|
||||
# Configuration
|
||||
LATEST_VERSION_FORMULA="php" # The formula name for latest PHP version
|
||||
PHP_VERSION_FILE=".php-version" # File name to look for when auto-switching
|
||||
|
||||
# Switch brew php version
|
||||
function check_dependencies()
|
||||
{
|
||||
if ! command -v brew > /dev/null 2>&1; then
|
||||
echo "Error: Homebrew is not installed"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function usage()
|
||||
{
|
||||
echo "Brew PHP Switcher - Switch between PHP versions installed via Homebrew"
|
||||
echo ""
|
||||
echo "Usage: php-switcher <version> [options]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " --help Show this help message"
|
||||
echo " --installed List installed PHP versions"
|
||||
echo " --current Show currently active PHP version"
|
||||
echo " --auto Auto-switch based on .php-version file in current directory"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " php-switcher 7.4"
|
||||
echo " php-switcher 8.0"
|
||||
echo " php-switcher latest"
|
||||
echo " php-switcher --auto"
|
||||
echo ""
|
||||
echo "Auto-switching:"
|
||||
echo " Create a .php-version file in your project directory with a PHP version"
|
||||
echo " Example .php-version content: 8.1"
|
||||
echo ""
|
||||
exit 0
|
||||
}
|
||||
|
||||
function list_php_versions()
|
||||
{
|
||||
# Check Homebrew's installation path for PHP versions
|
||||
local brew_cellar
|
||||
brew_cellar="$(brew --cellar)"
|
||||
local php_paths=()
|
||||
local versions=()
|
||||
local formulas=()
|
||||
local active=()
|
||||
|
||||
# Look for all PHP installations in Homebrew Cellar
|
||||
if [[ -d "$brew_cellar/php" ]]; then
|
||||
php_paths+=("$brew_cellar/php")
|
||||
fi
|
||||
|
||||
# Look for versioned PHP installations
|
||||
while IFS= read -r dir; do
|
||||
if [[ -d $dir ]]; then
|
||||
php_paths+=("$dir")
|
||||
fi
|
||||
done < <(find "$brew_cellar" \
|
||||
-maxdepth 1 -name 'php@*' \
|
||||
-type d 2> /dev/null || echo "")
|
||||
|
||||
if [[ ${#php_paths[@]} -eq 0 ]]; then
|
||||
echo "No PHP versions installed through Homebrew."
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Find which version is currently linked
|
||||
local current_bin
|
||||
current_bin=$(readlink -f \
|
||||
"$(command -v php 2> /dev/null)" \
|
||||
2> /dev/null || echo "")
|
||||
|
||||
# Collect data for each installed PHP version
|
||||
for path in "${php_paths[@]}"; do
|
||||
local formula
|
||||
formula=$(basename "$path")
|
||||
local version_label
|
||||
|
||||
if [[ $formula == "php" ]]; then
|
||||
version_label="latest"
|
||||
else
|
||||
version_label="${formula#php@}"
|
||||
fi
|
||||
|
||||
# Find the actual version from the directory structure
|
||||
local version_dir
|
||||
version_dir=$(find "$path" -maxdepth 1 -type d \
|
||||
| grep -v "^$path$" | sort -V | tail -1)
|
||||
|
||||
if [[ -n $version_dir && -d "$version_dir/bin" ]]; then
|
||||
local full_version
|
||||
full_version=$("$version_dir/bin/php" -v 2> /dev/null \
|
||||
| grep -oE 'PHP [0-9]+\.[0-9]+\.[0-9]+' \
|
||||
| head -1 \
|
||||
| cut -d' ' -f2 \
|
||||
|| echo "$version_label.x")
|
||||
|
||||
# Determine if this is the active version
|
||||
local is_active="No"
|
||||
if [[ -n $current_bin && $current_bin == "$version_dir/bin/php" ]]; then
|
||||
is_active="Yes"
|
||||
fi
|
||||
|
||||
# Handle the 'latest' case - replace with actual version number
|
||||
local display_version
|
||||
if [[ $version_label == "latest" ]]; then
|
||||
display_version="${full_version%.*}" # Get major.minor version
|
||||
else
|
||||
display_version="$version_label"
|
||||
fi
|
||||
|
||||
# Store data for table display
|
||||
versions+=("$display_version")
|
||||
formulas+=("$formula")
|
||||
active+=("$is_active")
|
||||
fi
|
||||
done
|
||||
|
||||
# Calculate maximum column widths
|
||||
local max_version_width=7 # "Version" header length
|
||||
local max_formula_width=7 # "Formula" header length
|
||||
local max_active_width=6 # "Active" header length
|
||||
|
||||
local count=${#versions[@]}
|
||||
for ((i = 0; i < count; i++)); do
|
||||
# Update max widths if needed
|
||||
if [[ ${#versions[i]} -gt $max_version_width ]]; then
|
||||
max_version_width=${#versions[i]}
|
||||
fi
|
||||
if [[ ${#formulas[i]} -gt $max_formula_width ]]; then
|
||||
max_formula_width=${#formulas[i]}
|
||||
fi
|
||||
done
|
||||
|
||||
# Build header with correct widths
|
||||
local header_format="| %-${max_version_width}s | %-${max_formula_width}s | "
|
||||
header_format+="%-${max_active_width}s |"
|
||||
|
||||
local separator_line="|"
|
||||
for ((i = 0; i < max_version_width + 2; i++)); do
|
||||
separator_line="${separator_line}-"
|
||||
done
|
||||
separator_line="${separator_line}|"
|
||||
|
||||
for ((i = 0; i < max_formula_width + 2; i++)); do
|
||||
separator_line="${separator_line}-"
|
||||
done
|
||||
separator_line="${separator_line}|"
|
||||
|
||||
for ((i = 0; i < max_active_width + 2; i++)); do
|
||||
separator_line="${separator_line}-"
|
||||
done
|
||||
separator_line="${separator_line}|"
|
||||
|
||||
# Print table header
|
||||
# shellcheck disable=SC2059
|
||||
printf "$header_format\n" "Version" "Formula" "Active"
|
||||
echo "$separator_line"
|
||||
|
||||
# Print table rows
|
||||
local row_format="| %-${max_version_width}s | %-${max_formula_width}s | "
|
||||
row_format+="%-${max_active_width}s |"
|
||||
|
||||
for ((i = 0; i < count; i++)); do
|
||||
# shellcheck disable=SC2059
|
||||
printf "$row_format\n" "${versions[i]}" "${formulas[i]}" "${active[i]}"
|
||||
done
|
||||
}
|
||||
|
||||
function get_php_formula_for_version()
|
||||
{
|
||||
local version="$1"
|
||||
|
||||
# Handle "latest" as a special case
|
||||
if [[ $version == "latest" ]]; then
|
||||
echo "$LATEST_VERSION_FORMULA"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# The regular version case (e.g., 7.4, 8.1)
|
||||
echo "php@$version"
|
||||
}
|
||||
|
||||
function check_formula_installed()
|
||||
{
|
||||
local formula="$1"
|
||||
local brew_cellar
|
||||
brew_cellar="$(brew --cellar)"
|
||||
|
||||
if [[ $formula == "php" ]]; then
|
||||
if [[ -d "$brew_cellar/php" ]]; then
|
||||
return 0
|
||||
fi
|
||||
elif [[ -d "$brew_cellar/$formula" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
function unlink_current_php()
|
||||
{
|
||||
local current_formula=""
|
||||
|
||||
# Find formulas more safely
|
||||
while IFS= read -r formula; do
|
||||
if [[ -n $formula ]]; then
|
||||
local linked
|
||||
linked=$(brew info --json=v1 "$formula" \
|
||||
| grep -o '"linked_keg":"[^"]*"' \
|
||||
| grep -v ':"null"')
|
||||
if [[ -n $linked ]]; then
|
||||
current_formula="$formula"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done < <(brew list --formula | grep -E '^php(@[0-9]+\.[0-9]+)?$' || echo "")
|
||||
|
||||
# If we found a linked formula, unlink it
|
||||
if [[ -n $current_formula ]]; then
|
||||
echo "Unlinking current PHP version ($current_formula)..."
|
||||
brew unlink "$current_formula" > /dev/null 2>&1 || true
|
||||
fi
|
||||
}
|
||||
|
||||
function link_php_version()
|
||||
{
|
||||
local formula="$1"
|
||||
|
||||
if ! check_formula_installed "$formula"; then
|
||||
echo "Error: PHP formula '$formula' is not installed"
|
||||
echo "Available versions:"
|
||||
list_php_versions
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Linking $formula..."
|
||||
if ! brew link --force --overwrite "$formula" > /dev/null 2>&1; then
|
||||
echo "Error: Failed to link $formula. Try running manually:"
|
||||
echo " brew link --force --overwrite $formula"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify the switch worked
|
||||
if ! command -v php > /dev/null 2>&1; then
|
||||
echo "Warning: PHP was linked but may not be working correctly"
|
||||
fi
|
||||
}
|
||||
|
||||
function get_current_version()
|
||||
{
|
||||
if ! command -v php > /dev/null 2>&1; then
|
||||
echo "No PHP currently linked"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local version
|
||||
version=$(php -v 2> /dev/null \
|
||||
| grep -oE 'PHP [0-9]+\.[0-9]+\.[0-9]+' \
|
||||
| head -1)
|
||||
|
||||
if [[ -z $version ]]; then
|
||||
echo "Unable to determine PHP version"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Find the corresponding formula
|
||||
local current_version
|
||||
current_version=$(echo "$version" | cut -d' ' -f2)
|
||||
local major_minor
|
||||
major_minor=$(echo "$current_version" | cut -d'.' -f1,2)
|
||||
|
||||
# Check if it's the latest version
|
||||
if check_formula_installed "php" \
|
||||
&& brew info --json=v1 php \
|
||||
| grep -o '"linked_keg":"[^"]*"' \
|
||||
| grep -v ':"null"' \
|
||||
| grep -q .; then
|
||||
echo "Current PHP version: $current_version (latest)"
|
||||
else
|
||||
echo "Current PHP version: $current_version (php@$major_minor)"
|
||||
fi
|
||||
}
|
||||
|
||||
function validate_version()
|
||||
{
|
||||
local version="$1"
|
||||
|
||||
# Valid formats: x.y or latest
|
||||
if [[ ! $version =~ ^([0-9]+\.[0-9]+|latest)$ ]]; then
|
||||
echo "Error: Invalid PHP version format. Use x.y format (e.g., 7.4) or"
|
||||
echo " 'latest'"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function find_php_version_file()
|
||||
{
|
||||
local dir="$PWD"
|
||||
|
||||
# Look for .php-version file in current directory and all parent directories
|
||||
while [[ $dir != "/" ]]; do
|
||||
if [[ -f "$dir/$PHP_VERSION_FILE" ]]; then
|
||||
echo "$dir/$PHP_VERSION_FILE"
|
||||
return 0
|
||||
fi
|
||||
dir=$(dirname "$dir")
|
||||
done
|
||||
|
||||
# Check the root directory as well
|
||||
if [[ -f "/$PHP_VERSION_FILE" ]]; then
|
||||
echo "/$PHP_VERSION_FILE"
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
function auto_switch_php_version()
|
||||
{
|
||||
local version_file
|
||||
|
||||
# Try to find a .php-version file
|
||||
version_file=$(find_php_version_file) || {
|
||||
echo "No .php-version file found in current directory or any parent"
|
||||
echo "directory. Create a $PHP_VERSION_FILE file with your desired"
|
||||
echo "PHP version (e.g., 8.1)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Read the version from the file
|
||||
local version
|
||||
version=$(tr -d '[:space:]' < "$version_file")
|
||||
|
||||
echo "Found $PHP_VERSION_FILE file at: $version_file"
|
||||
echo "Requested PHP version: $version"
|
||||
|
||||
# Validate the version
|
||||
validate_version "$version"
|
||||
|
||||
# Switch to the specified version
|
||||
switch_php_version "$version"
|
||||
}
|
||||
|
||||
function switch_php_version()
|
||||
{
|
||||
local version="$1"
|
||||
|
||||
# Get the formula name for the version
|
||||
local formula
|
||||
formula=$(get_php_formula_for_version "$version")
|
||||
|
||||
# Check if the requested PHP version is installed
|
||||
if ! check_formula_installed "$formula"; then
|
||||
echo "Error: PHP version $version is not installed"
|
||||
echo ""
|
||||
list_php_versions
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the current version info for comparison
|
||||
local current_info
|
||||
current_info=$(get_current_version 2> /dev/null || echo "None")
|
||||
|
||||
# Skip if we're already on the requested version
|
||||
if [[ $current_info == *"$version"* ]]; then
|
||||
echo "PHP version $version is already active"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Perform the switch
|
||||
unlink_current_php
|
||||
link_php_version "$formula"
|
||||
|
||||
# Verify the switch
|
||||
echo ""
|
||||
echo "Switched to:"
|
||||
get_current_version
|
||||
echo ""
|
||||
echo "PHP executable: $(command -v php)"
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
local version=""
|
||||
|
||||
# Parse arguments
|
||||
case "${1:-}" in
|
||||
--help)
|
||||
usage
|
||||
;;
|
||||
--installed)
|
||||
list_php_versions
|
||||
exit 0
|
||||
;;
|
||||
--current)
|
||||
get_current_version
|
||||
exit 0
|
||||
;;
|
||||
--auto)
|
||||
auto_switch_php_version
|
||||
exit 0
|
||||
;;
|
||||
"")
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
version="$1"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Validate and switch to the specified version
|
||||
validate_version "$version"
|
||||
switch_php_version "$version"
|
||||
}
|
||||
|
||||
# Run the script
|
||||
check_dependencies
|
||||
if [[ ${#@} -eq 0 ]]; then
|
||||
usage
|
||||
else
|
||||
main "$@"
|
||||
fi
|
||||
|
||||
# vim: ft=bash sw=4 ts=4 et tw=80 cc=80 :
|
||||
@@ -27,7 +27,8 @@
|
||||
},
|
||||
"homepage": "https://github.com/ivuorinen/dotfiles#readme",
|
||||
"devDependencies": {
|
||||
"@ivuorinen/base-configs": "^2.0.0"
|
||||
"@ivuorinen/base-configs": "^2.0.0",
|
||||
"bundle-audit": "^0.1.0"
|
||||
},
|
||||
"packageManager": "yarn@1.22.22"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user