Compare commits

...

5 Commits

6 changed files with 168 additions and 3 deletions

View File

@@ -0,0 +1 @@
complete -c dev-switch -f -a '(git worktree list --porcelain 2>/dev/null | string match "worktree *" | string replace "worktree " "" | while read -l p; basename $p; end)'

View File

@@ -0,0 +1,52 @@
function __dev_repo_name
# Use the main worktree (first entry) for consistent naming across worktrees
set -l lines (git worktree list --porcelain | string replace -rf "^worktree " "")
basename $lines[1]
end
function __dev_create_session -a session dir
if test -z "$dir"
set dir (pwd)
end
if not tmux has-session -t "$session" 2>/dev/null
# Unset any devbox environment variables so they can be re-sourced
# in the new directory.
set -l shell env
for var in (set --names --export | string match 'DEVBOX_*')
set -a shell -u $var
end
set -a shell (command -s fish) --login
tmux new-session -d -s "$session" -c "$dir" -n dev $shell
# Ensure that new panes in this session also start with the clean environment.
tmux set-option -t "$session" default-command (string join ' ' -- $shell)
set -l left (tmux display-message -t "$session:dev" -p '#{pane_id}')
tmux split-window -h -t "$left" -c "$dir" $shell
set -l right (tmux display-message -t "$session:dev" -p '#{pane_id}')
tmux split-window -v -t "$right" -c "$dir" $shell
set -l bottom_right (tmux display-message -t "$session:dev" -p '#{pane_id}')
tmux send-keys -t "$left" 'vim' Enter
tmux send-keys -t "$right" 'claude' Enter
tmux select-pane -t "$bottom_right"
end
end
function __dev_attach_session -a session
if test -z "$TMUX"
tmux attach-session -t "$session"
else
set -l current_session (tmux display-message -p '#S')
if test "$current_session" != "$session"
tmux switch-client -t "$session"
end
end
end
function __dev_wt_session_name -a repo branch
set -l name "$repo-"(string replace -a '/' '-' -- $branch | string replace -a '\\' '-')
string replace -a '.' '-' -- $name
end

View File

@@ -7,6 +7,7 @@
# #
set AUTOENV_AUTH_FILE ~/.autoenv_authorized set AUTOENV_AUTH_FILE ~/.autoenv_authorized
set AUTOENV_TRUSTED_FILE ~/.autoenv_trusted
if [ -z "$AUTOENV_ENV_FILENAME" ] if [ -z "$AUTOENV_ENV_FILENAME" ]
set AUTOENV_ENV_FILENAME ".env" set AUTOENV_ENV_FILENAME ".env"
end end
@@ -77,6 +78,27 @@ function autoenv_hashline
echo "$envfile:$hash" echo "$envfile:$hash"
end end
function autoenv_content_hash
set envfile $argv[1]
shasum "$envfile" | cut -d' ' -f 1
end
function autoenv_check_trusted
set envfile $argv[1]
set hash (autoenv_content_hash "$envfile")
touch $AUTOENV_TRUSTED_FILE
grep -Fxq "$hash" $AUTOENV_TRUSTED_FILE
end
function autoenv_trust_env
set envfile $argv[1]
set hash (autoenv_content_hash "$envfile")
touch $AUTOENV_TRUSTED_FILE
if not grep -Fxq "$hash" $AUTOENV_TRUSTED_FILE
echo "$hash" >>$AUTOENV_TRUSTED_FILE
end
end
function autoenv_check_authz function autoenv_check_authz
# typeset envfile hash # typeset envfile hash
set envfile $argv[1] set envfile $argv[1]
@@ -87,7 +109,7 @@ end
function autoenv_check_authz_and_run function autoenv_check_authz_and_run
set envfile $argv[1] set envfile $argv[1]
if autoenv_check_authz "$envfile" if autoenv_check_authz "$envfile"; or autoenv_check_trusted "$envfile"
autoenv_source "$envfile" autoenv_source "$envfile"
return 0 return 0
end end
@@ -100,11 +122,16 @@ function autoenv_check_authz_and_run
autoenv_indent "$envfile" autoenv_indent "$envfile"
autoenv_env " --- (end contents) -----------------------------------------" autoenv_env " --- (end contents) -----------------------------------------"
autoenv_env autoenv_env
autoenv_printf "Are you sure you want to allow this? (y/N) \n" autoenv_printf "Are you sure you want to allow this? (y/t/N) \n"
autoenv_env " y - approve for this path only"
autoenv_env " t - trust these contents everywhere"
read answer read answer
if [ $answer = y -o $answer = Y ] if [ "$answer" = y -o "$answer" = Y ]
autoenv_authorize_env "$envfile" autoenv_authorize_env "$envfile"
autoenv_source "$envfile" autoenv_source "$envfile"
else if [ "$answer" = t -o "$answer" = T ]
autoenv_trust_env "$envfile"
autoenv_source "$envfile"
end end
end end
end end
@@ -131,3 +158,7 @@ function autoenv_source
#set -e AUTOENV_CUR_FILE #set -e AUTOENV_CUR_FILE
#set -e AUTOENV_CUR_DIR #set -e AUTOENV_CUR_DIR
end end
# Run once on shell startup so .env files are sourced in the initial
# working directory (PWD is already set, so --on-variable PWD won't fire).
autoenv_init

View File

@@ -0,0 +1,74 @@
function dev-wt -d "Switch to a tmux dev session for a worktree, creating it if needed" -a name
set -l repo (__dev_repo_name 2>/dev/null)
if test -z "$repo"
echo "Not in a git repository"
return 1
end
# Default to current branch when no argument given
if test -z "$name"
set name (git branch --show-current 2>/dev/null)
if test -z "$name"
echo "Usage: dev-wt [worktree-name]"
return 1
end
end
set -l wt_path ""
set -l wt_branch ""
# Search for worktree by directory basename or branch name
set -l current_path ""
set -l current_branch ""
for line in (git worktree list --porcelain)
if string match -q "worktree *" -- $line
set current_path (string replace "worktree " "" -- $line)
set current_branch ""
else if string match -q "branch *" -- $line
set current_branch (string replace "branch refs/heads/" "" -- $line)
if test (basename "$current_path") = "$name"; or test "$current_branch" = "$name"
set wt_path $current_path
set wt_branch $current_branch
break
end
end
end
# If worktree not found, create it
if test -z "$wt_path"
set -l main_wt_path (git worktree list --porcelain | head -1 | string replace "worktree " "")
set -l parent_dir (dirname "$main_wt_path")
set wt_path "$parent_dir/$repo-$name"
set wt_branch "$name"
if test -d "$wt_path"
echo "Error: directory already exists: $wt_path"
return 1
end
# Create branch from main if it doesn't exist
if not git rev-parse --verify "$wt_branch" >/dev/null 2>&1
echo "Creating branch '$wt_branch' from main..."
git branch "$wt_branch" main
end
echo "Creating worktree at $wt_path..."
git worktree add "$wt_path" "$wt_branch"
# Run repo-specific setup hook if present
set -l setup_hook "$main_wt_path/.worktree-setup.sh"
if test -x "$setup_hook"
echo "Running worktree setup hook..."
bash "$setup_hook" "$wt_path" "$main_wt_path" "$wt_branch"
end
end
if test -z "$wt_branch"
echo "Worktree '$name' has no branch (detached HEAD)"
return 1
end
set -l session (__dev_wt_session_name $repo $wt_branch)
__dev_create_session $session $wt_path
__dev_attach_session $session
end

View File

@@ -0,0 +1,5 @@
function dev -d "Create and attach to a tmux dev session for the current directory"
set -l session (basename (pwd) | string replace -a '.' '-')
__dev_create_session $session
__dev_attach_session $session
end

View File

@@ -21,6 +21,7 @@ brew install \
gh \ gh \
git \ git \
git-delta \ git-delta \
hmans/beans/beans \
jq \ jq \
lazygit \ lazygit \
neovim \ neovim \
@@ -83,6 +84,7 @@ flatpak install flathub org.gimp.GIMP
flatpak install flathub org.gimp.GIMP.Plugin.GMic flatpak install flathub org.gimp.GIMP.Plugin.GMic
flatpak install flathub org.musicbrainz.Picard flatpak install flathub org.musicbrainz.Picard
flatpak install flathub fr.handbrake.ghb flatpak install flathub fr.handbrake.ghb
flatpak install flathub com.github.jeromerobert.pdfarranger
# Install devbox # Install devbox
# https://www.jetify.com/docs/devbox/installing-devbox # https://www.jetify.com/docs/devbox/installing-devbox