【问题标题】:fish shell - Showing the current command in the window title of screenfish shell - 在屏幕的窗口标题中显示当前命令
【发布时间】:2014-07-22 10:41:20
【问题描述】:

我希望当前命令显示在屏幕(或 tmux)的标题中。

我尝试了以下设置,但它不起作用。

我怎样才能让它工作?

.screenrc

shelltitle "$ |fish"
shell /usr/local/bin/fish

.config/fish/config.fish

set -x PS1 '\033k\033\\[\u@\h \W]\$ '

【问题讨论】:

    标签: gnu-screen fish


    【解决方案1】:

    对于 fish 2.1.0 版,您只需编辑 ~/.config/fish/functions/fish_title.fish

    function fish_title
        hostname
    end
    

    对于 1.23.1 版本,这似乎不起作用。如果目录不存在,请先创建它们:

    mkdir -p ~/.config/fish/functions/

    【讨论】:

      【解决方案2】:

      .config/fish/functions/fish_title.fish 对我有用:

      function fish_title
          # this one sets the X terminal window title
          # argv[1] has the full command line
          echo (hostname): (pwd): $argv[1]
      
          switch "$TERM"
          case 'screen*'
      
            # prepend hostname to screen(1) title only if on ssh
            if set -q SSH_CLIENT
              set maybehost (hostname):
            else
              set maybehost ""
            end
      
            # inside the function fish_title(), we need to
            # force stdout to reach the terminal
            #
            # (status current-command) gives only the command name
            echo -ne "\\ek"$maybehost(status current-command)"\\e\\" > /dev/tty
          end
      end
      

      【讨论】:

      • 确实,最后一个>/dev/ttyGNU 屏幕 非常重要。我发现此时其他答案都失败了。
      【解决方案3】:

      我认为您正在寻找fish_title。见documentation here

      你可以这样做:

      function fish_title
          echo $_ ' '
          pwd
      end
      funcsave fish_title
      

      (注意你只是在提示符下运行它——不要把它放在配置文件中)。

      【讨论】:

      • 我添加了相同的答案并将其删除。用户希望更新 screen 标题,而不是终端标题。
      【解决方案4】:

      感谢您的回答。 终于成功了!

      .screenrc

      shelltitle "$ |fish"
      shell /usr/local/bin/fish
      

      .config/fish/config.fish

      function fish_prompt
          echo -ne '\033k'
          echo -ne $argv
          echo -ne '\033\\'
          echo -ne '$ '
      end
      

      【讨论】:

        猜你喜欢
        • 2015-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-19
        • 1970-01-01
        • 2016-10-13
        • 1970-01-01
        相关资源
        最近更新 更多