【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) $
相关推荐
刘大辉在路上1 小时前
突发!!!GitLab停止为中国大陆、港澳地区提供服务,60天内需迁移账号否则将被删除
git·后端·gitlab·版本管理·源代码管理
VinciYan2 小时前
基于Jenkins+Docker的自动化部署实践——整合Git与Python脚本实现远程部署
python·ubuntu·docker·自动化·jenkins·.net·运维开发
it噩梦2 小时前
es 中 terms set 使用
大数据·elasticsearch
Jackey_Song_Odd2 小时前
Ubuntu 24.04.1 解决部分中文字符(门、径)显示错误的问题
linux·ubuntu
tntlbb3 小时前
Ubuntu20.4 VPN+Docker代理配置
运维·ubuntu·docker·容器
热心市民运维小孙3 小时前
Ubuntu重命名默认账户
linux·ubuntu·excel
PyAIGCMaster3 小时前
文本模式下成功。ubuntu P104成功。
服务器·数据库·ubuntu
Jackey_Song_Odd4 小时前
解决Ubuntu下无法装载 Windows D盘的问题
linux·ubuntu
喝醉酒的小白5 小时前
Elasticsearch 配置文件
大数据·elasticsearch·搜索引擎
猫猫的小茶馆7 小时前
【数据结构】数据结构整体大纲
linux·数据结构·算法·ubuntu·嵌入式软件