- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我在 symlink
中,我想在我的提示中以不同的方式显示当前工作目录。
我有这么远:
[[ `pwd -P` = `pwd` ]] && echo "\[1;31m\]$(pwd -P)" || echo "\[1;32m\]$(pwd)"
将返回所需的输出,但它不能替代命令提示符中的 \w
。
我尝试用反引号将它包装起来,但这只会导致 PS1
中的 pwd -Ppwd
。
如果它是 符号链接(symbolic link)
或不是,我想有条件地更改颜色和值,这就是为什么我想要 if/else 类型决策。
最佳答案
如果您希望这实际上高效(并且提示应该快速呈现!),那么您需要缓存物理查找,并使用$PWD
而不是逻辑的 $(pwd)
。
# global variables are prefixed with funcname__ to avoid conflicts
# look up color codes for our terminal rather than assuming ANSI
set_prompt__red=$(tput setaf 1)
set_prompt__green=$(tput setaf 2)
set_prompt__reset=$(tput sgr0)
set_prompt() {
# only rerun this code when changing directories!
if [[ $set_prompt__lastPWDl != "$PWD" ]]; then
set_prompt__lastPWDl=$PWD
set_prompt__lastPWDp=$(pwd -P)
if [[ "$set_prompt__lastPWDl" = "$set_prompt__lastPWDp" ]]; then
set_prompt__pwd_color="$set_prompt__red"
else
set_prompt__pwd_color="$set_prompt__green"
fi
fi
# ...actually could have just "return"ed above, but this way we can change other
# aspects of the prompt even when we don't need to do a new directory lookup.
PS1='...whatever prefix...'
PS1+="\[${set_prompt__pwd_color}\]${PWD}\[${set_prompt__reset}\]"
PS1+='...whatever suffix...'
}
PROMPT_COMMAND=set_prompt
关于bash - PS1 定义中的条件密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49882286/
我在 tomcat 8.0.24 上运行 Atlassian Bitbucket,在 Ubuntu 14.04.5 LTS 上运行 Java 1.8.0 31-b13(64 位),内核 3.13.0-
docker命令reference for ps提到 docker ps -a docker ps --all 命令显示所有容器的列表。 在docker上工作时,我错误地使用了以下命令 docker
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
docker ps 不让我知道容器本身的 pid。在主机上运行的 docker ps 和 ps 的输出之间进行命令字符串匹配并不是万无一失的,因为我可以在主机上运行相同的命令。 有没有人有确定的方法将
如何通过命令“ps”或“ps -ef”知道进程是在后台运行还是在前台运行? 我首先想到的是,当我输入 ps -ef 时,有一个名为 TTY 的部分。 当我查看 TTY 列表时,大多数都是“?” (问号
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a softwar
我正在使用带有 3 个文件的 GUI 编写 PowerShell 脚本: window1.ps1 - 输入变量并启动start.vbs start.vbs - 启动window2.ps1 window
这似乎是一个愚蠢的问题,但我一直无法找到明确的答案。 This website指出破折号是可选的 ps aux 然而,ps aux有效但 ps -aux出现错误 no user named 'x' .
我有一个 bash 脚本 (ScreamDaemon.sh),在其中添加了检查它的示例是否已经运行的检查。 numscr=`ps aux | grep ScreamDaemon.sh | wc -l`
我需要解释一下 ps -ef 命令的四个字段(4 或 0),这个数字的含义谢谢你 root 27116 27112 4 15:25 pts/0 00:00:00 grep -qsRw -m1 moni
我刚开始学习 linux 命令,请帮助我找出 ps -ef 和 ps -ef | 之间的区别 | linux 中的 more 命令 最佳答案 与 ps -ef | more你管| ps 的输出至 mo
# ps | grep safe 14592 root 136m S /tmp/data/safe/safe 16210 root 1664 S grep safe
我有一个 bash 脚本 (ScreamDaemon.sh),在其中添加了检查它的示例是否已经运行的检查。 numscr=`ps aux | grep ScreamDaemon.sh | wc -l`
为什么 docker compose 创建的容器只能从 docker-compose ps 访问并且在杀死正在运行的容器后仍然存在? 最佳答案 不是。 docker ps只显示正在运行的容器,dock
我试图在 unix 框中找到所有正在运行的 java 进程。我很困惑 ps –ef|grep java 和 ps –ef|grep *.java 哪一个是正确的,确切的区别是什么? PS:两者都返回不
给定一个 pid 数组和代码: for i in ${listedPids[@]} do runningCheck="ps -u $USER | grep $i"
我的 PowerShell 配置文件 (CurrentUser.AllHosts) 中有两个脚本让我抓狂,因为它们在看似相同的控制台上给出了不同的结果。在 Powershell(提升版)上,脚本没有任
对于我正在创建的 python 脚本,我需要先获取进程的 PID(基于其名称),然后使用其 PID、持续时间从该进程获取,从下面的打印输出中,将是“00:00:00” root 5686
前言 大家好,我是 god23bin。欢迎来到《 一分钟学一个 Linux 命令 》系列, 每天只需一分钟,记住一个 Linux 命令不成问题 。今天要说的是 ps 命令。
我发现 ps aux 列出了当前正在运行的进程,我发现其他人提到了 ps auxwww .我想知道这是什么意思?或者它有什么作用? ps aux有什么区别和 ps auxwww ? 最佳答案 引用 m
我是一名优秀的程序员,十分优秀!