Compare commits

..

6 Commits

9 changed files with 49 additions and 177 deletions

View File

@@ -181,3 +181,5 @@ fi
# ble.sh # ble.sh
# https://github.com/akinomyoga/ble.sh#13-set-up-bashrc # https://github.com/akinomyoga/ble.sh#13-set-up-bashrc
[[ ${BLE_VERSION-} ]] && ble-attach [[ ${BLE_VERSION-} ]] && ble-attach
if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init bash)"; fi

View File

@@ -1 +0,0 @@
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,2 @@
# worktrunk completions for fish
complete --keep-order --exclusive --command wt --arguments "(test -n \"\$WORKTRUNK_BIN\"; or set -l WORKTRUNK_BIN (type -P wt 2>/dev/null); and COMPLETE=fish \$WORKTRUNK_BIN -- (commandline --current-process --tokenize --cut-at-cursor) (commandline --current-token))"

View File

@@ -1,52 +0,0 @@
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

@@ -1,74 +0,0 @@
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

@@ -1,5 +1,29 @@
function dev -d "Create and attach to a tmux dev session for the current directory" function dev -d "Create and attach to a tmux dev session for the current git branch"
set -l session (basename (pwd) | string replace -a '.' '-') set -l branch (git branch --show-current 2>/dev/null)
__dev_create_session $session if test -z "$branch"
__dev_attach_session $session echo "Not in a git repository"
return 1
end
set -l session (string replace -a '/' '-' -- $branch | string replace -a '\\' '-')
if not tmux has-session -t "$session" 2>/dev/null
tmux new-session -d -s "$session" -c (pwd) -n dev
tmux split-window -h -t "$session:dev" -c (pwd)
tmux split-window -v -t "$session:dev.0" -c (pwd)
tmux split-window -v -t "$session:dev.2" -c (pwd)
tmux send-keys -t "$session:dev.1" 'vim' Enter
tmux send-keys -t "$session:dev.2" 'claude' Enter
tmux send-keys -t "$session:dev.3" 'pnpm i && pnpm dev' Enter
tmux select-pane -t "$session:dev.0"
end
if test -z "$TMUX"
exec tmux attach-session -t "$session"
else
set -l current_session (tmux display-message -p '#S')
if test "$current_session" != "$session"
exec tmux switch-client -t "$session"
end
end
end end

View File

@@ -1,45 +0,0 @@
function __create_session
set session "process-compose"
set dir "/home/tgrosinger/obsidian"
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 send-keys -t "$left" 'devbox services attach' Enter
tmux select-pane -t "$right"
end
end
function __attach_session
set session "process-compose"
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 pc -d "Create and attach to a tmux session for process compose in Obsidian"
__create_session
__attach_session
end

View File

@@ -0,0 +1,15 @@
# worktrunk shell integration for fish
# Sources full integration from binary on first use.
# Docs: https://worktrunk.dev/config/#shell-integration
# Check: wt config show | Uninstall: wt config shell uninstall
function wt
command wt config shell init fish | source
# Check both command exit code ($pipestatus[1]) and source exit code ($pipestatus[2])
# If source fails, the function isn't replaced and we'd infinite-loop calling ourselves
set -l wt_status $pipestatus[1]
set -l source_status $pipestatus[2]
test $wt_status -eq 0; or return $wt_status
test $source_status -eq 0; or return $source_status
wt $argv
end

View File

@@ -28,7 +28,8 @@ brew install \
restic \ restic \
ripgrep \ ripgrep \
stow \ stow \
tmux tmux \
worktrunk
#crane \ #crane \
#deno \ #deno \
#go \ #go \