Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Efficient terminal command line tool - gives your terminal a nice look


Jun 01, 2021 Article blog


Table of contents


The article was reproduced from the public number: Rukawa View

I've heard in my WeChat communication group that many front-ends don't buy mac computers (like me) or use ohmyzsh

This article is not difficult, will soon be able to read, mainly hope that readers you can install after reading to start using efficient terminal tools. With such a powerful terminal tool, I found Windows works so well that I don't need to buy mac in an instant.

The main ones are:

  • Take advantage of Windows Linux subsystem features
  • Install Ubuntu system, install ohmyzsh and some plug-ins
  • Install the windows Terminal tool
  • Install vscode remote-wsl plug-in
  • Install tig to view git records

Let's look at the effect first. Anyway, after I used ohmyzsh I couldn't live without it.

 Efficient terminal command line tool - gives your terminal a nice look1

Windows installs the Ubuntu subsystem and installs windows Terminal

Search Enable or turn off windows, check windows subsystems for Linux Windows and restart your PC when you're sure.

Search for Ubuntu and windows Terminal and install windows Terminal may require a higher version of the win10 system, generally updated to the latest version)

Ubuntu is installed, you will be asked to set your username and password.

 Efficient terminal command line tool - gives your terminal a nice look2

 Efficient terminal command line tool - gives your terminal a nice look3

 Efficient terminal command line tool - gives your terminal a nice look4

It is recommended that you install the latest version of Ubuntu 20.04

 Efficient terminal command line tool - gives your terminal a nice look5

win10 has ubuntu subsystem and oh my zsh installed, you can access the f disk under win10 or any other disk, via /mnt/f/ There is also the pwd effect diagram above.

Install the vscode remote-wsl plug-in

Download and install vscode and install remote-wsl plug-in.

 Efficient terminal command line tool - gives your terminal a nice look6

Install oh my zsh

Outline how to install oh my zsh oh my zsh official website. github ohmyzsh

Installing oh my zsh section is suitable for Ubuntu and mac systems.

echo $SHELL
# /bin/bash 默认是bash
# 查看下有哪些shells
cat /etc/shells
# 安装 zsh
sudo apt-get install zsh -y
# 查看zsh版本
zsh --version
# 5.1.1
# 安装后zsh 后cat /etc/shells 才有/bin/zsh /usr/bin/zsh


# 切换成zsh
chsh -s $(which zsh)
# 或者这条命令
# chsh -s /usr/bin/zsh
# 三种安装方案可供选择:
# Via curl
$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"


# Via Wget
$ sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"


# 如果上面两种情况还安装不了,可以使用如下方式。


# via git clone
git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
chsh -s $(which zsh)
# 打开新的终端会应用新的zshrc配置

If none of the above can be installed, you can view the oh my zsh document

After a successful installation, the configuration information will be at ~/.zshrc Y ou can see that the git code ~/.zshrc Plugin:git is configured by default by opening the edit zsh configuration information via code s/.zshrc (if vscode is not installed, you can open zsh configuration information with vim ~/.zshrc That is, it is easier to use some of the aliases associated with git

# 比如
`git status`时,只需要输入`gst``git pull` 时,只需要输入`gl``git push` 时,只需要输入`gp`等等。

Because there are these shorthands in the configuration, there are many more to see here oh my zsh plugin git.plugin.zsh document configuration, github oh my zshin git .plugin.zsh file address. O nce installed successfully, a folder for ~/.oh-my-zsh is created at the same time, which is actually the git warehouse master branch of .oh-my-zsh Y ou can find a plugins folder in the folder with a lot of plug-ins built in. Y ou can customize theme theme, depending on the ample.zsh-theme. custom custom related. Plug-in-related will be installed here, and more can be viewed at example.plugin.zsh

I temporarily installed these plug-ins.

plugins=(
  # 内置插件,启用即可
  git
  cp
  mv
  # 按两下esc键,用sudo权限
  sudo
  # 记录历史输入的zsh命令,自动提示,快速使用
  zsh-autosuggestions
  # zsh 命令高亮
  zsh-syntax-highlighting
)

By the way, the installation method for the next two zsh-autosuggestions

git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions

Install zsh-syntax-highlighting

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting

$ZSH_CUSTOM is actually a variable that represents this ~/.oh-my-zsh/custom is installed in this directory. There are many high-efficiency plug-ins, and so you explore the official website of oh my zsh, but the plug-in installed more, feel there will be some catons

# 每次修改了这个`.zshrc`配置文件,需要重载一下,才能生效。
source .zshrc
# 也可以封装成一个简写命令 alias
alias rl='source ~/.zshrc'

You can also configure more alias in this profile.

# ~/.zshrc
# 比如跳转到工作目录
alias dgg='cd /mnt/f/git-source/github'
# vscode 打开要编辑的文件或文件夹
code blog

This is the effect diagram at the beginning.

 Efficient terminal command line tool - gives your terminal a nice look7

That's not win10 and you want to increase efficiency by setting aliases, isn't there a way to use git bash to set up alias install git and bring your own git bash

windows git bash sets aliases for increased efficiency

windows desktop or any Explorer location, right-click, select Git Bash Here and open the git bash command line. S et the theme first, right-click options Looks > theme > dracula I chose dracula theme and looked comfortable. You can also set fonts, and so on.

# 跳转到根路径
cd ~
# 查看下是否有.bash_profile文件
la
# 如果没有.bash_profile文件,需要创建
touch .bash_profile
# 打开编辑 (我这里安装了vscode,所以直接用其打开文件)
code .bash_profile

You can set some aliases based on the modification. F or example, our commonly used git status command can be encapsulated as gst The clear-screen command clear encapsulated as cls

alias gst='git status'
alias cls='clear'

Each time you modify this file, you need to enter source ~/.bash_profile overload the file for it to take effect. code ~/.bash_profile edit this profile with vscode and encapsulate it as a command. Like what:

alias rl='source ~/.bash_profile'
alias bashconfig='code ~/.bash_profile'

This allows the overload to take effect by simply entering rl after rl modification has been saved. You can also encapsulate some of my work directories, some of which I have under /f/git-source/github file.

# github上的项目
alias dgg='cd F:/git-source/github'
# 周报相关
alias dcwk='cd F:/git-source/coding/weekly'

Each time you enter the project, you can jump dgg to the directory and select the appropriate directory. For example, dgg enters the working directory, cd analyse-vue-cli enters the project directory (enter anal click tab smart tip)

#  /f/git-source/github/analyse-vue-cli (dev)
# 查看状态 git status
gst
# 用vscode 打开这个文件夹,开始编辑~
code ./

git-related, for example, some of the more usually used.

alias g='git'
alias ga='git add'
alias gaa='git add -all'
alias gp='git push'
alias gl='git pull'
alias gcmsg='git commit -m'
# 分支相关
alias gb='git branch'
alias gbr='git branch -r'
alias gba='git branch -a'
# checkout
alias gco='git checkout'
alias gcb='git checkout -b'
# merge
alias gm='git merge'
# diff
alias gd='git diff'
alias gdw='git diff --word-diff'

More can copy some commands of oh my zsh plug-in, leave alias related, oh my zsh plugin git .plugin.zshPlugin: git wiki is equivalent to unlocking the git plug-in of oh my zsh There are many plug-ins, such as npm click-to-view, node 等 that can be studied.

git bash there are no plug-ins like oh my zsh I haven't found out yet, if you know, please let me know. D irectory-related actions, you can also set some aliases. Like what:

# 回退到上一级
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
alias ......='cd ../../../../..'

More aliases can be customized to the command-line tool on windows and you can also use cmder to click to view the cmder official website command-line tool. A lthough I installed it a few years ago, I found that git bash worked better, probably because I wasn't used to cmder For cmder configuration-related, here's an article recommended by the Lord of the Late Clear Grass Xuan: "The Cmder of essential artifacts under Win"

There is also cygwin, also a windows command-line tool, which can also be on my zsh

Of course, git can also set aliases.

git set the alias, using the tig artifact

# git status => git st
git config --global alias.st status

More can be found in Mr. Liao Xuefeng's git configuration alias for this article. B ut perhaps most people don't know that they may be using visualization tools. I think visualization tools are also some of the encapsulations for git and we still need to understand what's behind it. T he command line uses git and I recommend tig git log plus, very good performance. ntu, linux mac can be installed directly, windows is a little more cumbersome. Check out the official installation documentation in the tig github repository, or check out this article: Tig, the artifact that subverts the Git command experience

brief summary

Grinding the knife does not cut wood by mistake, take the time to toss the research tools, is conducive to improve the development efficiency.

Above is W3Cschool编程狮 on the efficient terminal command line tool - to give your terminal beauty related to the introduction, I hope to help you.