feat(functions): helper fish_reload, env per-dir, vv e stormcode
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# per-directory env: KEY=VAL KEY2=VAL2 => /path1;/path2
|
||||
# righe che iniziano con # sono commenti. Attivare: riavvia fish o fai un cd.
|
||||
# AWS_PROFILE=StormRomaLab AWS_DEFAULT_REGION=eu-west-1 => /home/df/Projects/Work/Reply/StormProxy
|
||||
@@ -0,0 +1,51 @@
|
||||
function __env_per_dir --on-variable PWD --description "Apply per-directory env vars from ~/.config/fish/.env-per-dir.conf"
|
||||
set -l file ~/.config/fish/.env-per-dir.conf
|
||||
if set -q env_per_dir_file; and string length -q -- $env_per_dir_file
|
||||
set file $env_per_dir_file
|
||||
end
|
||||
test -f "$file"; or return 0
|
||||
|
||||
set -g __env_per_dir_managed
|
||||
set -g __env_per_dir_wanted
|
||||
|
||||
while read -l line
|
||||
string match -rq -- '^[[:space:]]*#' "$line"; and continue
|
||||
string match -q -- '' "$line"; and continue
|
||||
|
||||
set -l parts (string split --max 1 ' => ' -- "$line")
|
||||
test (count $parts) -eq 2; or continue
|
||||
|
||||
set -l assignments (string split ' ' -- $parts[1])
|
||||
set -l folders (string split ';' -- $parts[2])
|
||||
|
||||
for a in $assignments
|
||||
set -l kv (string split --max 1 '=' -- "$a")
|
||||
test (count $kv) -eq 2; or continue
|
||||
if not contains -- $kv[1] $__env_per_dir_managed
|
||||
set -a __env_per_dir_managed $kv[1]
|
||||
end
|
||||
end
|
||||
|
||||
set -l matched 0
|
||||
for d in $folders
|
||||
if string match -q -- "$d" "$PWD"; or string match -q -- "$d/*" "$PWD"
|
||||
set matched 1
|
||||
end
|
||||
end
|
||||
|
||||
if test $matched -eq 1
|
||||
for a in $assignments
|
||||
set -l kv (string split --max 1 '=' -- "$a")
|
||||
test (count $kv) -eq 2; or continue
|
||||
set -a __env_per_dir_wanted $kv[1]
|
||||
set -gx $kv[1] $kv[2]
|
||||
end
|
||||
end
|
||||
end < "$file"
|
||||
|
||||
for name in $__env_per_dir_managed
|
||||
if not contains -- $name $__env_per_dir_wanted
|
||||
set -e "$name"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
function fish_reload --description 'Re-source fish init: config.fish, conf.d, functions and completions'
|
||||
set -l fish_dir ~/.config/fish
|
||||
|
||||
# conf.d + config.fish
|
||||
for file in $fish_dir/conf.d/*.fish
|
||||
source $file
|
||||
end
|
||||
source $fish_dir/config.fish
|
||||
|
||||
# Erase autoloaded functions so they reload from disk on next use
|
||||
for file in $fish_dir/functions/*.fish
|
||||
functions -e (path change-extension '' (path basename $file)) 2>/dev/null
|
||||
end
|
||||
|
||||
# Reload completions
|
||||
for file in $fish_dir/completions/*.fish
|
||||
complete -e -c (path change-extension '' (path basename $file)) 2>/dev/null
|
||||
source $file
|
||||
end
|
||||
|
||||
# Re-run key bindings
|
||||
functions -q fish_user_key_bindings; and fish_user_key_bindings
|
||||
|
||||
set_color green
|
||||
echo 'fish config reloaded'
|
||||
set_color normal
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
function stormcode -d "Lancia opencode con il profilo stormcode (config dir dedicata, service 49375)"
|
||||
set -lx OPENCODE_CONFIG_DIR ~/.config/stormcode/opencode
|
||||
set -lx XDG_DATA_HOME ~/.local/share/stormcode
|
||||
set -lx XDG_STATE_HOME ~/.local/state/stormcode
|
||||
set -lx XDG_CACHE_HOME ~/.cache/stormcode
|
||||
opencode $argv
|
||||
end
|
||||
@@ -0,0 +1,46 @@
|
||||
function vv -d "nvim: vv [nome] [file] — unico client TUI connesso al server persistente"
|
||||
set -l name default
|
||||
if set -q argv[1]; set name $argv[1]; end
|
||||
|
||||
# Sanitizza: solo alfanumerici, '-' e '_' (niente path traversal)
|
||||
if not string match -qr '^[A-Za-z0-9_-]+$' -- $name
|
||||
echo "vv: nome server non valido: '$name'" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
set -l dir /tmp/nvim-servers
|
||||
set -l sock "$dir/$name.sock"
|
||||
set -l log "$dir/$name.log"
|
||||
mkdir -p $dir
|
||||
|
||||
# Stale socket: esiste ma nessun nvim dietro -> rimuovi
|
||||
if test -S $sock
|
||||
set -l pid (command nvim --server $sock --remote-expr 'getpid()' 2>/dev/null)
|
||||
if not test -n "$pid"; or not kill -0 "$pid" 2>/dev/null
|
||||
rm -f $sock
|
||||
end
|
||||
end
|
||||
|
||||
# Avvia il server headless in trasparenza se manca (distaccato dalla shell)
|
||||
if not test -S $sock
|
||||
nohup nvim --headless --listen $sock >$log 2>&1 &
|
||||
disown $last_pid 2>/dev/null; or disown
|
||||
for i in (seq 1 100)
|
||||
test -S $sock; and break
|
||||
sleep 0.1
|
||||
end
|
||||
end
|
||||
|
||||
if not test -S $sock
|
||||
echo "vv: server '$name' non avviato (vedi $log)" >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
# Modello 1: apri UN client nvim connesso al server (TUI visibile).
|
||||
# Con file -> il file in una nuova tab; senza -> riaggancia la vista.
|
||||
if set -q argv[2]
|
||||
command nvim --server $sock --remote-tab $argv[2]
|
||||
else
|
||||
command nvim --server $sock
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user