feat: généraliser workspace-run pour ouvrir terminal ou éditeur dans le dossier du workspace
- Remplace workspace-term.sh par workspace-run.sh (commande en paramètre) - mod+Return → sakura, mod+Shift+Return → zeditor Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
38
files/workspace-run.sh
Normal file
38
files/workspace-run.sh
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
# Usage: workspace-run.sh <command> [args...] -- dir is appended as last argument
|
||||
# Examples:
|
||||
# workspace-run.sh zeditor
|
||||
# workspace-run.sh sakura --working-directory
|
||||
cmd=${1:?usage: workspace-run.sh <command> [args...]}
|
||||
shift
|
||||
|
||||
workspace=$(i3-msg -t get_workspaces | jq -r '.[] | select(.focused) | .name')
|
||||
|
||||
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 "$cmd" "$@" "${dir:-$HOME}"
|
||||
Reference in New Issue
Block a user