Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmux integration #79

Open
0fflineuser opened this issue Aug 17, 2024 · 0 comments
Open

tmux integration #79

0fflineuser opened this issue Aug 17, 2024 · 0 comments

Comments

@0fflineuser
Copy link

0fflineuser commented Aug 17, 2024

Hi!
I just did a little tmux script to load the sessions if anyone is interested.
Sorry if I shouldn't have posted it as an issue I didn't really know where to share it.

tmux-possession-nvim script :

#!/bin/bash
# Inspired by https://github.com/WaylonWalker/devtainer/blob/main/bin/.local/bin/ta

DIR="$HOME/.local/share/nvim/possession"

_session_name=$(find "$DIR" -maxdepth 1 -name '*.json' -type f -printf '%f\n' | sed 's/.json$//' | fzf --reverse --header="Select a neovim session >")
session_name=${_session_name//./_}

if [ -z "$session_name" ]; then
  exit 1
fi

not_in_tmux() {
  [ -z "$TMUX" ]
}

session_exists() {
  tmux has-session -t "=$session_name" 2>/dev/null
}

path_name=$(jq -r '.cwd' "$DIR/$_session_name.json")

create_if_needed_and_attach() {
  if not_in_tmux; then
    if ! session_exists; then
      tmux new-session -Ad -s "$session_name" -c $path_name
      tmux send-keys -t "$session_name" "nvim -c \":lua require('possession.session').load('$_session_name')\"" Enter
    fi
    tmux new-session -As "$session_name" -c $path_name
  else
    if ! session_exists; then
      tmux new-session -Ad -s "$session_name" -c $path_name
      tmux send-keys -t "$session_name" "nvim -c \":lua require('possession.session').load('$_session_name')\"" Enter
    fi
    tmux switch-client -t "$session_name"
  fi
}

create_if_needed_and_attach

Then add a keybind to your tmux configuration

bind M-n display-popup -E "tmux-possession-nvim"

Video demo :

demo.mp4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant