gpt4 book ai didi

bash - 这个用于命名 iTerm 选项卡的脚本如何工作?

转载 作者:行者123 更新时间:2023-11-29 09:37:10 31 4
gpt4 key购买 nike

我正在尝试命名我的 iTerm 选项卡并找到 this link.这是该人帖子的相关部分:

I wrote a simple script, which I call “nametab”, which allows you to name the tab you are in from the command line. You just type something like:

$ nametab New tab name

If you’d like to use this yourself, here is the code:

#!/bin/bash

# A simple script which will name a tab in iTerm
# usage:
# $ nametab New tab name

echo -ne "\033]0;"$@"\007"

我创建了一个目录 $HOME/dev/bash_scripts 并在该目录中放置了一个名为 nametab.sh 的文件。然后我切换到那个目录并运行命令

chmod u+x nametab.sh

但是当我尝试通过键入 nametab.sh New tab hellooooo 来命名 iTerm 中的当前选项卡时,没有任何反应。我还尝试了 nametab.sh hellooooo,但没有任何反应。

你能帮我理解我不明白的地方吗?


更新:

echo TERM=$TERM

返回

TERM=xterm-256color

echo $PATH

返回

.:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:~/dev/bash_scripts

cat ~/dev/bash_scripts/nametab.sh

返回

#!/bin/bash

# A simple script which will name a tab in iTerm
# usage:
# $ nametab NewTabName

echo "trying to rename the current tab to $@"
echo -ne "\033]0;"$@"\007"
echo "finished"

nametab.sh hellooooo

返回

trying to rename the current tab to helloooo
finished

但选项卡名称始终保持不变。

顺便说一下,标签名称是

MindRoot (bash)

我正在运行 iTerm2。我尝试在 /etc/bashrc 中完成我所有的 bash shell 配置。这样,无论我登录哪个用户帐户,我都可以获得相同的 bash 终端行为。 /etc/bashrc的内容是

# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
return
fi

#PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize

# ALL OF THE BELOW ADDED BY DEONOMO ON 2011-04-25

# custom prompt
PROMPT_HOSTNAME='MindRoot'
PROMPT_COLOR='0;35m'

# If I am root, set the prompt to bright red
if [ ${UID} -eq 0 ]; then
PROMPT_COLOR='1;31m'
fi

PS1='\[\e]1;${PROMPT_HOSTNAME}\a\e]2;${PROMPT_HOSTNAME}:${PWD}\a\
\e[${PROMPT_COLOR}\]\
[\u@${PROMPT_HOSTNAME} \w]\n \#\$ \
\[\e[m\]'

#PS1="\e[0;45m\w:$ "

# added by Deonomo on 2011/09/12 in order to have textmate work as default editor
export EDITOR='mate -w'

# added by Deonomo on 2012-01-11 in order to start a dev/bash_scripts directory
export PATH="$PATH:~/dev/bash_scripts"

最佳答案

如果你想有一个别名来改变选项卡名称,你实际上可以通过在你的 .profile/.bashrc 文件中定义一个函数来实现,如下所示:

function renametab () {
echo -ne "\033]0;"$@"\007"
}

关于bash - 这个用于命名 iTerm 选项卡的脚本如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8823103/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com