【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) $
相关推荐
snow@li7 小时前
工程化:Commitlint / 规范化Git提交消息格式
前端·git
DX_dove7 小时前
点云压缩配置开发环境遇到一些bug
ubuntu·bug
MonkeyKing_sunyuhua7 小时前
git lfs下载卡住,没有进度条怎么处理
git
抓个马尾女孩7 小时前
git出现Permission denied问题
git
hunter2062069 小时前
无法下载 https://mirrors./ubuntu/dists/bionic/main/binary-arm64/Packages
linux·运维·ubuntu
辣香牛肉面10 小时前
4 种 MySQL 同步 ES 方案
数据库·mysql·elasticsearch
magic_ll10 小时前
【环境配置】ubuntu中 Docker的安装
linux·ubuntu·docker
码农葫芦侠10 小时前
Git常用功能
git
Elasticsearch10 小时前
Elasticsearch:Runtime fields - 运行时字段(一)
elasticsearch
垂慕容11 小时前
响应远程更新:git reset 和 git rebase 的比较与最佳实践
git