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

发布于:2024-07-01 ⋅ 阅读:(18) ⋅ 点赞:(0)

  • y9kp

显示当前shell

echo $SHELL

which bash

  • 根据输出,例如 /bin/bash 改变shell:
chsh -s /bin/bash

  • 退出
  • 重新登录

加入函数及覆盖PS1

# 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
}

export PS1='\[\e[0;32m\]\u@\h:\[\e[0;36m\]\w\[\e[0;33m\] $(git_branch)\[\e[0m\] $ '

操作记录

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) $

网站公告

今日签到

点亮在社区的每一天
去签到