Compare commits
6 Commits
00ca94a9f3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f5c054f3e | |||
| 5fb50bb924 | |||
| 8b983c5dec | |||
| 42acd37773 | |||
| a516164d6f | |||
| 7261362c8e |
@@ -181,5 +181,3 @@ fi
|
||||
# ble.sh
|
||||
# https://github.com/akinomyoga/ble.sh#13-set-up-bashrc
|
||||
[[ ${BLE_VERSION-} ]] && ble-attach
|
||||
|
||||
if command -v wt >/dev/null 2>&1; then eval "$(command wt config shell init bash)"; fi
|
||||
|
||||
1
home/.config/fish/completions/dev-switch.fish
Normal file
1
home/.config/fish/completions/dev-switch.fish
Normal 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)'
|
||||
@@ -1,2 +0,0 @@
|
||||
# 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))"
|
||||
52
home/.config/fish/conf.d/dev.fish
Normal file
52
home/.config/fish/conf.d/dev.fish
Normal 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
|
||||
@@ -7,6 +7,7 @@
|
||||
#
|
||||
|
||||
set AUTOENV_AUTH_FILE ~/.autoenv_authorized
|
||||
set AUTOENV_TRUSTED_FILE ~/.autoenv_trusted
|
||||
if [ -z "$AUTOENV_ENV_FILENAME" ]
|
||||
set AUTOENV_ENV_FILENAME ".env"
|
||||
end
|
||||
@@ -77,6 +78,27 @@ function autoenv_hashline
|
||||
echo "$envfile:$hash"
|
||||
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
|
||||
# typeset envfile hash
|
||||
set envfile $argv[1]
|
||||
@@ -87,7 +109,7 @@ end
|
||||
|
||||
function autoenv_check_authz_and_run
|
||||
set envfile $argv[1]
|
||||
if autoenv_check_authz "$envfile"
|
||||
if autoenv_check_authz "$envfile"; or autoenv_check_trusted "$envfile"
|
||||
autoenv_source "$envfile"
|
||||
return 0
|
||||
end
|
||||
@@ -100,11 +122,16 @@ function autoenv_check_authz_and_run
|
||||
autoenv_indent "$envfile"
|
||||
autoenv_env " --- (end contents) -----------------------------------------"
|
||||
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
|
||||
if [ $answer = y -o $answer = Y ]
|
||||
if [ "$answer" = y -o "$answer" = Y ]
|
||||
autoenv_authorize_env "$envfile"
|
||||
autoenv_source "$envfile"
|
||||
else if [ "$answer" = t -o "$answer" = T ]
|
||||
autoenv_trust_env "$envfile"
|
||||
autoenv_source "$envfile"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -131,3 +158,7 @@ function autoenv_source
|
||||
#set -e AUTOENV_CUR_FILE
|
||||
#set -e AUTOENV_CUR_DIR
|
||||
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
|
||||
|
||||
74
home/.config/fish/functions/dev-wt.fish
Normal file
74
home/.config/fish/functions/dev-wt.fish
Normal 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
|
||||
5
home/.config/fish/functions/dev.fish
Normal file
5
home/.config/fish/functions/dev.fish
Normal 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
|
||||
45
home/.config/fish/functions/pc.fish
Normal file
45
home/.config/fish/functions/pc.fish
Normal file
@@ -0,0 +1,45 @@
|
||||
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
|
||||
@@ -1,15 +0,0 @@
|
||||
# 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
|
||||
@@ -28,8 +28,7 @@ brew install \
|
||||
restic \
|
||||
ripgrep \
|
||||
stow \
|
||||
tmux \
|
||||
worktrunk
|
||||
tmux
|
||||
#crane \
|
||||
#deno \
|
||||
#go \
|
||||
|
||||
Reference in New Issue
Block a user