Skip to main content
added 12 characters in body
Source Link
mike
  • 281
  • 1
  • 4
  • 10

I've found solution relying heavily on tmux. Since tmux is working independently of the shell and prevails even after closing the windows, one can prepare a tmux session and then attach to it. The thing won't instantly exit, since the attachment command does not return unless you exit it.

This and the fact that you can name and search a session yields the following Nautilus-Script:

#!/bin/bash
# nautilus script to start files in nvim under a tmux session
# place this script into ~/.local/share/nautilus/scripts/nvimOpen.sh
# presented without warranty by mike aka curvi

# nvim running in another session? -
# TODO tmux rename-session -t $whaever nvim

# Tmux session 'nvim' is running neovim always!
if tmux has-session -t nvim ; then
  # test if it is open and split it
  for selected_file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ; do
    tmux send-keys -t nvim Escape # change to normal mode
    tmux send-keys -t nvim ";vsp $selected_file" Enter # open file in vsplit
  done
else
  # or start it up freshly!
  tmux new-session -d -s nvim ;
  tmux send-keys -t nvim "nvim -O $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" Enter
  tmux send-keys -t nvim Escape # change to normal mode
fi
# after the tmux session is prepared - attach to it in gnome-terminal!
gnome-terminal -e "tmux attach-session -d -t nvim"

Bonus: since I send the keys, instead of issueing the commands directly they appear in the terminals history, like expected!

Attention: my nvim/init.vim contains a remapping of ; to :, which means, that in order to run one has to check the sent keys for "regular" vim/neovim settings!

I've found solution relying heavily on tmux. Since tmux is working independently of the shell and prevails even after closing the windows, one can prepare a tmux session and then attach to it. The thing won't instantly exit, since the attachment command does not return unless you exit it.

This and the fact that you can name and search a session yields the following Nautilus-Script:

#!/bin/bash
# nautilus script to start files in nvim under a tmux session
# place this script into ~/.local/share/nautilus/scripts/nvimOpen.sh
# presented without warranty by mike aka curvi

# nvim running in another session? -
# TODO tmux rename-session -t $whaever nvim

# Tmux session 'nvim' is running neovim always!
if tmux has-session -t nvim ; then
  # test if it is open and split it
  for selected_file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ; do
    tmux send-keys -t nvim Escape # change to normal mode
    tmux send-keys -t nvim ";vsp $selected_file" Enter # open file in vsplit
else
  # or start it up freshly!
  tmux new-session -d -s nvim ;
  tmux send-keys -t nvim "nvim -O $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" Enter
  tmux send-keys -t nvim Escape # change to normal mode
fi
# after the tmux session is prepared - attach to it in gnome-terminal!
gnome-terminal -e "tmux attach-session -d -t nvim"

Bonus: since I send the keys, instead of issueing the commands directly they appear in the terminals history, like expected!

Attention: my nvim/init.vim contains a remapping of ; to :, which means, that in order to run one has to check the sent keys for "regular" vim/neovim settings!

I've found solution relying heavily on tmux. Since tmux is working independently of the shell and prevails even after closing the windows, one can prepare a tmux session and then attach to it. The thing won't instantly exit, since the attachment command does not return unless you exit it.

This and the fact that you can name and search a session yields the following Nautilus-Script:

#!/bin/bash
# nautilus script to start files in nvim under a tmux session
# place this script into ~/.local/share/nautilus/scripts/nvimOpen.sh
# presented without warranty by mike aka curvi

# nvim running in another session? -
# TODO tmux rename-session -t $whaever nvim

# Tmux session 'nvim' is running neovim always!
if tmux has-session -t nvim ; then
  # test if it is open and split it
  for selected_file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ; do
    tmux send-keys -t nvim Escape # change to normal mode
    tmux send-keys -t nvim ";vsp $selected_file" Enter # open file in vsplit
  done
else
  # or start it up freshly!
  tmux new-session -d -s nvim ;
  tmux send-keys -t nvim "nvim -O $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" Enter
  tmux send-keys -t nvim Escape # change to normal mode
fi
# after the tmux session is prepared - attach to it in gnome-terminal!
gnome-terminal -e "tmux attach-session -d -t nvim"

Bonus: since I send the keys, instead of issueing the commands directly they appear in the terminals history, like expected!

Attention: my nvim/init.vim contains a remapping of ; to :, which means, that in order to run one has to check the sent keys for "regular" vim/neovim settings!

deleted 770 characters in body
Source Link
mike
  • 281
  • 1
  • 4
  • 10

I've found solution relying heavily on tmux. Since tmux is working independently of the shell and prevails even after closing the windows, one can prepare a tmux session and then attach to it. The thing won't instantly exit, since the attachment command does not return unless you exit it.

This and the fact that you can name and search a session yields the following Nautilus-Script:

#!/bin/bash
# nautilus script to start files in nvim under a tmux session
# place this script into ~/.local/share/nautilus/scripts/nvimOpen.sh
# presented without warranty by mike aka curvi

# nvim running in another session? -
# TODO tmux rename-session -t $whaever nvim

# Tmux session 'nvim' is running neovim always!
if tmux has-session -t nvim ; then
  # test if it is open and split it
  for selected_file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ; do
    tmux send-keys -t nvim Escape # change to normal mode
    tmux send-keys -t nvim ",w" Enter # split pane vertically
    tmux send-keys -t nvim ";e";vsp $selected_file" Enter # load newopen file
  in donevsplit
else
  # or start it up freshly!
  tmux new-session -d -s nvim ;
  tmux send-keys -t nvim "nvim -O $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" Enter
  tmux send-keys -t nvim Escape # change to normal mode
fi
# after the tmux session is prepared - attach to it in gnome-terminal!
gnome-terminal -e "tmux attach-session -d -t nvim"

Bonus: since I send the keys, instead of issueing the commands directly they appear in the terminals history, like expected!

If there is no "nvim" tmux-session running and you want to start multiple files from the script, I need to startAttention: my nvim with the first argument/init.vim contains a remapping of $NAUT.._PATHS; and loop over the rest to form splits. Somehow like

nvim ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[0]}
# all elements from index 1 (2nd ele) up to the last
second_files = ${#NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[*]:1}
for selected_file in $second_files ; do
   split_open ${selected_file} # split vim and open the file
done

Optional function design::, which means, that in order to run one has to check the sent keys for "regular" vim/neovim settings!

split_open () {
    tmux send-keys -t nvim ",w" Enter # split pane vertically
    tmux send-keys -t nvim ";e $1" Enter # load file 
}

I've found solution relying heavily on tmux. Since tmux is working independently of the shell and prevails even after closing the windows, one can prepare a tmux session and then attach to it. The thing won't instantly exit, since the attachment command does not return unless you exit it.

This and the fact that you can name and search a session yields the following Nautilus-Script:

#!/bin/bash
# nautilus script to start files in nvim under a tmux session
# place this script into ~/.local/share/nautilus/scripts/nvimOpen.sh
# presented without warranty by mike aka curvi

# nvim running in another session? -
# TODO tmux rename-session -t $whaever nvim

# Tmux session 'nvim' is running neovim always!
if tmux has-session -t nvim ; then
  # test if it is open and split it
  for selected_file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ; do
    tmux send-keys -t nvim Escape # change to normal mode
    tmux send-keys -t nvim ",w" Enter # split pane vertically
    tmux send-keys -t nvim ";e $selected_file" Enter # load new file
   done
else
  # or start it up freshly!
  tmux new-session -d -s nvim ;
  tmux send-keys -t nvim "nvim $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" Enter
  tmux send-keys -t nvim Escape # change to normal mode
fi
# after the tmux session is prepared - attach to it in gnome-terminal!
gnome-terminal -e "tmux attach-session -d -t nvim"

Bonus: since I send the keys, instead of issueing the commands directly they appear in the terminals history, like expected!

If there is no "nvim" tmux-session running and you want to start multiple files from the script, I need to start nvim with the first argument of $NAUT.._PATHS and loop over the rest to form splits. Somehow like

nvim ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[0]}
# all elements from index 1 (2nd ele) up to the last
second_files = ${#NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[*]:1}
for selected_file in $second_files ; do
   split_open ${selected_file} # split vim and open the file
done

Optional function design:

split_open () {
    tmux send-keys -t nvim ",w" Enter # split pane vertically
    tmux send-keys -t nvim ";e $1" Enter # load file 
}

I've found solution relying heavily on tmux. Since tmux is working independently of the shell and prevails even after closing the windows, one can prepare a tmux session and then attach to it. The thing won't instantly exit, since the attachment command does not return unless you exit it.

This and the fact that you can name and search a session yields the following Nautilus-Script:

#!/bin/bash
# nautilus script to start files in nvim under a tmux session
# place this script into ~/.local/share/nautilus/scripts/nvimOpen.sh
# presented without warranty by mike aka curvi

# nvim running in another session? -
# TODO tmux rename-session -t $whaever nvim

# Tmux session 'nvim' is running neovim always!
if tmux has-session -t nvim ; then
  # test if it is open and split it
  for selected_file in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS ; do
    tmux send-keys -t nvim Escape # change to normal mode
    tmux send-keys -t nvim ";vsp $selected_file" Enter # open file in vsplit
else
  # or start it up freshly!
  tmux new-session -d -s nvim ;
  tmux send-keys -t nvim "nvim -O $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" Enter
  tmux send-keys -t nvim Escape # change to normal mode
fi
# after the tmux session is prepared - attach to it in gnome-terminal!
gnome-terminal -e "tmux attach-session -d -t nvim"

Bonus: since I send the keys, instead of issueing the commands directly they appear in the terminals history, like expected!

Attention: my nvim/init.vim contains a remapping of ; to :, which means, that in order to run one has to check the sent keys for "regular" vim/neovim settings!

deleted 12 characters in body
Source Link
mike
  • 281
  • 1
  • 4
  • 10

Bonus: since I send the keys, instead of issueing the commands directly they appear in the terminals history, like expected! 2 things are still missing

If there is no "nvim" tmux-session running and you want to start multiple files from the script, I need to start nvim with the first argument of $NAUT.._PATHS and loop over the rest to form splits. Somehow like

nvim ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[0]}
# all elements from index 1 (2nd ele) up to the last
second_files = ${#NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[*]:1}
for selected_file in $second_files ; do
   split_open ${selected_file} # split vim and open the file
done

Optional function design:

  1. If neovim is running in another tmux session, I want to find it and rename that session.

  2. If there is no "nvim" tmux-session running and you want to start multiple files from the script, I need to start nvim with the first argument of $NAUT.._PATHS and loop over the rest to form splits. Somehow like

    nvim ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[0]} numel = ${#NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[*]} for (( i = 1 ; i < ${numel} ; i++ )) do; # split vim and open the file ${NAU.._PATHS[$i]} done

split_open () {
    tmux send-keys -t nvim ",w" Enter # split pane vertically
    tmux send-keys -t nvim ";e $1" Enter # load file 
}

Bonus: since I send the keys, instead of issueing the commands directly they appear in the terminals history, like expected! 2 things are still missing:

  1. If neovim is running in another tmux session, I want to find it and rename that session.

  2. If there is no "nvim" tmux-session running and you want to start multiple files from the script, I need to start nvim with the first argument of $NAUT.._PATHS and loop over the rest to form splits. Somehow like

    nvim ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[0]} numel = ${#NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[*]} for (( i = 1 ; i < ${numel} ; i++ )) do; # split vim and open the file ${NAU.._PATHS[$i]} done

Bonus: since I send the keys, instead of issueing the commands directly they appear in the terminals history, like expected!

If there is no "nvim" tmux-session running and you want to start multiple files from the script, I need to start nvim with the first argument of $NAUT.._PATHS and loop over the rest to form splits. Somehow like

nvim ${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[0]}
# all elements from index 1 (2nd ele) up to the last
second_files = ${#NAUTILUS_SCRIPT_SELECTED_FILE_PATHS[*]:1}
for selected_file in $second_files ; do
   split_open ${selected_file} # split vim and open the file
done

Optional function design:

split_open () {
    tmux send-keys -t nvim ",w" Enter # split pane vertically
    tmux send-keys -t nvim ";e $1" Enter # load file 
}
deleted 12 characters in body
Source Link
mike
  • 281
  • 1
  • 4
  • 10
Loading
added 22 characters in body
Source Link
mike
  • 281
  • 1
  • 4
  • 10
Loading
added 139 characters in body
Source Link
mike
  • 281
  • 1
  • 4
  • 10
Loading
added 126 characters in body
Source Link
mike
  • 281
  • 1
  • 4
  • 10
Loading
Source Link
mike
  • 281
  • 1
  • 4
  • 10
Loading