Compare commits
1 Commits
main
...
7d329bd9c8
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d329bd9c8 |
70
agent-cmd.sh
70
agent-cmd.sh
@@ -1,70 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Detect available agents, prompt with fzf, run the selected one.
|
|
||||||
# Detaches the client if all panes in the window are dead afterwards.
|
|
||||||
|
|
||||||
agents=()
|
|
||||||
command -v claude &>/dev/null && agents+=(claude)
|
|
||||||
command -v opencode &>/dev/null && agents+=(opencode)
|
|
||||||
command -v agy &>/dev/null && agents+=(agy)
|
|
||||||
command -v codex &>/dev/null && agents+=(codex)
|
|
||||||
|
|
||||||
if [ ${#agents[@]} -eq 0 ]; then
|
|
||||||
echo "No agent commands found (claude, opencode, gemini)"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# This runs as the window's default-command, which tmux starts *before* the
|
|
||||||
# popup client attaches. Until then the pane keeps a stale default size (often
|
|
||||||
# 80x24), so wait for the attach before measuring — otherwise fzf is sized
|
|
||||||
# against the wrong dimensions and renders far too small.
|
|
||||||
for _ in $(seq 1 100); do
|
|
||||||
[ "$(tmux display-message -p '#{session_attached}')" -gt 0 ] && break
|
|
||||||
sleep 0.02
|
|
||||||
done
|
|
||||||
|
|
||||||
# Minimize fzf prompt size while centering it, using the real pane dimensions.
|
|
||||||
width=24
|
|
||||||
height=$((${#agents[@]} + 6))
|
|
||||||
cols=$(tmux display-message -p '#{pane_width}')
|
|
||||||
lines=$(tmux display-message -p '#{pane_height}')
|
|
||||||
hmargin=$(((cols - width) / 2))
|
|
||||||
vpad=$(((lines - height) / 2))
|
|
||||||
[ $hmargin -lt 0 ] && hmargin=0
|
|
||||||
[ $vpad -lt 0 ] && vpad=0
|
|
||||||
tput cup "$vpad" 0
|
|
||||||
|
|
||||||
agent=$(printf '%s\n' "${agents[@]}" | fzf \
|
|
||||||
--prompt='agent> ' \
|
|
||||||
--reverse \
|
|
||||||
--border=rounded \
|
|
||||||
--height="$height" \
|
|
||||||
--margin="0,$hmargin" \
|
|
||||||
--padding=1)
|
|
||||||
|
|
||||||
# Reset cursor so the agent doesn't render starting where fzf left it.
|
|
||||||
tput cup 0 0
|
|
||||||
tput ed
|
|
||||||
|
|
||||||
if [ -n "$agent" ]; then
|
|
||||||
"$agent" || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Brief delay to let tmux update pane status
|
|
||||||
sleep 0.1
|
|
||||||
|
|
||||||
window_id=$(tmux display-message -p '#{window_id}')
|
|
||||||
my_pane=$(tmux display-message -p '#{pane_id}')
|
|
||||||
|
|
||||||
# Count live sibling panes (not us, not dead)
|
|
||||||
other_live=$(tmux list-panes -t "$window_id" -F '#{pane_id} #{pane_dead}' \
|
|
||||||
| awk -v me="$my_pane" '$1 != me && $2 == "0"' | wc -l | tr -d ' ')
|
|
||||||
|
|
||||||
if [ "$other_live" -eq 0 ]; then
|
|
||||||
# No live siblings — close the popup and kill the window
|
|
||||||
# (also cleans up any dead siblings).
|
|
||||||
tmux detach-client
|
|
||||||
tmux kill-window -t "$window_id" 2>/dev/null || true
|
|
||||||
else
|
|
||||||
# User has split off other live panes — only kill ours, keep popup open.
|
|
||||||
tmux kill-pane 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
47
agent.sh
47
agent.sh
@@ -2,56 +2,39 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
# Get the directory passed as argument (from #{pane_current_path})
|
||||||
|
dir="${1:-$HOME}"
|
||||||
# Use the current directory (set via display-popup -d)
|
|
||||||
dir="${PWD:-$HOME}"
|
|
||||||
# Use the directory basename as window name
|
# Use the directory basename as window name
|
||||||
window_name=$dir
|
window_name="$(basename "$dir")"
|
||||||
|
session_name="agent"
|
||||||
|
|
||||||
# Create the agent session if it doesn't exist
|
# Create the agent session if it doesn't exist
|
||||||
if ! tmux has-session -t agent; then
|
if ! tmux has-session -t "$session_name" 2>/dev/null; then
|
||||||
tmux new-session -ds agent -c "$dir" -n "$window_name" "$script_dir/agent-cmd.sh"
|
tmux new-session -ds "$session_name" -c "$dir" -n "$window_name" claude
|
||||||
# Store the directory in a window option for later matching
|
# Store the directory in a window option for later matching
|
||||||
tmux set-window-option -t agent @agent_dir "$dir"
|
tmux set-window-option -t "$session_name" @agent_dir "$dir"
|
||||||
|
tmux attach-session -t "$session_name"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Apply session options on every invocation so updates propagate to live sessions
|
|
||||||
tmux set-option -t agent status off
|
|
||||||
tmux set-option -t agent remain-on-exit on
|
|
||||||
tmux set-option -t agent default-command "$script_dir/agent-cmd.sh"
|
|
||||||
|
|
||||||
# Search for an existing window with matching directory
|
# Search for an existing window with matching directory
|
||||||
target_window=""
|
target_window=""
|
||||||
for window_id in $(tmux list-windows -t agent -F '#{window_id}'); do
|
while IFS=$'\t' read -r window_id window_dir; do
|
||||||
window_dir=$(tmux show-window-option -t "$window_id" -v @agent_dir 2>/dev/null || true)
|
|
||||||
if [ "$window_dir" = "$dir" ]; then
|
if [ "$window_dir" = "$dir" ]; then
|
||||||
target_window="$window_id"
|
target_window="$window_id"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done < <(tmux list-windows -t "$session_name" -F '#{window_id} #{@agent_dir}')
|
||||||
|
|
||||||
if [ -n "$target_window" ]; then
|
if [ -n "$target_window" ]; then
|
||||||
# Select the existing window
|
# Select the existing window
|
||||||
tmux select-window -t "$target_window"
|
tmux select-window -t "$target_window"
|
||||||
else
|
else
|
||||||
# Create a new window; default-command runs agent-cmd.sh
|
# Create a new window with claude
|
||||||
tmux new-window -t agent -c "$dir" -n "$window_name"
|
tmux new-window -t "$session_name" -n "$window_name" -c "$dir" claude
|
||||||
# Store the directory in a window option for later matching
|
# Store the directory in a window option for later matching
|
||||||
tmux set-window-option -t agent @agent_dir "$dir"
|
tmux set-window-option -t "$session_name" @agent_dir "$dir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Prune windows whose recorded directory no longer exists. This runs after the
|
|
||||||
# current directory's window is guaranteed to exist, so the session always
|
|
||||||
# keeps at least one live window and is never killed out from under us.
|
|
||||||
for window_id in $(tmux list-windows -t agent -F '#{window_id}'); do
|
|
||||||
window_dir=$(tmux show-window-option -t "$window_id" -v @agent_dir 2>/dev/null || true)
|
|
||||||
# Skip windows with no recorded directory rather than risk pruning them.
|
|
||||||
[ -n "$window_dir" ] || continue
|
|
||||||
if [ ! -d "$window_dir" ]; then
|
|
||||||
tmux kill-window -t "$window_id" 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Attach to the session
|
# Attach to the session
|
||||||
tmux attach-session -t agent
|
tmux attach-session -t "$session_name"
|
||||||
|
|||||||
117
check-version.sh
117
check-version.sh
@@ -1,29 +1,13 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Compare the current tmux version against one or more version constraints.
|
# Compare the current tmux version against a given version.
|
||||||
#
|
# Exit: 0 if comparison is true, 1 if false
|
||||||
# Each constraint pairs an operator and version in a single argument,
|
|
||||||
# e.g. ">= 3.2". Multiple constraints can be joined with the logical operators
|
|
||||||
# `and` / `or`, where `and` binds tighter than `or` (standard precedence). This
|
|
||||||
# allows a single invocation to express a range without spawning the script
|
|
||||||
# multiple times.
|
|
||||||
#
|
|
||||||
# Exit: 0 if the whole expression is true, 1 if false
|
|
||||||
#
|
|
||||||
# Examples:
|
|
||||||
# check-version.sh ">= 3.2"
|
|
||||||
# check-version.sh ">= 3.2" and "< 3.3"
|
|
||||||
# check-version.sh "< 2.9" or ">= 3.4"
|
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat >&2 <<'EOF'
|
echo "usage: $0 <operator> <version>" >&2
|
||||||
usage: check-version.sh <constraint> [and|or <constraint> ...]
|
echo "operators: < <= == >= >" >&2
|
||||||
constraint: <operator> <version>, e.g. ">= 3.2"
|
|
||||||
operators: < <= == >= >
|
|
||||||
logical: and or (and binds tighter than or)
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then
|
if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then
|
||||||
@@ -31,11 +15,14 @@ if [[ ${1:-} == "-h" || ${1:-} == "--help" ]]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $# -eq 0 ]]; then
|
if [[ $# -ne 2 ]]; then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
operator="$1"
|
||||||
|
target_version="$2"
|
||||||
|
|
||||||
# Extract tmux version (e.g., "tmux 3.3a" -> "3.3a")
|
# Extract tmux version (e.g., "tmux 3.3a" -> "3.3a")
|
||||||
current_version=$(tmux -V | sed 's/^tmux //')
|
current_version=$(tmux -V | sed 's/^tmux //')
|
||||||
|
|
||||||
@@ -88,78 +75,22 @@ compare_versions() {
|
|||||||
echo 0
|
echo 0
|
||||||
}
|
}
|
||||||
|
|
||||||
# Evaluate a single constraint (e.g. ">= 3.2") against the current version.
|
result=$(compare_versions "$current_version" "$target_version")
|
||||||
# Returns 0 (true) or 1 (false); exits on a malformed constraint.
|
|
||||||
eval_constraint() {
|
|
||||||
local constraint="$1"
|
|
||||||
local operator version
|
|
||||||
read -r operator version <<< "$constraint"
|
|
||||||
|
|
||||||
if [[ -z "$operator" || -z "$version" ]]; then
|
case "$operator" in
|
||||||
echo "error: invalid constraint: '$constraint' (expected '<operator> <version>', e.g. '>= 3.2')" >&2
|
'<')
|
||||||
|
[[ "$result" -eq -1 ]] && exit 0 || exit 1 ;;
|
||||||
|
'<=')
|
||||||
|
[[ "$result" -le 0 ]] && exit 0 || exit 1 ;;
|
||||||
|
'==')
|
||||||
|
[[ "$result" -eq 0 ]] && exit 0 || exit 1 ;;
|
||||||
|
'>=')
|
||||||
|
[[ "$result" -ge 0 ]] && exit 0 || exit 1 ;;
|
||||||
|
'>')
|
||||||
|
[[ "$result" -eq 1 ]] && exit 0 || exit 1 ;;
|
||||||
|
*)
|
||||||
|
echo "error: invalid operator: $operator" >&2
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
local result
|
|
||||||
result=$(compare_versions "$current_version" "$version")
|
|
||||||
|
|
||||||
case "$operator" in
|
|
||||||
'<') [[ "$result" -eq -1 ]] ;;
|
|
||||||
'<=') [[ "$result" -le 0 ]] ;;
|
|
||||||
'==') [[ "$result" -eq 0 ]] ;;
|
|
||||||
'>=') [[ "$result" -ge 0 ]] ;;
|
|
||||||
'>') [[ "$result" -eq 1 ]] ;;
|
|
||||||
*)
|
|
||||||
echo "error: invalid operator: '$operator'" >&2
|
|
||||||
usage
|
|
||||||
exit 1 ;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# Walk the alternating constraint/logical sequence, accumulating each `and`
|
|
||||||
# group (1 = true) and folding completed groups into the `or` result. Truth
|
|
||||||
# values are tracked as ints and converted to an exit code at the end.
|
|
||||||
or_result=0
|
|
||||||
and_result=1
|
|
||||||
expect=constraint
|
|
||||||
|
|
||||||
for token in "$@"; do
|
|
||||||
if [[ "$expect" == "constraint" ]]; then
|
|
||||||
case "$token" in
|
|
||||||
and | or)
|
|
||||||
echo "error: expected a constraint, got logical operator: $token" >&2
|
|
||||||
usage
|
|
||||||
exit 1 ;;
|
|
||||||
esac
|
|
||||||
if eval_constraint "$token"; then
|
|
||||||
and_result=$(( and_result & 1 ))
|
|
||||||
else
|
|
||||||
and_result=$(( and_result & 0 ))
|
|
||||||
fi
|
|
||||||
expect=logical
|
|
||||||
else
|
|
||||||
case "$token" in
|
|
||||||
and)
|
|
||||||
;;
|
|
||||||
or)
|
|
||||||
or_result=$(( or_result | and_result ))
|
|
||||||
and_result=1 ;;
|
|
||||||
*)
|
|
||||||
echo "error: expected 'and' or 'or', got: $token" >&2
|
|
||||||
usage
|
|
||||||
exit 1 ;;
|
|
||||||
esac
|
|
||||||
expect=constraint
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ "$expect" == "constraint" ]]; then
|
|
||||||
echo "error: expression ends with a logical operator" >&2
|
|
||||||
usage
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
or_result=$(( or_result | and_result ))
|
|
||||||
|
|
||||||
[[ "$or_result" -eq 1 ]] && exit 0 || exit 1
|
|
||||||
|
|||||||
@@ -2,14 +2,8 @@
|
|||||||
|
|
||||||
session_name=$(tmux display-message -p '#S')
|
session_name=$(tmux display-message -p '#S')
|
||||||
session_layout=~/.local/share/tmux/layouts/session-$session_name
|
session_layout=~/.local/share/tmux/layouts/session-$session_name
|
||||||
# Set by `session -p <project>`, which names the session after the project but
|
|
||||||
# can't be relied on for the lookup above since tmux rewrites `.` in names.
|
|
||||||
session_project=$(tmux show-environment -t "$session_name" TMUX_PROJECT 2>/dev/null |
|
|
||||||
sed -n 's/^TMUX_PROJECT=//p')
|
|
||||||
if [ -f $session_layout ]; then
|
if [ -f $session_layout ]; then
|
||||||
$session_layout
|
$session_layout
|
||||||
elif [ -n "$session_project" ]; then
|
|
||||||
~/.local/share/tmux/layouts/session-project "$session_project"
|
|
||||||
elif [ "$session_name" != "agent" ]; then
|
elif [ "$session_name" != "agent" ]; then
|
||||||
tmux rename-window home
|
tmux rename-window home
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ symlink $HOME/.config/tmux/layouts/session-infra \
|
|||||||
$HOME/.local/share/tmux/layouts/session-infra
|
$HOME/.local/share/tmux/layouts/session-infra
|
||||||
symlink $HOME/.config/tmux/layouts/session-main \
|
symlink $HOME/.config/tmux/layouts/session-main \
|
||||||
$HOME/.local/share/tmux/layouts/session-main
|
$HOME/.local/share/tmux/layouts/session-main
|
||||||
symlink $HOME/.config/tmux/layouts/session-project \
|
|
||||||
$HOME/.local/share/tmux/layouts/session-project
|
|
||||||
symlink $HOME/.config/tmux/layouts/session-visor \
|
symlink $HOME/.config/tmux/layouts/session-visor \
|
||||||
$HOME/.local/share/tmux/layouts/session-visor
|
$HOME/.local/share/tmux/layouts/session-visor
|
||||||
symlink $HOME/.config/tmux/layouts/session-work \
|
symlink $HOME/.config/tmux/layouts/session-work \
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ tmux new-window -c ~/.config/tmux
|
|||||||
tmux rename-window config/tmux
|
tmux rename-window config/tmux
|
||||||
`dirname $0`/window-auto
|
`dirname $0`/window-auto
|
||||||
|
|
||||||
tmux new-window -c ~/.config/git
|
|
||||||
tmux rename-window config/git
|
|
||||||
`dirname $0`/window-auto
|
|
||||||
|
|
||||||
if [ -d ~/.config/work ]; then
|
if [ -d ~/.config/work ]; then
|
||||||
tmux new-window -c ~/.config/work
|
tmux new-window -c ~/.config/work
|
||||||
tmux rename-window config/work
|
tmux rename-window config/work
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
#!/usr/bin/env zsh
|
|
||||||
|
|
||||||
# usage: session-project <project>
|
|
||||||
#
|
|
||||||
# Layout for a session created by `session -p <project>`, where <project> is a
|
|
||||||
# path in ~/Projects with the prefix removed. The session-created hook passes
|
|
||||||
# the project along, taking it from the session environment.
|
|
||||||
|
|
||||||
project=$1
|
|
||||||
repo=$HOME/Projects/$project
|
|
||||||
|
|
||||||
tmux rename-window home
|
|
||||||
$(dirname $0)/window-auto
|
|
||||||
|
|
||||||
# Without a project there is nothing but the home window, which is all a
|
|
||||||
# session created directly from this layout's name can get.
|
|
||||||
if [[ -z "$project" ]] || ! git -C "$repo" rev-parse --git-dir &>/dev/null; then
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
# The remote's default branch, falling back to whatever HEAD points at for
|
|
||||||
# repositories without an origin/HEAD, e.g. those with no remote at all.
|
|
||||||
branch=$(git -C "$repo" symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null)
|
|
||||||
branch=${branch#origin/}
|
|
||||||
if [[ -z "$branch" ]]; then
|
|
||||||
branch=$(git -C "$repo" symbolic-ref --short HEAD 2>/dev/null)
|
|
||||||
fi
|
|
||||||
if [[ -z "$branch" ]]; then
|
|
||||||
# Detached HEAD, name the window after the commit it sits on.
|
|
||||||
branch=$(git -C "$repo" rev-parse --short HEAD 2>/dev/null)
|
|
||||||
fi
|
|
||||||
|
|
||||||
tmux new-window -c "$repo"
|
|
||||||
tmux rename-window "$branch"
|
|
||||||
$(dirname $0)/window-auto
|
|
||||||
117
project.sh
117
project.sh
@@ -2,112 +2,19 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
projects_dir=$HOME/Projects
|
projects=()
|
||||||
|
|
||||||
# Print the sorted, de-duplicated list of selectable projects.
|
# Get list of projects from ~/Projects
|
||||||
list_projects() {
|
for dir in $HOME/Projects/**/*; do
|
||||||
local projects=() dir relative git_dirs kept_roots=() root kept
|
if [ -d $dir ]; then
|
||||||
|
projects+=(${dir#$HOME/Projects/})
|
||||||
# All depth-2 directories without @ are included unconditionally
|
|
||||||
for dir in "$projects_dir"/*/*/; do
|
|
||||||
[ -d "$dir" ] || continue
|
|
||||||
relative="${dir#$projects_dir/}"
|
|
||||||
relative="${relative%/}"
|
|
||||||
[[ "$relative" != *@* ]] && projects+=("$relative")
|
|
||||||
done
|
|
||||||
|
|
||||||
# For @ directories, only show the top-most directory that holds a .git
|
|
||||||
# entry. Sorting makes every parent precede its descendants, so once a root
|
|
||||||
# is kept we drop anything nested beneath it — typically a git submodule —
|
|
||||||
# while separate clones and worktrees, each in their own directory, survive.
|
|
||||||
if command -v fd &>/dev/null; then
|
|
||||||
git_dirs=$(fd -H '^\.git$' "$projects_dir" || true)
|
|
||||||
else
|
|
||||||
git_dirs=$(find "$projects_dir" \( -name 'node_modules' -o -name '.git' \) \
|
|
||||||
-prune -name '.git' -print || true)
|
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
while IFS= read -r root; do
|
project=$(
|
||||||
for kept in "${kept_roots[@]}"; do
|
echo "${projects[@]}" | tr ' ' '\n' | sort -u |
|
||||||
if [[ "$root" == "$kept/"* ]]; then
|
fzf --layout=reverse --info=hidden --border=rounded --cycle
|
||||||
continue 2
|
)
|
||||||
fi
|
|
||||||
done
|
|
||||||
kept_roots+=("$root")
|
|
||||||
projects+=("$root")
|
|
||||||
done < <(printf '%s\n' "$git_dirs" |
|
|
||||||
grep '@' |
|
|
||||||
sed -E -e "s|^$projects_dir/||" -e 's|/\.git/?$||' |
|
|
||||||
sort -u)
|
|
||||||
|
|
||||||
printf '%s\n' "${projects[@]}" | sort -u
|
tmux new-window -n $project -c ~/Projects/$project
|
||||||
}
|
~/.local/share/tmux/layouts/window-auto
|
||||||
|
|
||||||
# Second pass: runs inside the popup. Read the list the first pass already
|
|
||||||
# built (so the directory scan only happens once) and open the selection.
|
|
||||||
if [[ "${1:-}" == --pick ]]; then
|
|
||||||
listfile=$2
|
|
||||||
trap 'rm -f "$listfile"' EXIT
|
|
||||||
|
|
||||||
# Cancelling fzf (Esc/^C) exits non-zero; treat it as "no selection" and
|
|
||||||
# leave quietly, rather than letting the status propagate out of the popup
|
|
||||||
# and print '...project.sh returned 130' in the parent pane.
|
|
||||||
project=$(
|
|
||||||
fzf --layout=reverse --info=hidden --border=rounded --cycle < "$listfile"
|
|
||||||
) || exit 0
|
|
||||||
[ -n "$project" ] || exit 0
|
|
||||||
|
|
||||||
# Inside a session for this same project, e.g. one created by `session -p`,
|
|
||||||
# the slug only repeats the session name, so name the window after the branch
|
|
||||||
# checked out there instead — a worktree's whole identity. Everything up to
|
|
||||||
# the `@` is the clone the worktrees hang off, and tmux rewrote `.` and `:` in
|
|
||||||
# the session name, so match both before comparing.
|
|
||||||
window_name=$project
|
|
||||||
session=$(tmux display -p '#S')
|
|
||||||
root=${project%%@*}
|
|
||||||
if [ "${root//[.:]/_}" = "$session" ]; then
|
|
||||||
branch=$(git -C "$projects_dir/$project" symbolic-ref --short HEAD 2>/dev/null ||
|
|
||||||
git -C "$projects_dir/$project" rev-parse --short HEAD 2>/dev/null || true)
|
|
||||||
window_name=${branch:-$project}
|
|
||||||
fi
|
|
||||||
|
|
||||||
tmux new-window -n "$window_name" -c "$projects_dir/$project"
|
|
||||||
~/.local/share/tmux/layouts/window-auto
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
# First pass: scan once, size a popup to fit the longest project name, then
|
|
||||||
# re-launch ourselves inside it. fzf has no width of its own — it fills the
|
|
||||||
# popup — so the popup width is what we scale.
|
|
||||||
listfile=$(mktemp)
|
|
||||||
list_projects > "$listfile"
|
|
||||||
|
|
||||||
longest=0
|
|
||||||
while IFS= read -r line; do
|
|
||||||
if (( ${#line} > longest )); then
|
|
||||||
longest=${#line}
|
|
||||||
fi
|
|
||||||
done < "$listfile"
|
|
||||||
|
|
||||||
# We're launched from run-shell, which owns no client, so resolve the client
|
|
||||||
# that triggered us. It both anchors the popup (-c, without which the popup
|
|
||||||
# gets no tty and fzf can't draw) and gives the terminal width for the cap.
|
|
||||||
client=$(tmux display -p '#{client_name}')
|
|
||||||
cols=$(tmux display -p -c "$client" '#{client_width}')
|
|
||||||
|
|
||||||
# Clamp between the original fixed width and 90% of the terminal. In between,
|
|
||||||
# pad for fzf's chrome: rounded border (2) + pointer gutter (2) + scrollbar (1)
|
|
||||||
# + a column of breathing room.
|
|
||||||
min=60
|
|
||||||
max=$(( cols * 90 / 100 ))
|
|
||||||
width=$(( longest + 6 ))
|
|
||||||
(( width < min )) && width=$min
|
|
||||||
(( width > max )) && width=$max
|
|
||||||
|
|
||||||
flags=(-c "$client" -w "$width" -h 10)
|
|
||||||
# Match the borderless popup the keybinding used on tmux >= 3.3.
|
|
||||||
if ~/.config/tmux/check-version.sh ">= 3.3"; then
|
|
||||||
flags+=(-B)
|
|
||||||
fi
|
|
||||||
|
|
||||||
tmux display-popup "${flags[@]}" -E "'$0' --pick '$listfile'"
|
|
||||||
|
|||||||
@@ -4,12 +4,9 @@ set -e
|
|||||||
|
|
||||||
sessions=()
|
sessions=()
|
||||||
|
|
||||||
# Get list of predefined session layouts, skipping session-project since it is
|
# Get list of predefined session layouts
|
||||||
# parameterized by `session -p <project>` rather than a session of its own
|
|
||||||
for item in $HOME/.local/share/tmux/layouts/session-*; do
|
for item in $HOME/.local/share/tmux/layouts/session-*; do
|
||||||
layout=${item#$HOME/.local/share/tmux/layouts/session-}
|
sessions+=(${item#$HOME/.local/share/tmux/layouts/session-})
|
||||||
[ "$layout" = project ] && continue
|
|
||||||
sessions+=($layout)
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Get list of existing sessions
|
# Get list of existing sessions
|
||||||
|
|||||||
@@ -3,10 +3,7 @@ if -b '[ "$WSL_DISTRO_NAME" != "" ]' \
|
|||||||
'setw -g status-left " #(hostname)|#{WSL_DISTRO_NAME}|#{session_name}"' \
|
'setw -g status-left " #(hostname)|#{WSL_DISTRO_NAME}|#{session_name}"' \
|
||||||
'setw -g status-left " #(hostname -s)|#{session_name}"'
|
'setw -g status-left " #(hostname -s)|#{session_name}"'
|
||||||
setw -g status-left-style fg=colour240,bg=colour233
|
setw -g status-left-style fg=colour240,bg=colour233
|
||||||
# Only a maximum, and the component is never padded out to it, so leave room
|
setw -g status-left-length 32
|
||||||
# for the hostname beside a full session name: project sessions are named after
|
|
||||||
# a path, e.g. modularml/modular@benie/some-branch.
|
|
||||||
setw -g status-left-length 100
|
|
||||||
|
|
||||||
# Centre status style
|
# Centre status style
|
||||||
setw -g status-style fg=colour240,bg=colour233
|
setw -g status-style fg=colour240,bg=colour233
|
||||||
|
|||||||
58
tmux.conf
58
tmux.conf
@@ -28,13 +28,10 @@ set -g status-interval 2
|
|||||||
set -g default-terminal "tmux-256color"
|
set -g default-terminal "tmux-256color"
|
||||||
|
|
||||||
# Enable true-color
|
# Enable true-color
|
||||||
if '~/.config/tmux/check-version.sh "< 3.2"' \
|
if '~/.config/tmux/check-version.sh "<" 3.2' \
|
||||||
'set-option -as terminal-features ",xterm*:Tc"' \
|
'set-option -as terminal-features ",xterm*:Tc"' \
|
||||||
'set-option -as terminal-features ",xterm*:RGB"'
|
'set-option -as terminal-features ",xterm*:RGB"'
|
||||||
|
|
||||||
# Declare clipboard (OSC-52) support so tmux emits it for copy-pipe.
|
|
||||||
set -as terminal-features ',xterm*:clipboard'
|
|
||||||
|
|
||||||
# Focus events enabled for terminals that support them
|
# Focus events enabled for terminals that support them
|
||||||
set -g focus-events on
|
set -g focus-events on
|
||||||
|
|
||||||
@@ -52,7 +49,7 @@ unbind -T copy-mode-vi MouseDragEnd1Pane
|
|||||||
# Enable changing cursor shape per pane, vim or zsh should emit escape
|
# Enable changing cursor shape per pane, vim or zsh should emit escape
|
||||||
# sequences to change cursor shape.
|
# sequences to change cursor shape.
|
||||||
# iTerm2 only requires this before tmux 2.9
|
# iTerm2 only requires this before tmux 2.9
|
||||||
if '[ -n $ITERM_PROFILE ] && ~/.config/tmux/check-version.sh "< 2.9"' \
|
if '[ -n $ITERM_PROFILE ] && ~/.config/tmux/check-version.sh "<" 2.9' \
|
||||||
'set -ga terminal-overrides "*:Ss=\E]1337;CursorShape=%p1%d\7"'
|
'set -ga terminal-overrides "*:Ss=\E]1337;CursorShape=%p1%d\7"'
|
||||||
# VTE compatible terminals.
|
# VTE compatible terminals.
|
||||||
if '[ ! -n $ITERM_PROFILE ]' \
|
if '[ ! -n $ITERM_PROFILE ]' \
|
||||||
@@ -61,28 +58,26 @@ if '[ ! -n $ITERM_PROFILE ]' \
|
|||||||
# Enable strikethrough on VTE compatible terminals.
|
# Enable strikethrough on VTE compatible terminals.
|
||||||
set -ga terminal-overrides 'xterm*:smxx=\E[9m'
|
set -ga terminal-overrides 'xterm*:smxx=\E[9m'
|
||||||
|
|
||||||
if -b '~/.config/tmux/check-version.sh ">= 3.2" and "< 3.3"' {
|
# Binding to create window-auto layout
|
||||||
bind A if -F '#{==:#{session_name},agent}' { detach-client } {
|
bind a run-shell ~/.local/share/tmux/layouts/window-auto
|
||||||
display-popup -d '#{pane_current_path}' -w 50% -h 90% -E ~/.config/tmux/agent.sh
|
# TODO: bind A run-shell ~/.local/share/tmux/layouts/window-auto --refresh
|
||||||
}
|
|
||||||
bind H display-popup -w 75% -h 75% -E htop
|
|
||||||
bind I display-popup -d '#{pane_current_path}' -E ~/.config/tmux/interpreter.sh
|
|
||||||
bind N display-popup -d '#{pane_current_path}' -w 60% -h 75% -E nvim
|
|
||||||
bind S display-popup -w 60 -h 10 -E ~/.config/tmux/session.sh
|
|
||||||
bind T display-popup -d '#{pane_current_path}' -E $SHELL
|
|
||||||
}
|
|
||||||
if -b '~/.config/tmux/check-version.sh ">= 3.3"' {
|
|
||||||
bind A if -F '#{==:#{session_name},agent}' { detach-client } {
|
|
||||||
display-popup -S fg=#54546D -b rounded -d '#{pane_current_path}' -w 75% -h 90% -E ~/.config/tmux/agent.sh
|
|
||||||
}
|
|
||||||
bind H display-popup -S fg=#54546D -b rounded -w 50% -h 75% -E htop
|
|
||||||
bind I display-popup -S fg=#54546D -b rounded -d '#{pane_current_path}' -E ~/.config/tmux/interpreter.sh
|
|
||||||
bind N display-popup -S fg=#54546D -b rounded -d '#{pane_current_path}' -w 60% -h 75% -E nvim
|
|
||||||
bind S display-popup -B -w 60 -h 10 -E ~/.config/tmux/session.sh
|
|
||||||
bind T display-popup -S fg=#54546D -d '#{pane_current_path}' -E $SHELL
|
|
||||||
}
|
|
||||||
|
|
||||||
bind P run-shell ~/.config/tmux/project.sh
|
# Set only on macOS where it's required
|
||||||
|
if -b '[ "`uname`" = "Darwin" ]' \
|
||||||
|
'set -g default-command "reattach-to-user-namespace -l $SHELL"'
|
||||||
|
|
||||||
|
if -b '~/.config/tmux/check-version.sh ">" 3.2' {
|
||||||
|
# Open a popup with running the default shell
|
||||||
|
bind T display-popup -S fg=#54546D -b rounded -d '#{pane_current_path}' -E $SHELL
|
||||||
|
# Open a popup with session creator/switcher
|
||||||
|
bind S display-popup -B -w 60 -h 10 -E '~/.config/tmux/session.sh'
|
||||||
|
# Open a popup with project selector
|
||||||
|
bind P display-popup -B -w 60 -h 10 -E '~/.config/tmux/project.sh'
|
||||||
|
# Open a popup to pick an interpreter then launch it
|
||||||
|
bind I display-popup -S fg=#54546D -b rounded -d '#{pane_current_path}' -E '$SHELL -i ~/.config/tmux/interpreter.sh'
|
||||||
|
# Open a popup with AI agent session for current directory
|
||||||
|
bind A display-popup -S fg=#54546D -b rounded -w 90% -h 90% -E '~/.config/tmux/agent.sh "#{pane_current_path}"'
|
||||||
|
}
|
||||||
|
|
||||||
# Restore old next/previous window bindings
|
# Restore old next/previous window bindings
|
||||||
bind C-n next-window
|
bind C-n next-window
|
||||||
@@ -159,13 +154,12 @@ if -b '[ "$SSH_TTY" != "" ]' \
|
|||||||
'set-option -g set-clipboard on'
|
'set-option -g set-clipboard on'
|
||||||
|
|
||||||
# Yank to the system clipboard in copy mode.
|
# Yank to the system clipboard in copy mode.
|
||||||
|
# TODO: reattach-to-user-namespace not necessary with tmux > 2.6
|
||||||
if -b '[ "`uname`" = "Darwin" ]' \
|
if -b '[ "`uname`" = "Darwin" ]' \
|
||||||
'bind -T copy-mode-vi y send-keys -X copy-pipe "pbcopy"'
|
'bind -T copy-mode-vi y send-keys -X copy-pipe "reattach-to-user-namespace pbcopy"'
|
||||||
# When not in WSL2 use xsel, when in WSL use win32yank.exe to avoid UI lockups.
|
# When not in WSL2 use xsel, when in WSL use win32yank.exe to avoid UI lockups.
|
||||||
if -b '[ "`uname`" != "Darwin" ]' {
|
if -b '[ "$WSLENV" = "" ]' \
|
||||||
if -b '[ "$WSLENV" = "" ]' \
|
'bind -T copy-mode-vi y send-keys -X copy-pipe "xsel -i --clipboard"' \
|
||||||
'bind -T copy-mode-vi y send-keys -X copy-pipe "xsel -i --clipboard"' \
|
'bind -T copy-mode-vi y send-keys -X copy-pipe "win32yank.exe -i -crlf"'
|
||||||
'bind -T copy-mode-vi y send-keys -X copy-pipe "win32yank.exe -i -crlf"'
|
|
||||||
}
|
|
||||||
|
|
||||||
source-file ~/.config/tmux/theme.tmux
|
source-file ~/.config/tmux/theme.tmux
|
||||||
|
|||||||
Reference in New Issue
Block a user