这是我第二次发布问题,因为整个情况最终比我想象的更令人困惑。
我正在尝试制作一个脚本来打开 tmux,将其分成 3 个 Pane ,使它们水平大小相等,然后在所有 Pane 中启动 ncmpcpp。这是我设法编写的脚本:
#!/bin/sh
tmux new-session -d 'ncmpcpp'
printf 'creating session\n'
tmux split-window -h 'ncmpcpp'
printf 'window split 1\n'
tmux split-window -h 'ncmpcpp'
printf 'window split 2\n'
tmux select-layout even-horizontal
printf 'evening out panes\n'
tmux a #
printf 'attaching session\n'
我是编写脚本的初学者,如果这里的错误很明显,我深表歉意。 printfs 在那里,这样我就可以确定脚本在何处使 tmux 崩溃。显然,它在 tmux a #
处崩溃。
奇怪的是,崩溃是瞬间发生的。由于它消失的速度太快,我无法截图。
terminate called after throwing an instance of `std::logic_error
what() : constructed window couldn't fit into terminal'
基本上,这些 Pane 对于 ncmpcpp 来说太小了,无法在其中启动。尽管我可以在更小的终端中手动启动 ncmpcpp。
然而,经过一番折腾,我不小心“有点”解决了问题。
我把脚本搞砸了,结果是这样的:
#!/bin/sh
printf '\033[8;29;252t'
tmux new-session -d
tmux select-layout even-horizontal
tmux send-keys -t 0 'tput cols' Enter
tmux split-window -h
sleep 1
tmux select-layout even-horizontal
tmux send-keys -t 1 'tput cols' Enter
tmux split-window -h
sleep 1
tmux select-layout even-horizontal
tmux send-keys -t 2 'tput cols' Enter
sleep 1
tmux send-keys -t 0 'ncmpcpp' Enter
tmux send-keys -t 1 'ncmpcpp' Enter
tmux send-keys -t 2 'ncmpcpp' Enter
tmux a #
开始时暂停 3 秒,然后立即启动 tmux,有 3 个面板,所有面板上都有 ncmpcpp。
...有时。
它并非一直有效,有时某些 Pane 会彻底崩溃,有时则不会。
老实说,我对这里发生的事情感到很困惑。我的猜测是 Pane 的大小没有记录好,足以搞砸每个 Pane 有多少列/行的值。但老实说,我很难过。
这就是我问这个问题的原因 - ncmpcpp 仅在终端尺寸足够大时启动。由于 tmux 混淆了说明列是什么的实际值,是否不可能执行我在标题中所说的内容?
最佳答案
所以
#!/bin/sh
printf '\033[8;29;252t'
tmux new-session -d -x 252 -y 29
tmux select-layout even-horizontal
tmux send-keys -t 0 'tput cols' Enter
tmux split-window -h
sleep 1
tmux select-layout even-horizontal
tmux send-keys -t 1 'tput cols' Enter
tmux split-window -h
sleep 1
tmux select-layout even-horizontal
tmux send-keys -t 2 'tput cols' Enter
sleep 1
tmux send-keys -t 0 'ncmpcpp -s playlist' Enter
tmux send-keys -t 1 'ncmpcpp -s media_library' Enter
tmux send-keys -t 2 'ncmpcpp -s clock' Enter
# help,playlist,browser,search_engine,media_library,
# playlist_editor,tag_editor,outputs,visualizer,clock
tmux a #
是你自己的答案。您是否尝试过更改 ncmpcpp 布局: (用-c调用)
ncmpcpp -c ~/.my_ncmpcpp.conf
#~/.my_ncmpcpp.conf
#edited from https://bbs.archlinux.org/viewtopic.php?pid=1236890#p1236890
song_list_format = "{$5%a $9}{$2%t$9}|{$7%f$9}$7$R{%b }{$3%4l$9}$9
song_status_format = "{{%a{ \"%b\"{ (%y)}} - }{%t}}|{%f}"
song_library_format = "{%N - }{%t}|{%f}"
now_playing_prefix = "$b"
alternative_header_first_line_format = "$b$8$aqqu$/a$9 $2{%t}|{%f}$9 $8$atqq$/a$9$/b"
alternative_header_second_line_format = "$b$8$aqqu$/a$9 $3{%b}|{%f}$9 $8$atqq$/a$9$/b"
song_columns_list_format = "(4)[blue]{n:#} (25)[blue]{a} (40)[blue]{t|f} (30)[blue]{b} (7f)[blue] {l}"
playlist_show_remaining_time = "yes"
playlist_separate_albums = "yes"
playlist_display_mode = "columns" (classic/columns)
browser_display_mode = "columns" (classic/columns)
search_engine_display_mode = "columns" (classic/columns)
progressbar_look = "✠❱•"
default_place_to_search_in = "database"
user_interface = "alternative"
header_visibility = "no"
titles_visibility = "yes"
show_hidden_files_in_local_browser = "no"
screen_switcher_mode = "browser, search_engine"
startup_screen = "search_engine"
ask_before_clearing_playlists = "yes"
clock_display_seconds = "yes"
display_volume_level = "yes"
display_bitrate = "no"
display_remaining_time = "yes"
regular_expressions = "extended"
ignore_leading_the = "yes"
mouse_support = "no"
enable_window_title = "yes"
allow_for_physical_item_deletion = "no"
external_editor = "vim"
use_console_editor = "yes"
colors_enabled = "yes"
header_window_color = "default"
main_window_color = "white"
progressbar_color = "green"
alternative_ui_separator_color = "red"
active_column_color = "red"
或者这可能是您想要的东西。
#!/bin/bash
SESSION=ncmpcpp
#url=https://bbs.archlinux.org/viewtopic.php?pid=1167179#p1167179
tmux -2 has-session -t $SESSION
if [ $? -eq 0 ]; then
tmux -2 attach -t $SESSION
exit 0;
fi
tmux -2 new-session -d -s $SESSION 'ncmpcpp -s playlist'
for i in "C-l" "Enter" "2"
do tmux -2 send-keys -t $SESSION:0.0 "$i"
done
tmux -2 set -t $SESSION -g status off
tmux -2 attach-session -t $SESSION
关于bash - 编写启动 ncmpcpp 的 3 个 Pane 的功能性 tmux shell 脚本是不可能的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46787777/