【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) $
相关推荐
一心0923 小时前
ubuntu 20.04.6 sudo 源码包在线升级到1.9.17p1
运维·ubuntu·sudo·漏洞升级
好好学习啊天天向上3 小时前
世上最全:ubuntu 上及天河超算上源码编译llvm遇到的坑,cmake,ninja完整过程
linux·运维·ubuntu·自动性能优化
G皮T6 小时前
【Elasticsearch】自定义评分检索
大数据·elasticsearch·搜索引擎·查询·检索·自定义评分·_score
snoopyfly~7 小时前
Ubuntu 24.04 LTS 服务器配置:安装 JDK、Nginx、Redis。
java·服务器·ubuntu
BD_Marathon8 小时前
Ubuntu下Tomcat的配置
linux·ubuntu·tomcat
BD_Marathon8 小时前
Ubuntu:Tomcat里面的catalina.sh
linux·ubuntu·tomcat
BD_Marathon8 小时前
设置LInux环境变量的方法和区别_Ubuntu/Centos
linux·ubuntu·centos
&Sinnt&8 小时前
Git 版本控制完全指南:从入门到精通
git·后端
zhaowangji8 小时前
ubuntu 20.04 安装中文输入法 (sougou pin yin)
linux·ubuntu
Tiny21411 小时前
多人协同开发时Git使用命令
git