Skip to content

Commit

Permalink
feat: add zellij terminal session manager
Browse files Browse the repository at this point in the history
  • Loading branch information
aboqasem committed May 25, 2024
1 parent 8951b21 commit 45ea9e6
Show file tree
Hide file tree
Showing 7 changed files with 514 additions and 1 deletion.
3 changes: 3 additions & 0 deletions custom/aliases.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ alias cat='bat'
alias -g -- --help='--help 2>&1 | bat --language=help --style=plain'

alias lg=lazygit
# TODO: remove when fixed: https://github.com/zellij-org/zellij/issues/2764
alias zellij='zellij -l ~/.config/zellij/layouts/main.kdl'
alias zj=zellij

# Enable aliases to be sudo’ed
alias sudo='sudo '
Expand Down
44 changes: 44 additions & 0 deletions custom/functions.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,47 @@ function rmcap() {
function ret() {
cat /tmp/capture.out
}

# TODO: remove when fixed: https://github.com/zellij-org/zellij/issues/3151
function zj_fix() {
# replace panes like:
# pane command="/usr/local/bin/zsh" focus=true {
# args "-l"
# start_suspended true
# }
# with:
# pane

local layout_dump_file="$1"
if [[ ! -f "$layout_dump_file" ]]; then
echo "Layout dump file not found"
return 1
fi

local fixed=$(cat "$layout_dump_file" | sed -zE 's/pane command="[^"]*zsh" [^{]*\{[^}]*start_suspended true[^}]*\}/pane/g')
echo "$fixed" >"$layout_dump_file"
}

function zj_save() {
if [[ -z "$ZELLIJ" ]]; then
echo "Not in a Zellij session"
return 1
fi

local layout_dump_name="$(date +%Y-%m-%d-%H-%M-%S-%N).dump"
local layout_dump_file="$HOME/.config/zellij/layouts/$layout_dump_name.kdl"
echo "Saving layout to $layout_dump_file..."
command zellij action dump-layout >"$layout_dump_file"
zj_fix "$layout_dump_file"
local latest_layout_dump_file="$HOME/.config/zellij/layouts/latest.dump.kdl"
ln -sf "$layout_dump_file" "$latest_layout_dump_file"
}

function zj_restore() {
local latest_layout_dump_file="$HOME/.config/zellij/layouts/latest.dump.kdl"
if [[ ! -f "$latest_layout_dump_file" ]]; then
echo "No layout found"
return 1
fi
command zellij -l "$latest_layout_dump_file" $@
}
3 changes: 2 additions & 1 deletion setup/Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ brew 'gnu-sed'
brew 'zsh'
brew 'bash'

# Terminal session managers
brew 'zellij'
brew 'tmux'

# Install GnuPG to enable PGP-signing commits.
Expand All @@ -47,7 +49,6 @@ brew 'ripgrep'
brew 'gs'
brew 'imagemagick'
brew 'less'
brew 'nano'
brew 'postgresql'
brew 'rename'
brew 'shellcheck'
Expand Down
8 changes: 8 additions & 0 deletions syncconf.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
[".config/atuin", { type = "dir" }],
]

[[groups]]
name = "Zellij"
[[groups.items]]
type = "symlink"
paths = [
[".config/zellij", { type = "dir" }],
]

[[groups]]
name = "tmux"
[[groups.items]]
Expand Down
Loading

0 comments on commit 45ea9e6

Please sign in to comment.