【ubuntu】切换shell并显示git分支名字

  • y9kp

显示当前shell

bash 复制代码
echo $SHELL
bash 复制代码
which bash
  • 根据输出,例如 /bin/bash 改变shell:
bash 复制代码
chsh -s /bin/bash
  • 退出
  • 重新登录

加入函数及覆盖PS1

bash 复制代码
# Function to return the current Git branch name
git_branch() {
  # Check if the current directory is in a Git repository
  if git rev-parse --git-dir > /dev/null 2>&1; then
    # Get the current Git branch
    git_branch=$(git symbolic-ref HEAD 2>/dev/null | sed -e 's,.*/\(.*\),\1,')
    # If the branch name is not empty, print it
    if [ ! -z "$git_branch" ]; then
      echo "($git_branch)"
    fi
  fi
}
bash 复制代码
export PS1='\[\e[0;32m\]\u@\h:\[\e[0;36m\]\w\[\e[0;33m\] $(git_branch)\[\e[0m\] $ '

操作记录

bash 复制代码
wsl: A localhost proxy configuration was detected but not mirrored into WSL. WSL in NAT mode does not support localhost proxies.
zhangbin@LAPTOP-Y9KP:~$ pwd
/home/zhangbin
zhangbin@LAPTOP-Y9KP:~$
zhangbin@LAPTOP-Y9KP:~$ ls
aliply  immersive  Miniconda3-latest-Linux-x86_64.sh  setproxy.sh  setwinproxy.sh
zhangbin@LAPTOP-Y9KP:~$ echo $SHHELL

zhangbin@LAPTOP-Y9KP:~$ echo $SHELL
/bin/bash
zhangbin@LAPTOP-Y9KP:~$ chsh -s /bin/bash
Password:
zhangbin@LAPTOP-Y9KP:~$ echo $SHELL
/bin/bash
zhangbin@LAPTOP-Y9KP:~$ cd immersive/
zhangbin@LAPTOP-Y9KP:~/immersive$ ls
Immersive-Video-Sample
zhangbin@LAPTOP-Y9KP:~/immersive$ cd ..
zhangbin@LAPTOP-Y9KP:~$ ls
aliply  immersive  Miniconda3-latest-Linux-x86_64.sh  setproxy.sh  setwinproxy.sh
zhangbin@LAPTOP-Y9KP:~$ pwd
/home/zhangbin
zhangbin@LAPTOP-Y9KP:~$ cd /mnt/d/
$RECYCLE.BIN/              NowCorder/                 test2/
allpython/                 ProgramData/               UnReal/
BaiduNetdiskDownload/      Program Files/             Users/
BaiduNetdiskWorkspace/     Program Files (x86)/       WeChat Files/
Code/                      Qt/                        Windows Kits/
HRAppStoreDownload/        Qt15/                      XTRANS/
Kugou/                     SOFT/                      zhb-dev/
LivecastSampleMFcLog/      System Volume Information/ 张龄心/
ME/                        test/                      迅雷下载/
zhangbin@LAPTOP-Y9KP:~$ cd /mnt/d/XTRANS/cuda/
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda$ ls
 01-mocap-dev
 cuda-samples
 cudnn-linux-x86_64-8.9.7.29_cuda11-archive.tar.xz
'Decoupling Human and Camera Motion from Videos in the Wild.pdf'
 onnx_tensorrt_project_yolov4
 tensorrt-yolov6_vs
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda$ pwd
/mnt/d/XTRANS/cuda
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda$ ls
 01-mocap-dev
 cuda-samples
 cudnn-linux-x86_64-8.9.7.29_cuda11-archive.tar.xz
'Decoupling Human and Camera Motion from Videos in the Wild.pdf'
 onnx_tensorrt_project_yolov4
 tensorrt-yolov6_vs
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda$ cd /home/zhangbin/
zhangbin@LAPTOP-Y9KP:~$ ls
aliply  immersive  Miniconda3-latest-Linux-x86_64.sh  setproxy.sh  setwinproxy.sh
zhangbin@LAPTOP-Y9KP:~$ vi cd2xtrans.sh
zhangbin@LAPTOP-Y9KP:~$ chmod a+x cd2xtrans.sh
zhangbin@LAPTOP-Y9KP:~$ ./cd2xtrans.sh
/mnt/d/XTRANS/cuda
zhangbin@LAPTOP-Y9KP:~$ pwd
/home/zhangbin
zhangbin@LAPTOP-Y9KP:~$ source cd2xtrans.sh
/mnt/d/XTRANS/cuda
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda$ pwd
/mnt/d/XTRANS/cuda
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda$ ls
 01-mocap-dev
 cuda-samples
 cudnn-linux-x86_64-8.9.7.29_cuda11-archive.tar.xz
'Decoupling Human and Camera Motion from Videos in the Wild.pdf'
 onnx_tensorrt_project_yolov4
 tensorrt-yolov6_vs
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda$ cd -1
-bash: cd: -1: invalid option
cd: usage: cd [-L|[-P [-e]] [-@]] [dir]
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda$ cd 01-mocap-dev/develop/
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda/01-mocap-dev/develop$ ls
dist  README.md  src  third-party
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda/01-mocap-dev/develop$ vi ~/.bashrc
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda/01-mocap-dev/develop$ source ~/.bashrc
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda/01-mocap-dev/develop (develop) $
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda/01-mocap-dev/develop (develop) $
zhangbin@LAPTOP-Y9KP:/mnt/d/XTRANS/cuda/01-mocap-dev/develop (develop) $
相关推荐
LanLance2 小时前
ES101系列09 | 运维、监控与性能优化
java·运维·后端·elasticsearch·云原生·性能优化·golang
超级土豆粉3 小时前
从0到1写一个适用于Node.js的User Agent生成库
linux·ubuntu·node.js
疯狂的沙粒5 小时前
如何通过git命令查看项目连接的仓库地址?
大数据·git·elasticsearch
qq_254617776 小时前
Gerrit+repo管理git仓库,如果本地有新分支不能执行repo sync来同步远程所有修改,会报错
git
π大星星️6 小时前
Git分布式版本控制工具
分布式·git
kingbal7 小时前
IDEA:配置 Git 需要完成 Git 路径设置、账号认证以及仓库关联三个主要步骤
git·idea
IT成长日记9 小时前
Elasticsearch集群手动分片分配指南:原理与实践
大数据·elasticsearch·手动分片分配
抠脚学代码9 小时前
Ubuntu18.6 学习QT问题记录以及虚拟机安装Ubuntu后的设置
qt·学习·ubuntu
Sapphire~16 小时前
Linux-07 ubuntu 的 chrome 启动不了
linux·chrome·ubuntu
啵啵学习16 小时前
Linux 里 su 和 sudo 命令这两个有什么不一样?
linux·运维·服务器·单片机·ubuntu·centos·嵌入式