feat: custom last working dir based on i3 desktop
to improve DX when multitasking
This commit is contained in:
32
files/workspace-term.sh
Normal file
32
files/workspace-term.sh
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/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}"
|
||||||
4
home.nix
4
home.nix
@@ -14,6 +14,10 @@
|
|||||||
source = ./files/stt-dictate.sh;
|
source = ./files/stt-dictate.sh;
|
||||||
executable = true;
|
executable = true;
|
||||||
};
|
};
|
||||||
|
home.file.".local/bin/workspace-term" = {
|
||||||
|
source = ./files/workspace-term.sh;
|
||||||
|
executable = true;
|
||||||
|
};
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
./packages.nix
|
./packages.nix
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
# see https://rycee.gitlab.io/home-manager/options.html#opt-xsession.windowManager.i3.config.keybindings
|
# see https://rycee.gitlab.io/home-manager/options.html#opt-xsession.windowManager.i3.config.keybindings
|
||||||
keybindings = pkgs.lib.mkOptionDefault {
|
keybindings = pkgs.lib.mkOptionDefault {
|
||||||
"${modifier}+Return" = "exec sakura"; # i3-sensible-terminal
|
"${modifier}+Return" = "exec ~/.local/bin/workspace-term";
|
||||||
|
|
||||||
### BÉPO ###
|
### BÉPO ###
|
||||||
"${modifier}+b" = "kill";
|
"${modifier}+b" = "kill";
|
||||||
|
|||||||
@@ -25,7 +25,6 @@
|
|||||||
"fasd"
|
"fasd"
|
||||||
"git"
|
"git"
|
||||||
"httpie"
|
"httpie"
|
||||||
"last-working-dir"
|
|
||||||
"pass"
|
"pass"
|
||||||
"ssh-agent"
|
"ssh-agent"
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user