sudo apt-get install tmux
) and learning the basics, I fell in love with this multiplexer. Everything in it is good. There is one “but” - after each reboot, you need to reconfigure the tmux window. And this is 5 extra minutes! Is it really impossible to save the state of tmux windows! alias rapp='cd ~/work/ruby/Apps/sample_app' alias rappo='cd ~/work/ruby/Apps/sample_app && subl .' alias rapps='/bin/bash --login' alias tmux-k='tmux kill-session' alias tmux-ko='tmux kill-server' alias tmux-l='tmux ls'
sudo touch tmux-s
) and made it executable ( sudo chmod +x tmux-s
). As a matter of fact, in this file there will be a code that will raise the tmux session with the panels and windows I need, and also take the necessary parameters. The file contents are as follows: #!/bin/bash ####################### # Constants flag='0' ####################### # Config Variables session_name="rails" first_window_name="first" second_window_name="second" base_pane_command="rapp && rapps" server_start_comand="rails s" tests_start_comand="guard" project_open_command="rappo" console_open_command="rails c" ####################### # Addpanes add_panes() { tmux split-window -h -t "${session_name}" tmux split-window -v -t "${session_name}" tmux send-keys -t "${session_name}":"${first_window_name}".1 "${base_pane_command}" Cm tmux send-keys -t "${session_name}":"${first_window_name}".2 "${base_pane_command}" Cm tmux send-keys -t "${session_name}":"${first_window_name}".3 "${base_pane_command}" Cm tmux send-keys -t "${session_name}":"${first_window_name}".2 "${server_start_comand}" tmux send-keys -t "${session_name}":"${first_window_name}".3 "${tests_start_comand}" } ####################### # Tmux server start tmux_session_start() { if [ "${flag}" != '1' ] ;then echo "Session ${session_name} start..." tmux new-session -s ${session_name} -n ${first_window_name} -d add_panes fi } ####################### # Rails server start rails_server_start() { tmux send-keys -t "${session_name}":"${first_window_name}".2 Cm } ####################### # Guard start guard_tests_start() { tmux send-keys -t "${session_name}":"${first_window_name}".3 Cm } ####################### # Open project in Sublime Text open_project() { tmux send-keys -t "${session_name}":"${first_window_name}".1 "${project_open_command}" Cm } ####################### # Ruby console start ruby_console_start() { tmux send-keys -t "${session_name}":"${first_window_name}".1 "${console_open_command}" Cm } ####################### # error_param error_param() { tmux kill-session echo "Session ${session_name} killed..." echo "Parameter is incorrect! Avaliable parameters: -s for start Rails server -t for start Gusrd server -o for open project in Sublime Text -c for open Ruby concole" exit 1 } if [ ! ${1} ] ;then tmux_session_start fi while [ ${1} ] ;do case ${1} in -s) tmux_session_start rails_server_start flag='1' shift 1 ;; -t) tmux_session_start guard_tests_start flag='1' shift 1 ;; -o) tmux_session_start open_project flag='1' shift 1 ;; -c) tmux_session_start ruby_console_start flag='1' shift 1 ;; *) error_param ;; esac done echo "Success!" tmux select-pane -L -t "${session_name}" tmux resize-pane -R -t "${session_name}":"${first_window_name}".1 25 tmux new-window -n "${second_window_name}" -t "${session_name}" tmux select-window -t "${session_name}":"${first_window_name}" tmux attach -t "${session_name}"
The “Config Variables” block contains user settings
Also for correct work, I advise you to create a file ~ / .tmux.conf and enter the settings in it from here: user tmux settings
tmux-s
and get a convenient tmux window, ready to work with Ruby on Rails. You can play with the parameters - they also work. It is only important to set up aliases correctly from ~ / .bash_aliases so that the paths are assigned to your project. And remember, the script is written to help those who learn from the book railstutorial.ru . If you do not have Guard, the script will not work correctly with the -t parameter. Also install Sublime Text.Source: https://habr.com/ru/post/217339/
All Articles