【问题标题】:Start tmux with cmus opend through bash script通过 bash 脚本打开 cmus 启动 tmux
【发布时间】:2012-12-06 18:12:26
【问题描述】:

我想打开一个包含 cmus 的新 tmux 会话和窗口,或者,如果已经在运行,则附加到它。在Ubuntuusers,我找到了应该执行此操作的脚本。

1. #!/bin/bash
2. SESSION=main
3. tmux="tmux -2 -f tmux.conf"
4. 
5. # if the session is already running, just attach to it.
5. $tmux has-session -t $SESSION
7. if [ $? -eq 0 ]; then
8.   echo "Session $SESSION already exists. Attaching."
9.   sleep 1
10.  $tmux attach -t $SESSION
11.  exit 0;
12.  fi

我已经知道我可以手动完成它

tmux new -n music cmus

但是当我在脚本中使用它时,我只会收到消息

usage: new-session [-d] [-n window-name] [-s session-name] [-t target-session] [-x width] [-y height] [command]

我也尝试了新会话,但没有变化。我完全不知道命令或脚本或两者都有什么问题

【问题讨论】:

    标签: bash tmux


    【解决方案1】:

    我解决这个问题的方法是有一个主 tmux 会话,像 mutt 或 cmus 这样的程序可以启动或连接到该会话。例如,对于 cmus,我有一个别名:

    alias cmus='monkeys -n music cmus'
    

    猴子是以下脚本:

    #! /bin/sh
    
    name=monkeys
    
    # make sure tmux server is running:
    tmux start-server
    
    # determine if monkeys session is running:
    tmux has-session -t ${name}
    
    # no monkeys running, create monkeys,
    # if more than one argument, take it as a command to run 
    # on monkeys, else just attach to monkeys
    if [ "$?" != "0" ]; then
        tmux new-session -s ${name} $*
    elif [ $# -gt 0 ]; then
        tmux new-window -t ${name} $*
    else
        tmux a -t ${name}
    fi
    

    【讨论】:

    • 首先感谢您的回复。但不幸的是,它在这里不起作用。当没有会话时,它可以完美地工作,但是当已经有会话时,我得到“创建窗口失败:使用中的索引:0”。此外,我的技能也没有那么高,以至于我能 100% 地理解你的脚本。你有什么想法吗?
    • 真的吗?即使已经有一个会话,它也对我有用。将 elsif 行更改为: tmux new-window -a -t ${name} $* 会发生什么
    • 另外,脚本背后的想法只是检查是否有特定的会话正在运行(即在新会话或新窗口之间进行选择)。这个检查来自 tmux has-session -t ${name} 的退出状态。退出状态保存在自动 shell 变量 $? 中。
    • 也没有用。只有新的错误。 “无法连接到服务器:连接被拒绝 [退出]”
    • 今天我再次检查它,我认为我的最后一条评论是废话。 Sry 昨天有点醉了。 ;) Cmus 已经在运行了。但它又没有用。打开一个全新的会话没有问题。但它没有识别正在运行的会话。我尝试了“tmux has-session -t music”并且没有响应“tmux has-session -t test session not found: test”表明该会话不存在。
    猜你喜欢
    • 2016-11-26
    • 2014-07-28
    • 2011-07-23
    • 2015-03-26
    • 1970-01-01
    • 2014-04-20
    • 1970-01-01
    • 1970-01-01
    • 2018-03-26
    相关资源
    最近更新 更多