Files
dotfiles/files/workspace-term.sh
Pierre Martin 60d4342e83 feat: custom last working dir based on i3 desktop
to improve DX when multitasking
2026-03-18 16:09:22 +01:00

33 lines
879 B
Bash

#!/usr/bin/env bash
workspace=$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused) | .name')
# Cherche le dossier courant d'un terminal déjà ouvert sur ce bureau
terminal_cwd() {
local wids
wids=$(i3-msg -t get_tree | jq -r "
.nodes[].nodes[].nodes[]
| select(.name == \"$workspace\")
| .. | objects | select(.window? != null) | .window
")
for wid in $wids; do
local pid
pid=$(xdotool getwindowpid "$wid" 2>/dev/null) || continue
local shell_pid
shell_pid=$(pgrep -P "$pid" -x zsh | head -1) || continue
local cwd
cwd=$(readlink "/proc/$shell_pid/cwd" 2>/dev/null) || continue
echo "$cwd"
return
done
}
dir=$(terminal_cwd)
if [ -z "$dir" ]; then
dir_file="$HOME/.config/i3/workspace-dirs"
dir=$(grep "^${workspace}=" "$dir_file" 2>/dev/null | cut -d= -f2-)
fi
exec sakura --working-directory "${dir:-$HOME}"