Open mkaito opened 6 years ago
This also doesn't work on GuixSD, likely for the same reasons since the distros are similar. I haven't done anything advanced trying to get it to work. I just did my usual steps and noticed that the bind to save a session did nothing visually. Hopefully someone interested can get this working on both distros. I think they are the future of GNU/Linux, so I'd love it if I could carry over the workflow I'm used to.
This plugin works for me on NixOS with the following home-manager config:
{
home-manager.users.austin = { pkgs, ... }: {
programs.tmux = {
enable = true;
plugins = with pkgs.tmuxPlugins; [{
plugin = resurrect;
extraConfig = "set -g @resurrect-strategy-nvim 'session'";
}];
};
};
}
For me this worked:
~/.tmux.conf
resurrect_dir="~/.local/share/tmux/resurrect"
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @resurrect-strategy-vim 'session'
set -g @resurrect-strategy-nvim 'session'
set -g @resurrect-processes 'vim nvim hx cat less more tail watch'
set -g @resurrect-dir $resurrect_dir
set -g @resurrect-hook-post-save-all '~/.tmux/post_save.sh $resurrect_dir/last'
~/.tmux/post_save.sh
sed -ie "s| --cmd .*-vim-pack-dir||g" $1
sed -i 's|fish :\[fish\] <defunct>|fish :|g' $1
sed -i ':a;N;$!ba;s|\[fish\] <defunct>\n||g' $1
sed -i "s|/run/current-system/sw/bin/||g" $1
sed -i "s| $HOME| ~|g" $1
sed -ie "s|:bash .*/tmp/nix-shell-.*/rc|:nix-shell|g" $1
I came across the same issue and the problem is with the way that tmux-resurrect saves the names of the process it later needs to resurrect, This issue is not specific to NixOS and is caused once the name of the process deviates from the one tmux-resurrect plugin expects when it parses its state file(file named last that points at some tmuxresurrect*).
I used a shorter version then the one suggested by @Gediminas , without the use of separate script and a bit safer with the use of "sponge".
{
plugin = resurrect;
extraConfig = ''
set -g @resurrect-capture-pane-contents 'on'
resurrect_dir="$HOME/.tmux/resurrect"
set -g @resurrect-dir $resurrect_dir
set -g @resurrect-hook-post-save-all 'target=$(readlink -f $resurrect_dir/last); sed "s| --cmd .*-vim-pack-dir||g; s|/etc/profiles/per-user/$USER/bin/||g" $target | sponge $target'
'';
}
For anyone still having issues: I don't know since when but putting the hook in 'single quotes' escapes the dollar sign so the variables do not get substituted. Putting them in "double quotes" seems to work.
Here my config:
{
plugin = resurrect;
extraConfig = # tmux
''
set -g @resurrect-processes 'ssh psql mysql sqlite3'
set -g @resurrect-strategy-nvim 'session'
resurrect_dir=~/.local/share/tmux/resurrect
set -g @resurrect-dir $resurrect_dir
set -g @resurrect-hook-post-save-all "sed -i 's| --cmd .*-vim-pack-dir||g; s|/etc/profiles/per-user/$USER/bin/||g' $(readlink -f $resurrect_dir/last)"
'';
}
I removed sponge because I don't really use that package and don't have it installed.
I'm not sure how to get this to work on NixOS, due to the way paths are handled on it.
I've got the following in my
tmux.conf
:When I create a test session with just one pane and an nvim session, these are the contents of
resurrect/last
:Which does not restore nvim. What am I doing wrong?
Of interest, might be this auto-generated wrapper that runs nvim on NixOS: