strom/fish-misc
Archived
1
0
Fork 0
This repository has been archived on 2023-08-27. You can view files and clone it, but cannot push or open issues or pull requests.
fish-misc/functions/safe_launch_extra.fish

25 lines
825 B
Fish

# vim: ft=fish ts=4 sw=4 noet
function safe_launch_extra --description 'launch command inside a dedicated tmux session'
if ! command -sq tmux; return 1; end
command tmux has-session -t '_safe_launch' >/dev/null 2>&1
set -l sess $status
if _is_tmux
if [ "$sess" = 0 ] # has session
command tmux new-window -t '_safe_launch' "$argv;bash -i"
else
command tmux new-session -d -s '_safe_launch' \
&& command tmux new-window -k -t '_safe_launch' "$argv;bash -i" \
&& echo "created detached session ''_safe_launch'' to avoid nesting"
end
else
if [ "$sess" = 0 ] # session
command tmux new-window -t '_safe_launch' "$argv;bash -i" \
&& command tmux attach-session -t '_safe_launch'
else
command tmux start-server \
&& command tmux new-session -s '_safe_launch' "$argv;bash -i"
end
end
end