[Software Recommendation] A particularly easy-to-use bash → Git Bash (Windows uses Linux commands)

introduction

When we want to use command line tools to perform some operations on a Windows system, we will find that many of the commands used by the Windows cmd command line or Powershell are different from the commands used by the Linux system Terminal. So what should we do? Here is a very useful Bash tool - Git Bash.

1. Installation of Git Bash

Git Bash is a command line tool for running Git commands. It provides an environment similar to a Linux or macOS terminal, allowing us to use the Git version control system on Windows operating systems. Here is some important information about Git Bash:

  1. Basic functions of Git : Git Bash is mainly used to execute Git commands, including submitting code, creating branches, merging branches, viewing submission history, etc. We can enter Git commands on the command line to manage the code base.

  2. Linux-Like environment : Git Bash provides a Unix-based command line environment, which means we can use command syntax and tools similar to Linux or macOS. This makes using Git on Windows more convenient, especially for developers familiar with the Unix command line.

  3. Terminal functions : In addition to Git commands, Git Bash also supports common terminal functions, such as file navigation, file operations, text editing, etc. We can use the command line editor to modify code files, and we can also use various commands to manage files and folders.

  4. Shell scripts : Git Bash can also be used to write and run shell scripts, which can automate a variety of tasks, from simple file operations to complex workflows. This is useful for customizing Git workflows and automating tasks.

  5. Installation : We can download and install Git Bash from the Git official website. Once installed, we can find it in the start menu or launcher and open a new Git Bash terminal window.

In summary, Git Bash is a powerful tool for using Git and a Unix-like command line on Windows, which provides developers with a convenient way to manage and version control their code. By learning how to use Git Bash, we can interact with Git code bases more efficiently and develop in a Windows environment.

The download address of Git is : https://git-scm.com/download/win

2. Debugging Git Bash

First, we press the key in the Windows system Windows + Sto search, and the search keyword is git bash, and we get the following results:

Insert image description here

2.1 Modify language

Then we open Git Bash and change its language to Chinese.

Insert image description here

We need to reopen Git Bash for the language modification to take effect.

2.2 Switch themes

Insert image description here

2.3 Modify the right mouse button to paste

Insert image description here

2.4 Quickly open Git Bash

When we use cmd, we usually Windows + Ropen the run and then enter cmd -> 回车to open cmd. So how should our git bash be modified?

First we search Git Bash, open the path where its file is located, and then copy the path.

Insert image description here
After copying the path, set the system environment variable: 右键我的电脑 -> 属性 -> 高级系统设置 -> 高级 -> 环境变量 -> 系统变量下找到 Path -> 新建 -> 粘贴 Git Bash 所在路径 -> 确定.

Then copy it under the path of Git Bash Git Bashto get the copied file, and then rename the copied file bash.

During this process, the copy will require administrator rights, just give them.

Insert image description here
Then we can directly enter Git Bash in "Run" bash.

Insert image description here

2.5 Activate the Conda environment in Git Bash

Activating the Conda environment for the first time in Git Bash may fail. In this case, enter the following command:

conda init bash

Then close Bash, reopen it, and activate the virtual environment again.

2.6 Fix the bug that Python cannot be opened in Git Bash

Find the installation location of Git, as shown in the figure below:

Insert image description here

After: etc -> profile. d, profile. dopen the file in the folder with a text editor such as Notepad or VSCode aliases. sh, pythondelete the numbers after and change it to the following style:

case "$TERM" in
xterm*)
	# The following programs are known to require a Win32 Console
	# for interactive usage, therefore let's launch them through winpty
	# when run inside `mintty`.
	for name in node ipython php php5 psql python
	do
		case "$(type -p "$name".exe 2>/dev/null)" in
		''|/usr/bin/*) continue;;
		esac
		alias $name="winpty $name.exe"
	done
	;;
esac

conda activate2.7 Quickly execute and conda deactivatecommands in Bash

Still modify aliases.shthe file, as shown below, everyone understands:

# Some good standards, which are not used if the user
# creates his/her own .bashrc/.bash_profile

# --show-control-chars: help showing Korean or accented characters
alias ls='ls -F --color=auto --show-control-chars'
alias ll='ls -l'
alias act='conda activate'
alias deact='conda deactivate'

case "$TERM" in
xterm*)
	# The following programs are known to require a Win32 Console
	# for interactive usage, therefore let's launch them through winpty
	# when run inside `mintty`.
	for name in node ipython php php5 psql python
	do
		case "$(type -p "$name".exe 2>/dev/null)" in
		''|/usr/bin/*) continue;;
		esac
		alias $name="winpty $name.exe"
	done
	;;
esac

Guess you like

Origin blog.csdn.net/weixin_44878336/article/details/132698736