我尝试在bash提示符上添加我目前正在工作的git分支(签出),但没有成功。(同时保持我的当前路径显示活动目录/文件完整) 我有一个。bashrc文件在我的家,但我也看到很多人提到。profile文件…
当前回答
如果你用的是鱼壳,那就很直接了。 Fish是一个互动的贝壳,里面有很多好吃的东西。您可以使用apt-get安装它。
sudo apt-get install fish
然后,您可以使用
> fish_config
Web config started at 'http://localhost:8001/'. Hit enter to stop.
Created new window in existing browser session.
现在登录http://localhost:8001/ 打开提示选项卡并选择经典的+ git选项
现在点击使用提示按钮,你就设置好了。
其他回答
我尝试了一个python小脚本,放在....文件夹中 “gitprompt”文件
#!/usr/bin/env python
import subprocess, os
s = os.path.join(os.getcwd(), '.git')
def cut(cmd):
ret=''
half=0
record = False
for c in cmd:
if c == "\n":
if not (record):
pass
else:
break
if (record) and c!="\n":
ret = ret + c
if c=='*':
half=0.5
if c==' ':
if half == 0.5:
half = 1
if half == 1:
record = True
return ret
if (os.path.isdir(s)):
out = subprocess.check_output("git branch",shell=True)
print cut(out)
else:
print "-"
让它可执行之类的
然后相应地调整bash提示符,如下:
\u:\w--[$(gitprompt)] \$
查看这个回购:https://github.com/magicmonty/bash-git-prompt 这个提示符是“zsh的信息性git提示符”的一个移植。
通过Git克隆 将此存储库克隆到您的主目录。
git clone https://github.com/magicmonty/bash-git-prompt.git ~/.bash-git-prompt --depth=1
添加到~/.bashrc:
if [ -f "$HOME/.bash-git-prompt/gitprompt.sh" ]; then
GIT_PROMPT_ONLY_IN_REPO=1
source $HOME/.bash-git-prompt/gitprompt.sh
fi
root:~/project# -> root:~/project(dev)#
将以下代码添加到~/.bashrc的末尾
force_color_prompt=yes
color_prompt=yes
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt
这里是一个简单的干净的版本,我使用:link
vim ~/.bash
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $"
要反映最新的更改,请运行以下命令
source ~/.bashrc
输出:
chandrakant@NDL41104 ~/Chandrakant/CodeBase/LaravelApp (development) $
推荐文章
- 安装tzdata非交互式
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- 在Bash中检查变量是否存在于列表中
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 查看PS命令的全部输出
- 确保一次只运行一个shell脚本实例的快速方法
- 如何在Windows命令提示符下运行.sh ?
- 无法安装gem -未能建立gem本地扩展-无法加载这样的文件——mkmf (LoadError)
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- 如何从命令行将每两行合并为一行?
- 如何复制在bash所有目录和文件递归?